Visio Guy

Visio Discussions => General Visio => Topic started by: efowler on August 23, 2022, 03:55:47 AM

Title: Group Shape Master Formulas Not Evaluating When Dropped
Post by: efowler on August 23, 2022, 03:55:47 AM
Basically what the title says. I created a group shape, made it a stencil, but when I add it to a document, the formulas are not evaluating. I have to go in and click in the formula and press enter, then it turns blue and evaluates.
Title: Re: Group Shape Master Formulas Not Evaluating When Dropped
Post by: Surrogate on August 23, 2022, 05:18:13 AM
Can you share more details?

1. These formulas stored in parent shape or in sub-shape ?
2. Are these formulas referred to other shapes, pages or document cells?
Title: Re: Group Shape Master Formulas Not Evaluating When Dropped
Post by: Croc on August 23, 2022, 06:23:22 AM
Similar issues have already been discussed in the forum. You can also read this article with examples - https://visioport.ru/blog/index.php/34-thedocref. The article made the following conclusions:
1. When developing stencils, you should be very careful when using inheritance chains (several consecutive referrens in formulas), they may not work.
2. For long chains, it is desirable to provide for the translation of inherited formulas into local ones. This can be built into shape construction, for example using SETF in the EventDrop event, or using programmatic methods.
Personally, I prefer translating formulas into local ones using EventDrop.
Title: Re: Group Shape Master Formulas Not Evaluating When Dropped
Post by: Surrogate on August 23, 2022, 06:54:39 AM
Quote from: Croc on August 23, 2022, 06:23:22 AM
Similar issues have already been discussed in the forum
Croc mean Russian Visio Forum (https://visio-getbb-ru.translate.goog/index.php?_x_tr_sl=ru&_x_tr_tl=en&_x_tr_hl=en&_x_tr_pto=wapp).
Quote from: Croc on August 23, 2022, 06:23:22 AM
You can also read this article with examples -
Please read this article via Google Translate Service (https://visioport-ru.translate.goog/blog/index.php/34-thedocref?_x_tr_sl=ru&_x_tr_tl=en&_x_tr_hl=en&_x_tr_pto=wapp)
Quote from: Croc on August 23, 2022, 06:23:22 AMPersonally, I prefer translating formulas into local ones using EventDrop.
100%
Title: Re: Group Shape Master Formulas Not Evaluating When Dropped
Post by: efowler on August 23, 2022, 10:54:03 PM
It's a subshape which references the master for its position. It has the following PinX and PinY formulas:

PinX =POINTALONGPATH(Sheet.4!Geometry1.Path,User.Label_A_Distance/SQRT((Sheet.4!EndX-Sheet.4!BeginX)^2+(Sheet.4!EndY-Sheet.4!BeginY)^2))
PinY =POINTALONGPATH(Sheet.4!Geometry1.Path,User.Label_A_Distance/SQRT((Sheet.4!EndX-Sheet.4!BeginX)^2+(Sheet.4!EndY-Sheet.4!BeginY)^2))

When I move the whole shape group to a stencil, those formulas turn black and the subshape does not move when the master connector moves. I'm not sure how eventdrop would help me here, maybe I'm just not understanding.
Title: Re: Group Shape Master Formulas Not Evaluating When Dropped
Post by: wapperdude on August 23, 2022, 11:34:33 PM
How did you create the stencil master?

Typically, I create it on nor drawing page.  Once I'm done, I duplicate the shape.  Make sure all the various features work.  Then I drag and drop the shape onto the stencil.  To ally, I drag this stencil shape back onto the drawing page.  All formulas should work.

Edit Note:  Have verified this, using your formulas.  Works fine.  Behaves as desired.  The text box always remains at the beginning of the connecctor. (assuming the User value is set to 0.)

Title: Re: Group Shape Master Formulas Not Evaluating When Dropped
Post by: wapperdude on August 24, 2022, 01:20:23 AM
M$ directions:  https://support.microsoft.com/en-us/office/draw-a-shape-in-visio-259ed0da-4444-4bf3-9093-33a0a79629e8 (https://support.microsoft.com/en-us/office/draw-a-shape-in-visio-259ed0da-4444-4bf3-9093-33a0a79629e8)

To create a new master shape
You can reuse your custom shape in other drawings by making it a master shape. To turn a custom shape into a master shape, do the following...
1.  In the Shapes pane, click More Shapes, and then select a custom stencil or create a new custom stencil by selecting New Stencil (US units) or New Stencil (Metric).
2.  On the drawing page, select your custom shape and drag it into the new stencil in the Shapes pane.
3.  To rename your new master shape, right-click the shape, select Rename Master, and then type a name for the new master shape.
4.  In the Shapes pane, on the custom stencil, click Save to save the changes to the custom stencil with the new master shape.
Title: Re: Group Shape Master Formulas Not Evaluating When Dropped
Post by: efowler on August 24, 2022, 03:00:17 AM
I created converted a connector to a group, added 2 text boxes to the group, and did all the formulas. I can copy the shape and everything works perfectly. The labels stay with the connector, all is good. If I drag a copy into the stencil, and then edit the stencil master, it also works perfectly. But as soon as I drop that master into the drawing again and move the connector endpoints, the PinX and PinY values become #REF! and the labels no longer move with the connector.
Title: Re: Group Shape Master Formulas Not Evaluating When Dropped
Post by: wapperdude on August 24, 2022, 05:52:41 AM
Seemed to work fine for me.  I only did one end, will try oth, but don't expect any problems.  Please up load a sample, perhaps there's something that's being missed either in our communication or the steps being taken.
Title: Re: Group Shape Master Formulas Not Evaluating When Dropped
Post by: Surrogate on August 24, 2022, 06:21:12 AM
Quote from: efowler on August 24, 2022, 03:00:17 AM
But as soon as I drop that master into the drawing again and move the connector endpoints, the PinX and PinY values become #REF! and the labels no longer move with the connector.
Please check is section or segment exist (https://docs.microsoft.com/en-us/office/client-developer/visio/pointalongpath-function#remarks)
Title: Re: Group Shape Master Formulas Not Evaluating When Dropped
Post by: Surrogate on August 24, 2022, 07:32:32 AM
I experimented a bit with the POINTALONGPATH function (https://docs.microsoft.com/en-us/office/client-developer/visio/pointalongpath-function), it seems to work only with the shape itself in the cell it is used in. The Sheet.4!Geometry1.Path as argument of this function does not work !
Title: Re: Group Shape Master Formulas Not Evaluating When Dropped
Post by: Croc on August 24, 2022, 08:30:06 AM
Quoteit seems to work only with the shape itself in the cell it is used in. The Sheet.4!Geometry1.Path as argument of this function does not work !
This is not entirely accurate, since in its original form such a reference works. It breaks only in the transition Drawing - Master - Drawing
But the way to fix the problem is right!
If you calculate PNTX(POINTALONGPATH(...)), PNTY(POINTALONGPATH(...)) in the User section of the group, and refer to these cells in PinX, PinY cells of a text blocks, then everything works.
QuoteI'm not sure how eventdrop would help me here
I agree. In this case, EventDrop will not help.
Title: Re: Group Shape Master Formulas Not Evaluating When Dropped
Post by: Surrogate on August 24, 2022, 09:08:29 AM
Quote from: Croc on August 24, 2022, 08:30:06 AMThis is not entirely accurate
It seems I had a syntax error at the time. I had the value #VALUE in the formula in the master shape even before I threw the master on the page
Title: Re: Group Shape Master Formulas Not Evaluating When Dropped
Post by: wapperdude on August 24, 2022, 12:58:51 PM
Did follow-up which had label at both ends.  Works fine.  V2019 Pro.   The formulas are placed in the PinX and PinY cells as initially provided with the cadet that my initial master ID was different.   Dragging and dropping onto stencil, and then dragging master and dropping onto page created no ref issues. 

The only issue I see is a needed parent to local scaling issue.  The values translate incorrectly, but that would be expected.  For the beginning point this is not an issue sInce 0 = 0.  But the end point is impacted. 

Croc's suggestion of doing the valve in two User cells might be better form, but seems unnecessary. 

If you manually move the labels after dropping, that will clobber any formula in the PinX and ping cells.  In that case, use the Guard() fcn to protect the formulae.  But that will prevent Manual placement.  If such an option is desired, then the SETATREF() fcn are needed as they intercept & use the manual placement, updating rather than clobbering the formulas.  In addition, I would add control points to allow easy placement.  You had an earlier post that I provided a link which does all of this...I think.
Title: Re: Group Shape Master Formulas Not Evaluating When Dropped
Post by: Croc on August 24, 2022, 01:41:02 PM
I can offer my version for research.
The PointAlongPathIssue.vsdx file contains two masters.
issue contains the PointAlongPath function in label B. After dropping on the drawing page, label B no longer tracks the position of the end of the connector.
corrected contains the PointAlongPath function in the group. This master is working fine.
This is not a complete solution, but only a demonstration of how the function works in different group shapes.
Title: Re: Group Shape Master Formulas Not Evaluating When Dropped
Post by: wapperdude on August 24, 2022, 02:21:24 PM
Ooops!!!  Well that was interesting.  3rd times a charm.  This time the end point failed.  The formula remained in tact, but the value does give REF#.

Converted to Croc's technique.  That performs better, but, as he mentioned, the End lbl doesn't track with line end movement.  It appears the formula is not updating after drop.

Haven't gone any further.
Title: Re: Group Shape Master Formulas Not Evaluating When Dropped
Post by: Croc on August 24, 2022, 02:40:47 PM
Quote...as he mentioned, the End lbl doesn't track with line end movement.
This refers to the original version, which does not work well.
The second master, in which the function is moved to the group, works fine.
Title: Re: Group Shape Master Formulas Not Evaluating When Dropped
Post by: wapperdude on August 24, 2022, 03:02:53 PM
@Croc:  Ah. Yes.  Well, looks like I independently confirmed your discovery.  Here's my version.  The differeence that I can tell is that I set the label box size to be based upon the txt size.
Title: Re: Group Shape Master Formulas Not Evaluating When Dropped
Post by: Croc on August 24, 2022, 05:22:36 PM
By the way, after a little effort, I found out that the idea with EventDrop also works. But the reference to the group has to be calculated through the ID() function. That is, to get a "Sheet.4" link, you will have to write "Sheet."&ID()
Then the formula for the end point will look like
EventDrop = SETF(GetRef(Sheet.7!PinX),"PNTX(POINTALONGPATH(Sheet."&ID()&"!Geometry1.Path,Sheet."&ID()&"!User.Label_B_Distance))")
+SETF(GetRef(Sheet.7!PinY),"PNTY(POINTALONGPATH(Sheet."&ID()&"!Geometry1.Path,Sheet."&ID()&"!User.Label_B_Distance))")

Two more SETFs will have to be added to serve the begin point of the connector. I'm not going to write this so as not to confuse readers :)
In the attached .vsdx file, this is implemented in the "drop" master.
---
This is the method that I suggested at the very beginning, referring to the article. But the example in the article is designed for a permanent reference like TheDoc, and in this case the reference should lead to a group. And the name of the group changes when the master is copied to the drawing page. But the inheritance mechanism does not take this into account in the POINTALONGPATH function argument. Therefore, we have to calculate the name yourself using the ID() function.
Title: Re: Group Shape Master Formulas Not Evaluating When Dropped
Post by: wapperdude on August 24, 2022, 06:12:55 PM
@Croc:  Some nice discoveries.  However, it would seem that the simpler method is more appropriate than this latest solution.

Changes to the simpler approach could be to a have a more efficient method of modifying the location of the label and possibly  the LocPin assignments.  The location improvement could be as simple as using shape data, or a more freeform using control points.
Title: Re: Group Shape Master Formulas Not Evaluating When Dropped
Post by: efowler on August 24, 2022, 10:36:29 PM
You guys are talking way above my head, but I did try putting the Pin formulas in the master user section and referencing those cells from the label Pin cells, and it worked perfectly. Still have no clue why that's required, but happy to have it working. Thank you both for your help!