Link to home
Start Free TrialLog in
Avatar of qprsoft
qprsoftFlag for Finland

asked on

Visio swimlane resize

Hello

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!
Avatar of Scott Helmers
Scott Helmers
Flag of United States of America image

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.
Avatar of qprsoft

ASKER

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);
break;
}
}

Open in new window


ASKER CERTIFIED SOLUTION
Avatar of Scott Helmers
Scott Helmers
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.