Visio swimlane resize

Posted on 2011-05-04
Last Modified: 2012-05-11

I am creating Visio objects in C#.

Visio.Application visioApplication = new Visio.Application();
Visio.Document visioDocument = visioApplication.Documents.Add(@"C:/1.vsd");
Visio.Page currentPage = visioDocument.Pages[1];
Visio.Document currentStencil = visioApplication.Documents.OpenEx("XFUNC_M.vss", (short) Visio.VisOpenSaveArgs.visOpenDocked);
Visio.Shape swimlane = currentPage.Drop(currentStencil.Masters["Swimlane"], 0, 0);
//Height change goes fine 	
swimlane.Resize(VisResizeDirection.visResizeDirS, 10000, VisUnitCodes.visMillimeters);	

//but same for width fails! (it actually does nothing)	
swimlane.Resize(VisResizeDirection.visResizeDirE, 10000, VisUnitCodes.visMillimeters);

Open in new window

Height change goes fine, but same for width fails! (it actually does nothing)
What might be the reason?

Digging into VBA script, which is created if I record the actions, does not help. Actually, I have a guess that I should select some proper object, but I have not found one. I mean that this swimlane is created within some container which prevent from such resizing, but no solution yet!
Question by:qprsoft
    LVL 30

    Expert Comment

    by:Scott Helmers
    Your assumption about what's wrong is very close. The swimlane derives it's width from a "parent" shape created for you by the swimlane add-in code. Consequently, you can't set the width of an individual swimlane directly. Instead, you need to change the width of the parent shape.

    I found the name of the parent shape by tracing backwards from the swimlane shape. If you look at the Width field in the shapesheet for the swimlane, you'll see that it derives its width from a user field in Sheet.5. The user field in Sheet.5 derives its value from the width of a shape called "Horizontal holder".  Therefore, you need to change the width of the Horizontal holder.

    I don't know the syntax in C# but in VBA you can do something like this:
    Dim shp As Shape
    Set shp = ActivePage.Shapes("Horizontal holder")
    shp.Cells("Width").Formula = 13

    Open in new window

    BTW, you didn't mention which version of Visio you're using. My answer applies to Visio 2007 and prior. The structure of swimlanes is totally different in Visio 2010, so if you're using 2010, let me know.

    Author Comment

    Thank you.

    Yes I am using Visio 2010. Of course, it would be nice to have a generic solution.
    I have found some sort for solution, but I am not sure if it has some side-effects.

    for (var i = 1; i <= currentPage.Shapes.Count; i++)
       if	(currentPage.Shapes[i].Name == "Separator")
            currentPage.Shapes[i].Resize(VisResizeDirection.visResizeDirW, 100, isUnitCodes.visMillimeters);

    Open in new window

    LVL 30

    Accepted Solution

    This is interesting... I've played a lot with Visio 2010 containers, of which swimlanes are an example. However, the cross-function flowchart (CFF) add-in software that comes with Visio is overriding some of the standard container behavior, including some of the size adjustments.

    Good find in your post above -- the Separator is a special shape at the right edge of a swimlane container that creates a "phase". I'm sure you've seen the word "Phase" in the upper right corner. Though the CFF code prevents you from changing the lane width directly, you can drag the phase separator via the UI to adjust the lane width. And as you've discovered, you can also move it via code.

    If you haven't tried it yet, drag another Separator from the stencil onto the swimlane, and then drag it to change the new phase boundary you've created. My point is that your code will need to be aware that there could be more than one separator in the CFF structure. The first should be called "Separator" and subsequent ones should be "Separator.nn".
    LVL 19

    Expert Comment

    by:Amandeep Singh Bhullar
    This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    HTML table 7 40
    deploying a service to production environment 13 68
    What are the big features of MVC5? 4 34
    401 - Error 6 14
    Note:  There are two main ways to deploy InfoPath forms:  Server-side and directly through the SharePoint site.  Deploying a server-side InfoPath form means the form is approved by the Administrator, thus allowing greater functionality in the form. …
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now