Author Topic: VBA Add-ins and the ...Many methods  (Read 254 times)

0 Members and 1 Guest are viewing this topic.

Visisthebest

  • Full Member
  • ***
  • Posts: 128
VBA Add-ins and the ...Many methods
« on: June 12, 2020, 02:37:07 AM »
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 Guy

  • Administrator
  • Hero Member
  • *****
  • Posts: 1712
  • Smart Graphics for Visual People...n' Stuff
    • Visio Guy
Re: VBA Add-ins and the ...Many methods
« Reply #1 on: June 14, 2020, 03:24:47 PM »
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

  • Full Member
  • ***
  • Posts: 128
Re: VBA Add-ins and the ...Many methods
« Reply #2 on: June 15, 2020, 11:11:43 AM »
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.

Visisthebest

  • Full Member
  • ***
  • Posts: 128
Re: VBA Add-ins and the ...Many methods
« Reply #3 on: June 29, 2020, 04:02:38 AM »
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?
« Last Edit: June 29, 2020, 04:21:06 AM by Visisthebest »