Is it possible to make a custom re-layout function?

Started by 2020Visio!, August 23, 2015, 07:59:29 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

2020Visio!

The re-layout functions in Visio are super useful for several types of diagrams. We'd like to make a custom re-layout function.

Is this possible make a custom re-layout function, or is really about just writing a layout algorithm with your own custom VBA code?

Any direction with how to make your own re-layout function in Visio is extremely helpful for me thanks!

Yacine

Yacine

2020Visio!

#2
We're trying to make a fault tree that runs from left to right. (if you Google fault tree you will find lots of examples of a tree running from bottom to top, which which I mean the causal direction)

Visually, you only have one shape on the far right of the diagram.

That shape has one or more shapes connected to it on the left. These shapes each have one or more shapes connected to them on the left etc etc.

The layout algorithm:

- centers the total height of the shapes connected to one shape on the height of that shape

- creates as much space as necessary as a fault tree may have many shapes connected to them on the left (for instance, a tree in which 1 shape connect to 10 shapes which connects to a 100 shapes, where some shapes have 20 connections and other may have only 2 etc)

We want to be create some settings for this layout algorithm where we can finetune the amount of space used and maybe other variables.

Creating our own layout / re-layout allows us to get these diagrams as right as possible, where the user may only have to do some post-editing to optimize space use.

Thank you so much for any guidance and help with this!

wapperdude

#3
Few more questions:
1) Are the shapes being placed manually...presumed yes.
2) The tree is dynamic, i.e., starts simple, grows as investigation proceeds.
3) Growth can require insertion of new shapes anywhere along the fault tree...causing existing shapes to move either vertically and/or horizontally.  Thus, existing diagram can get congested, messy.
4) The largest vertical column of shapes defines the page height.
5) The right most shape must always be at the "half height" of the page.  (Comment:  this step is easy to do, but I, not sure it makes the best looking diagram as I could imagine significant asymmetry in the tree as it grows leftward.)
6) Is it desired or necessary that each vertical column be centered vertically?
7) Is it desired to minimize vertical "jogs" in the horizontal connecting lines?
8) Basically, the "function", keeps everything tidy.

This is a non-trivial problem and would take considerable coding...I would think.

Aren't there existing solutions, dedicated to this sort of task?

Wapperdude
Edit:  LOL, the smiley face with sunglasses was supposed to be an "8" with ")", but auto insert "knows" better.   ???  Decided to leave it...Funny.    ;D
Visio 2019 Pro

2020Visio!

#4
Hi Wapperdude,

See my answers in your questions below:

1) Are the shapes being placed manually...presumed yes.

- Yes (and if they are place automatically they are free to be moved)

2) The tree is dynamic, i.e., starts simple, grows as investigation proceeds.

- Yes

3) Growth can require insertion of new shapes anywhere along the fault tree...causing existing shapes to move either vertically and/or horizontally.  Thus, existing diagram can get congested, messy.

- Yes. Sometimes you have to do a multiselect of shapes and move them out of the way. This is quite easy in Visio.

4) The largest vertical column of shapes defines the page height.

- Yes

5) The right most shape must always be at the "half height" of the page.  (Comment:  this step is easy to do, but I, not sure it makes the best looking diagram as I could imagine significant asymmetry in the tree as it grows leftward.)

- Yes but this could be corrected for the asymmetry of the tree. Not hung up on exact centering.

6) Is it desired or necessary that each vertical column be centered vertically?

- Not exactly sure what you mean

7) Is it desired to minimize vertical "jogs" in the horizontal connecting lines?

- Not exactly sure what you mean but I assume you mean something like getting really long horizontal lines? The algorithm can be quite linear and unoptimized in this regard, we like to do post-editing and move things together to optimize space use. This often depends on the content of the items so better done by a human being who can assess the meaning of the items.

8) Basically, the "function", keeps everything tidy.

- Yes, to get the fault tree to look correct and balanced again, even if it is a space hog. Space optimization is done by hand afterwards.

- Because we like to experiment with how our specific fault tree will look with automatic layout, we want to have as much control as possible (so a piece of VBA code) to experiment until we get the re-layout optimized (enough) for most trees.

Yes there is highly technical fault tree software. Visio is much better software and provides a lot of freedom for adding elements in post-layout-editing. We are really doing something custom here (a fault tree of how moods and emotions of individuals and groups interact). Having total control over the shape design is also a must-have, off-the-shelf software does not provide this (and often looks pretty terrible).

We want to get to this point step by step, understanding this challenge in Visio one aspect at a time. Coding is not a problem, but I don't want to start until I understand Visio and its specific ways and object model really well.

Thank you for your thoughts and ideas!

Jim.

wapperdude

I can vision where this could become quite a large coding project...but, there are some pre-coding features that might help along the way.

Not sure which version of Visio you're using, I stopped upgrading with V2007, so will keep suggestions somewhat generic.

1) You can setup a page / shape behaviour such that shapes have minimum spacing, that shapes move out of the way when a new shape is dropped onto the page, and shapes can split connectors when placed on top of same.

2) You already know about aligning shapes, there's also a similar distribute function to give multiple shape selections equal spacings.

3) Once a set of shapes have been arranged, then can be grouped together to maintain their relative positions.  The same align/distribute methods can be used on groups.

To clarify a couple of my points...
  6)  Let's say 2nd column from right has 2 shapes.  The upper shape has 2 shapes connected to it (from next column to the left), but the lower shape has 5 shapes feeding it.  Clearly, diagram has asymmetry.  So, the column with the 2 shapes could have the shapes placed symmetrically wrt to page height (i.e., both equally offset above/below the page half height) or, each shape could be placed symmetrically wrt its preceding group of shapes.  This would result in a non-symmetrical placement of the two shapes.

  7) Is it desired to maximize the number of horizontal connectors that are straight runs...not necessarily long, just straight...fewest bends,  also, fewest crossovers?  Guess, this comes later in the development process...auto routing/placement.

Visio 2019 Pro

2020Visio!

Hi wapperdude,

Thank you so much for all your guidance!

I will try to do this using the Visio 2016 preview, or I'll revert to the previous version if I run in to a showstopping bug.

I am going to look into your points 1) 2) and 3) first because this should already let me do a lot of arranging of shapes on a local level, allows me to think about how to loop through an entire diagram arranging elements in parts of the diagram. I do see it will become more complex after that :) but experimenting a bit helps me to get familiarized with Visio.

I will use the macro recorder to see what code Visio generates when using these functions.

Is there good sample VBA code that is traversing through an entire diagram (through the connections, not just the collection of shapes on the page).

I did find this link which is useful for understanding some of the things to take in to account developing VBA for Visio:

http://visguy.com/vgforum/index.php?topic=6629.0

Jim