Making a flexible shape, driven by Excel

Started by miless2111s, March 14, 2022, 12:41:40 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

miless2111s

I want to be able to vary the shape displayed in Visio from a rectangle to Triangle to a star shape etc. I currently plan to do this by defining where I want each "corner" to be in the Shape Geometry in Excel and passing that information across. My plan is (was?) that I would have the maximum number of corners set up for the most complex shape and if I didn't need any then the spare ones would be "parked" at either the origin or last position.

This works well except when the shape has some rounding applied to it. At this point, the spare corners prevent the rounding so you end up with a lopsided shape :( It isn't so bad I park the spare ones on a line (say at height*0, width*0.5) but when the shape gets small enough these do start to cause uneven rounding.

Does anyone have any ideas on how to do this better?  Options I have considered (but am unsure how exactly to do):
* Have a user-triggered macro that either trims out the surplus corners OR puts them back in if needed
* A macro that runs every time the data is uploaded from Excel which defines the shape needed.  The disadvantage here would be that the updates would take longer as more code would be running
* A macro that runs if the shape designation field (a user data field) changes - can Visio do "if this changes then run macro" type triggers?  Does this impact the speed in the same way that such a macro slows down excel as it is always looking for a change?

Many thanks in advance for your help.

Surrogate

I can't imagine why you would want to do that?
WOW !
Quote from: miless2111s on March 14, 2022, 12:41:40 PM
I want to be able to vary the shape displayed in Visio from a rectangle to Triangle to a star shape etc. I currently plan to do this by defining where I want each "corner" to be in the Shape Geometry in Excel and passing that information across. My plan is (was?) that I would have the maximum number of corners set up for the most complex shape and if I didn't need any then the spare ones would be "parked" at either the origin or last position.
Rectangle/Triangle/Star in separate Geometry sections ?

Paul Herber

I can imagine a generic 'Shape' shape with a menu to select which one you want. Bear in mind though that the shape's name won't (and can't) change with the selection.
Electronic and Electrical engineering, business and software stencils for Visio -

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

vojo

Several options
1)  pass vertex values to user cells ==> use user cells as part of geometries
         Geometry1.x2 = geometry1.x1 + user.x2 cell
2)  Geometries for square, another for triangle, another for circle...excel uses user cell to decide which to show and which to hide
         geometry3.noshow = not(user.showhide).
3)  use user cells to have complete geometry formulas
          geometry1.x2 = user.xxx2 cell

BTW,
if you want behavior to affected by some other shape, you can use LOCTOLOC or LOCTOPAR functions in geometries
If you want to also allow some UI support, then use some of the SETEXPR(<blah blah blah>) functions

Visio Guy

If you want to foil rounding, just double-up the vertexes and the rounding won't show. You can selectively turn rounding on and off for shapes this way. Just double-up the vertices where you don't want rounding.

Also, be sure to take a look at More Shapes > Visio Extras > Drawing Tool Shapes. There you'll find the "Multigon edge" and "Multigon center" shapes. Right click to change from triangle to octagon!

For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

Yacine

#5
Quote from: miless2111s on March 14, 2022, 12:41:40 PM
... My plan is (was?) that I would have the maximum ...


I would warn from too complexe shapes. Always keep maintenance in mind.
Either (1) write a macro to build the maximum shape or (2) make it configure itself.
I'm using for over a decade a self built solution where I have base masters with several fixed list props. The lists contain the names of masters suitable for being inserted in the base shape.
A "callthis" will send the values to a macro which deletes the content of the base shape and re-inserts the sub-shapes chosen.
Yacine

miless2111s

Quote from: Paul Herber on March 14, 2022, 01:41:26 PM
I can imagine a generic 'Shape' shape with a menu to select which one you want. Bear in mind though that the shape's name won't (and can't) change with the selection.
To be honest I need the shape name to stay the same so that it remains linked to the source data which tells Vision how big it should be and where on the page it sits.  Could the "shape" macro be triggered by changes in the data driving the shape or would you see this as a manual selection?  Would it be possible to select multiple shapes at once to change or would I need to change each one individually?

miless2111s

Quote from: Visio Guy on March 14, 2022, 03:49:42 PM
If you want to foil rounding, just double-up the vertexes and the rounding won't show. You can selectively turn rounding on and off for shapes this way. Just double-up the vertices where you don't want rounding.

Also, be sure to take a look at More Shapes > Visio Extras > Drawing Tool Shapes. There you'll find the "Multigon edge" and "Multigon center" shapes. Right-click to change from triangle to octagon!

Thanks for the tip about the Multigon shapes I will have a look at these.   The issue with rounding is that I want to allow it :)  Sometimes a rounded rectangle is far nicer than a sharp cornered one, the issue comes when I have a rectangle with all the "unused" corners piled up in the bottom left then this corner can't round which just looks odd.   Mind you your suggestion explains how to do the rectangles with two rounded and two sharp edges so thanks for that one! :)

