VBA Add-ins and the ...Many methods

Started by Visisthebest, June 12, 2020, 07:37:07 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Visisthebest

I am glad that Visio offers methods like DropMany and variations of dropmany like DropLinked to drop a ton of shapes with the same master shape on a page. I understand this makes add-in code much faster when dropping hundreds or thousands of shapes but does very little for vba (learned that here in this forum).

For linking up shapes, I can only find AutoConnectMany but are there other ways of linking many shapes in one method call but having more control over the linking behavior? I typically connect from a specified connection point on shape A to a specified connection point on shape B, using a custom master connector. The connect method should certainly not relocate shapes or choose which connection point to use.

Thank you for your help and advice!
Visio 2021 Professional

Visio Guy

For data-linking, there is DropManyLinkedU but I didn't see one for connecting shapes with connectors, other than AutoConnectMany, which I suspect only works for "flowcharts in grids".

I have my own library function called ConnectMany, and I've been using it for so long, I thought it was part of Visio's API.

To make one of these is a bit of a pain to get it just right, but you "just" combine the DropMany and SetFormulas. It goes something like this:

1. Use DropMany to drop the shapes you need. Hopefully you can then determine the ids of the new shapes and pair them with your source data.
2. Use DropMany to drop the connectors you need (this step can be part of step 1's call to DropMany)
3. Use Page.SetFormulas to blast the glue formulas that you'll need. For example, if you want dynamic glue, each shape has these sets of formulae:

BeginX = _WALKGLUE(BegTrigger,EndTrigger,WalkPreference)
BeginY = _WALKGLUE(BegTrigger,EndTrigger,WalkPreference)

BegTrigger = _XFTRIGGER(Sheet.1!EventXFMod)
EndTrigger = _XFTRIGGER(Sheet.1!EventXFMod)

Where Sheet.1 is some "box" that the connector is glued to.

If you're doing point-to-point glue (connectors to connection points), then you will only set BeginX, BeginY, EndX, EndY to reference some shape's connection rows, ala: PAR(PNT(Sheet.1!Connections.X1,Sheet.1!Connections.Y1)). This formula will be the same for X and Y cells, but different for Begin vs. End.
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

Visisthebest

Thank you very much Visio Guy this is the solution I'm looking for!

It does require a call to a VBA Sub/Function from the add-in from what I understand, in most cases this is no problem and will really speed up the add-in, pushing one array with info about hundreds of shapes and their connections across the .net interop in one call instead of hundreds or even thousands of calls across the interop.
Visio 2021 Professional

Visisthebest

#3
Ok yes dove in to it more now I see it can all be done in the add-in, just 2 or 3 calls across the interop to create the entire diagram! Mistakenly thought I needed to create a VBA library function that combines DropMany & Setformulas and call it from the add-in. I see SetFormulas allows setting multiple formulas on multiple shapes at once supercool!

Will setting DeferRecalc to True

https://docs.microsoft.com/en-us/office/vba/api/visio.application.deferrecalc

and at the end of the operation to False further help speed things up significantly for a diagram with several hundred shapes & connections?
Visio 2021 Professional