VBA for swapping two connected shapes

Started by Visisthebest, July 30, 2018, 04:45:51 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Visisthebest

Hi All,

Just found this forum, how great this resource exists!

I am new to VBA and Visio, have been exposed much more to Javascript (all the good and the bad of JS).

We have a huge flowchart diagram where a lot of shapes are connected from left to right, each one with an incoming connection and an outgoing connection.

These shapes have a time in seconds or even milliseconds associated with them (they are events). They should be chronological but people people can make the mistake of sometimes putting an event out of order, most often meaning that one event connected to the other (directly) needs to be swapped to repair the chronological order.

What is important to know and to consider before starting out to write some VBA code to swap two events connected next to each other? The other connections these events have with other shapes should also be connected to the swapped shape. The shapes have identical sizes (rectangles). All the data on these shapes needs to move along with the swap.

Your ideas for how to start out making some VBA for this are greatly appreciated.

Warm regards,

Max Larsen
Visio 2021 Professional

wapperdude

Take a look at Paul Herber's Super Utilities.   

Wapperdude
Visio 2019 Pro

Visisthebest

Wapperdude thank you great functionalities in that tool kit, but it doesn't do shape swapping and reconnecting unfortunately.
Visio 2021 Professional

metuemre

It will be helpful if you can provide a sample visio file. What you want can be done with VBA

Paul Herber

Quote from: wapperdude on July 31, 2018, 01:00:43 AM
Take a look at Paul Herber's Super Utilities.   

Wapperdude
thanks dude,. I'm sorry but my utilities can't do that.
Electronic and Electrical engineering, business and software stencils for Visio -

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

Visisthebest

Great tools Paul will probably buy them!

I will make a sample file, but it is virtually identical to a cross-functional flowchart but with fine-grained times on the columns. (for instance, from electronic aviation system logs and other data sources for doing accident investigation, challenge is that the examples I have are confidential need to make an example without real data)

The swap is for horizontally-connected shapes that need to be swapped.

Thanks!

Max
Visio 2021 Professional

wapperdude

As I have V2007, haven't explored this myself.  But, with V2013, there is a change shape feature that might meet your needs.  https://blogs.msdn.microsoft.com/officedevdocs/2012/08/23/change-shapes-in-visio-2013/

HTH
Wapperdude
Visio 2019 Pro

Visisthebest

Yes Wapperdude thank you but I am looking for almost the inverse of that functionality, all the shape data and properties should move with the swap rather than stay put. I'll experiment with this in the coming weeks and share my code when it works, I'll write it generically so it works on cross-functional flowchart type diagrams and similar.
Visio 2021 Professional

AJD

Spit-balling here, don't have the opportunity to test this out any time soon.

You imply that the connectors are directional, so you could perform a check to see if the <timevalue> of the object on the left (the incoming connector) is less than the <timevalue> of the current object. Similar checks for the object on the right. This is a simple pair of YES/NO that could be displayed graphically (e.g. change the colour of the shapes etc).

To make life easier, a custom shape (I assume you are using those anyway) that constrains the types and directions of connectors (perhaps even custom connectors). If using standard shapes and connectors, you can determine visual direction by identifying which end of the connector is connected to which shape and then identifying which end has the arrow head. But, constraining the shapes makes these checks easier.

This is based on some work I did a few years ago (hence lack of fine detail here) to traverse a connected graph which used semi-standard connectors that the users could swap and modify in the UI.


Visisthebest

Thank you for this very useful to think about these options!
Visio 2021 Professional

pavane


Visisthebest

Quote from: pavane on September 09, 2018, 07:10:29 AM
Can you not just swap the contents?

Panave yes that is a possibility too, do you expect that to be faster as well? What is a good way to do this in VBA so it is truly one transaction, if any part of it doesn't execute properly (which would corrupt the data) the entire transaction is (automatically for the user) reversed and the user gets a prompt informing him/her the swap hasn't gone through?
Visio 2021 Professional

Paul Herber

First, set the Undo scope, so that if it goes wrong then all you have to do apply the undo and it will happen.
Next, it will depend on what shape properties you need to swap. Are the shapes of the same type? Is it just text to be swapped?
Electronic and Electrical engineering, business and software stencils for Visio -

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

Visisthebest

Thank you Paul, same shapes yes, both text and shape data need to be swapped.
Visio 2021 Professional

Visisthebest

#14
Oh yes I forget there may be more causal links than just on the horizontal line, so some connections may have to be reconnected from the one shape to the other and vice versa if just the properties of the shape are moved over.
Visio 2021 Professional