miless2111s

Quote from: Surrogate on March 14, 2022, 01:13:11 PM
I can't imagine why you would want to do that?
WOW !
Quote from: miless2111s on March 14, 2022, 12:41:40 PM
I want to be able to vary the shape displayed in Visio from a rectangle to Triangle to a star shape etc. I currently plan to do this by defining where I want each "corner" to be in the Shape Geometry in Excel and passing that information across. My plan is (was?) that I would have the maximum number of corners set up for the most complex shape and if I didn't need any then the spare ones would be "parked" at either the origin or last position.
Rectangle/Triangle/Star in separate Geometry sections ?

This is how I have started to test it, this can't do a star yet but in this configuration, it changes a rectangle into a Chevron with the degree of indent controlled by Excel rather than being a function of the length which just looks silly.
https://imgur.com/iJqkVrs

miless2111s

Quote from: vojo on March 14, 2022, 01:49:19 PM
Several options
1)  pass vertex values to user cells ==> use user cells as part of geometries
         Geometry1.x2 = geometry1.x1 + user.x2 cell
2)  Geometries for square, another for triangle, another for circle...excel uses user cell to decide which to show and which to hide
         geometry3.noshow = not(user.showhide).
3)  use user cells to have complete geometry formulas
          geometry1.x2 = user.xxx2 cell

BTW,
if you want behavior to affected by some other shape, you can use LOCTOLOC or LOCTOPAR functions in geometries
If you want to also allow some UI support, then use some of the SETEXPR(<blah blah blah>) functions

how do you do 2 and 3?  I am not aware of having different Geometries...

miless2111s

Quote from: Yacine on March 15, 2022, 08:29:18 AM
Quote from: miless2111s on March 14, 2022, 12:41:40 PM
... My plan is (was?) that I would have the maximum ...


I would warn from too complexe shapes. Always keep maintenance in mind.
Either (1) write a macro to build the maximum shape or (2) make it configure itself.
I'm using for over a decade a self built solution where I have base masters with several fixed list props. The lists contain the names of masters suitable for being inserted in the base shape.
A "callthis" will send the values to a macro which deletes the content of the base shape and re-inserts the sub-shapes chosen.
If I have understood you correctly I think this was the basis of the idea that a macro would add / remove the vertexis needed for the requested shape.  Would you see this as triggered for each shape manually or something that could be triggered by the data being passed to the shape?

vojo

turn on developer mode  (is in file ==> options ==>at the bottom)
right click shape, open shapesheet
on the menu, you can add /delete sections and add / delete rows.

I think help for all the cell functions can be accessed by help

wapperdude

#12
See this post for multiple shapes in a single entity.  It does more than you need because of the connectors, but over the idea.  http://visguy.com/vgforum/index.php?topic=6897.msg28789#msg28789

Note:  no "parking" needed.  Also, it doesn't use VisioGuys' no rounding technique.
Visio 2019 Pro

Yacine

#13
Quote from: miless2111s on March 15, 2022, 10:47:30 AM
If I have understood you correctly I think this was the basis of the idea that a macro would add / remove the vertexis needed for the requested shape.  Would you see this as triggered for each shape manually or something that could be triggered by the data being passed to the shape?

1) Sorry for having misunderstood your question,
2) Triggered by the data - dependson(prop.soandso) + callthis(...)


PS
I'll try these days to upload a forum version of my tool.
Yacine

miless2111s

Quote from: Yacine on March 15, 2022, 03:57:50 PM

2) Triggered by the data - dependson(prop.soandso) + callthis(...)


Can I check my understanding of this as this is the first time I have come across this....  If I have a user-defined cell that contains a text string (say "5 pt star") and this stays the same no macro is triggered however if the text changes during an update the macro will be called?  If this understanding is true then it would mean that the performance impact of having a macro that changes the shape on demand would be very low as it wouldn't be running on hundreds of shapes each time I run an update (the diagram has some 1,200 shapes which are updated by Excel)