Visio Guy

Visio Discussions => ShapeSheet & Smart Shapes => Topic started by: Gustavo on May 31, 2021, 10:46:02 PM

Title: How I get the Max value of X and Y with a variable Geometry vertices?
Post by: Gustavo on May 31, 2021, 10:46:02 PM
Hi all.

I have a master shape with a main shape with 2 sub-shapes. Sub-shapes have a geometry section, and the main shape has not.
Sub-shape 2 has a fixed width & height and position relative to subshape 1, and subshape 1 has a geometry which will be editable by the user in width&height and in number and position of geometry's vertex.
I want to obtain the max value of a subshape1 geometry.X and geometry.Y vertex, in order to have the main shape width and height value updated when the user change subshape 1 geometry in vertices number and values. I know it can be done by function

Width = MAX(Subshape1!Geometry1.X1,Subshape1!Geometry1.X2,Subshape1!Geometry1.X..n)

But I don't know how to get the vertice's number, if it will be variable. Id like to do it with shapesheet only, if possible. Any help would be appreciated.

Best regards.
Title: Re: How I get the Max value of X and Y with a variable Geometry vertices?
Post by: Surrogate on May 31, 2021, 11:40:22 PM
Quote from: Gustavo on May 31, 2021, 10:46:02 PM
But I don't know how to get the vertice's number, if it will be variable.
You can use SEGMENTCOUNT function (https://docs.microsoft.com/en-us/office/client-developer/visio/segmentcount-function#syntax) and get how many segments contain your shape.
Quanity of vertex = Quanity of segments + 1
Title: Re: How I get the Max value of X and Y with a variable Geometry vertices?
Post by: wapperdude on June 01, 2021, 01:21:21 AM
After you have max values, then do catenated if statements to find the matching x- & y- values.  For example, if(geo1.x1=maxX, geo1.x1,if(geo1.x2=maxX, geo1.x2, if(........))))....))))

The problem is how many variables to put into both the Max() and if() statements.

Note, instead of long if statement, you could add a bunch of rows in, e.g., User section.  To wit,
User.r1:  if(geo1.x1=maxX, geo1.x1, User.r2
User.r2:  if(geo1.x2=maxX, geo1.x2, User.r3
Etc

Or something like that.  The idea is that a successful evaluation gives the identity of the point, and unsuccessful evaluation keeps going until a match is found.