Dropping Swimlanes behaves differently depending on "Calling Shape"

Started by adstar22, October 16, 2013, 10:23:24 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

adstar22

To cut a long story short, I am developing an interactive workflow tool, and for 2 different shapes (an off page reference Arrow, and a basic Hexagon) I create a new page (actions triggered by dropping either of these shapes) in the document and want to add the swim lanes which are standard/consistent through the document.

The new page is created via a "common function" named fncNewPage called by two different routines ie pgeNew=fncNewPage.
First I add the new page: Set pgeNew = ActiveDocument.Pages.Add

Then I try and add the swimlane: Set shpSwim = pgeNew.Drop(Application.ActiveDocument.Masters("Swimlane (vertical)"), 1.49, 7.22)

The difference in behaviour is that:

When called in relation to the "off page reference" shape dropping the swimlane ALSO includes the CFF Container AND the Swimlane List, meaning I can add the additional swimlanes into the container in the correct positions.

When called in relation to the basic hexagon shape dropping the swimlane drops ONLY the swimlane. The CFF Container and Swimlane List are NOT created until I stop executing the code! By which time it is too late for me to add the other lanes etc.

As I said, the same new page function is called by both "shape related routines" so there is no difference in the created page at the point the swimlanes are added!

Any ideas would be GREATLY appreciated. (Appologies if this is the wrong section of the forum, but I had to start somewhere!)

Paul Herber

Those two shapes are different in that they both initiate an add-on to implement their behaviour. Your code needs to wait until their activity has finished, I can't remember what message it is you have to wait for but I'm sure someone will be along soon to do a memory refresh ...
Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

adstar22

This could be interesting, as my experiments have been unable to find anything which resolves the issue. I have tried using different shapes calling the same code and I still have the same issue.

Interstingly, if I call the code from a "standing start" (ie a blank macro) with no previous interference from any newly created shapes (which have all been processed (I thought) by the time the new page is created, and there is obviously no issue....

It would have been an ideal work around to create the page first, but the whole event is triggered by dropping the shape (OnEvent formula) onto an existing page! I will continue to find a work around in the hope that someone else is abel to provide information on a proper solution, including the idea of addons workign in the background, and how to "quiz" them!

Paul Herber

You need to see what happens when a swimlane shape is dropped on a blank page without your own add-on, that might give you some idea about what is actually happening. Without that you have no chance of working it out. Experimenting and guessing won't help.
Disable your own add-in, create a simple blank diagram from New -> Blank drawing.
Open the Cross-functional flowchart shapes stencil, drop a swimlane on your drawing.
a. notice that the Cross-functional menu has been added - the cross-functional addon is now running and taking change of events
b. Open the Drawing Explorer window - notice that there is more that just a swimlane shape on the drawing.

If you are doing this with the UML swimlane shape rather than Cross-functional all the above still applies (but with the UML addin).
Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

adstar22

Ok I have a resolution of sorts.

Having spent all day fiddling around with the basic code which created the new page and added the swimlane and getting no where as you (Paul) hinted I would, I decided to look at the basic differences between my working shape and my none working shape. I took on board Paul's advice, but recording events on a blank document just produced the same code I used to create my own routines.. so nothing learnt there. Although discovering the drawing explorer was new!

As I described before, both "shapes" ultimately call the same code to create the page and swimlanes. However, the working shape uses the "CallThis" command in the shape Sheet OnEvent_Drop, and my broken shape was using "RunMacro".

So... Not fully understand the differences, I decided that I should make the broken shape work the same as the working shape (given that it was an easy change AND the only noticable difference between the two shapes) and... POW a fully functioning CFF container when dropping a swimlane shape onto a new blank page!

As far as I can tell with my limited knowledge "CallThis" enables you to pass the shape as an object directly into a macro (as well as some optional arguments which you might have to use so the default shape object is in the correct position, but I just pass in "xxx" to a string variable I wont ever use), where as the RunMacro needs you to identify the shape you are looking at, in my case I did this using the Selection.PrimaryItem property.

So whilst I may not have "solved" the problem (What is the difference between running a macro which has to identify the shape, and calling a macro and passing in the shape, which prevents the swimlane from funcitoning correctly?) But I have most definately found a more than adequate work around!

Thanks Paul for your input.

Paul Herber

Glad you've got it working.
Recording a macro is not very representative of how code should be written, in fact the code created is diabolical in that it is relevant to only that perticular instance of a shape and is very difficult to make more general unless you know what you're doing. Also, much action within and resulting from dialogs is not recordable, and of course the macro only records user action, not the events happening in the background, which is what you want!
Download and have a look at the Visio SDK, look at persistent events, and run and use the event monitor (in the SDK).
Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/