Auto Add Shapes On Other Pages

Started by fensterb, August 04, 2015, 01:56:41 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

fensterb

Hey Guys, I create schematics for A/V equipment and I first add the shapes for the equipment, and then I also create a new page and create the equipment rack layout.

My question is, is there a way to setup visio so that when I add my Shape for the AV equipment, it automatically adds the Rack Shape to the 2nd page?

It is very easy to create the schematics and then forget to add the shape to the rack page. If I could get visio to automatically add it, that would help reduce my errors.

Thanks for the help!

P.S. I am using Visio 2007

Surrogate

Visio havn't same  build-in feature, you need write macro!

fensterb

Do I need to write a macro for each shape? Can you please help me write at least one macro to get the idea? I am a newbie!

Thank you

zhuravsky


Hey Ken

 fensterb:

   Here's another approach that uses much less code and is also easier to maintain and use.

   First off, I'd suggest putting the code inside the stencil where you get your shapes from.  Zhuravsky's approach assumes you put the code in the document.  But if you keep it in the stencil, all you need do is distribute the stencil and your users will get the code for free without having to install anything themselves.  Another benefit to this approach is that you have access to both shapes inside the macro, in case you need to do any additional processing.

   The heart of it is a simple procedure that lives in the ThisDocument module of the stencil:


Sub DropShapeOnPageTwo(ByRef ThingOne As Shape)
Dim ThingTwo As Shape
Set ThingTwo = ActiveDocument.Pages("Page-2").Drop(Documents.Item("Things.vss").Masters.Item("Thing Two"), 3, 3)
' <add any additional processing here>
End Sub


   This procedure is invoked by placing the following function in the EventDrop shapesheet cell of the master shape you're dropping on page 1:


=CALLTHIS("ThisDocument.DropShapeOnPageTwo","Things")


   Of course you'll need to change "Things" to the name of your stencil, "Page-2" to the name of your second page, and "Thing Two" to the name of the master shape you want to drop onto your second page.

   A simple sample is attached.  Just open your document, open the stencil, then drag Thing One off the stencil.  Thing Two automatically appears on Page-2 – assuming you've created a page named "Page-2", that is. 

   Hope this helps,

   - Ken




Ken V. Krawchuk
Author
No Dogs on Mars - A Starship Story
http://astarshipstory.com

fensterb

whew. Thanks so much. The example helped a lot. I had issues getting it to work because I didnt understand that the On Drop "Things" was a reference to the stencil name.

So, now to dig just one step deeper and I think it will solve all of my problems.

1) Can i auto add a shape from another stencil? For Example, my Stencil for my A/V equipment will be called "electronics" and my Stencil for my rack equipment will be called "racks" Does the call become:

ActiveDocument.Pages("Page-2").Drop(Documents.Item("racks.vss").Masters.Item("Thing Two"), 3, 3)

?

Also, there might be one thing I am not quite grasping and that is....how does this discern between the different shapes that I add?

for instance, in your example, you added "Thing One", so "Thing Two" was automatically added. I want to also add "Thing Three" and have "Thing Four" automatically get added. I dont understand where there is any "logic" to automatically add different shapes depending on which item you added.

Again, thanks for taking the time to help. I am so close to solving this!

zhuravsky

There is even better solution. No any macro required and you can even navigate between pages. Enjoy.
Off-page-reference Add-on required.

Hey Ken

   Very clever, Zhuavsky!  It reminds me of the old days of the APL programming language when coders would try to squeeze an entire program into a single line with as few characters as possible.

   Yes, fensterb, the process can add shapes from any open stencil.  Just change the .vss stencil name to match the one you want, as your example shows.  Watch out, though: if your dropped shape refers to a stencil that's not open, nothing happens.

   The dropped shapes are differentiated by their names in the DropShapeOnPageTwo procedure.  The shape you first dropped is referenced by the name ThingOne, and the one dropped on the second page is referenced by ThingTwo.  So, for example, the text inside of ThingOne is ThingOne.Text, the width of ThingTwo is ThingTwo.Cells("Width").Formula, etc.  As for any additional shapes (ThingThree, Four, Five, etc.), each time the procedure is invoked ThingOne and Two will point to the latest pair of shapes added.

   Hope this helps,

   - Ken

Ken V. Krawchuk
Author
No Dogs on Mars - A Starship Story
http://astarshipstory.com