Visio Guy

Visio Discussions => ShapeSheet & Smart Shapes => Topic started by: spandex on March 13, 2015, 02:58:15 PM

Title: SetAtRef et al.
Post by: spandex on March 13, 2015, 02:58:15 PM
I am looking for a "Tutorial for Dummies" on the SetAtRef.* family of functions. I have the Visio 2003 Developer's Survival Pack as well as a pair of entries from a Microsoft blog. Unfortunately, we dummies need a much more detailed explanation. Google did not have much to offer.

Thanks.
Title: Re: SetAtRef et al.
Post by: Surrogate on March 13, 2015, 03:46:03 PM
May be this article by John Goldsmith (http://mvp.microsoft.com/en-us/mvp/John%20Goldsmith-4020443) can help
Shapes with global values (http://visualsignals.typepad.co.uk/vislog/2011/11/shapes-with-global-values.html)
Title: Re: SetAtRef et al.
Post by: wapperdude on March 13, 2015, 03:49:35 PM
Setatref() is the most mysterious function in all of Visio. Appropriately, it has the least amount of documentation.  It is definitely not something for dummies!

While you googled for Setatref, did you search this forum?  There're many posts on the topic.  Let me direct you here for starters, suspect you'll be back with more questions:  Trouble with relative position of line shape's label (http://visguy.com/vgforum/index.php?topic=5968.msg24073#msg24073)

Wapperdude
Title: Re: SetAtRef et al.
Post by: vojo on March 13, 2015, 04:14:38 PM
it would be great if somebody on this forum could write a nice tutorial for posting on visio guy.
What the intent is in general
  -human words not abstract speak such as "container", "object", etc
  - Illustrative examples showing both the formula and result image/shape/display
  - Vary the examples to see what its actually doing
Title: Re: SetAtRef et al.
Post by: spandex on March 14, 2015, 11:03:00 AM
Quote from: Surrogate on March 13, 2015, 03:46:03 PM
May be this article by John Goldsmith (http://mvp.microsoft.com/en-us/mvp/John%20Goldsmith-4020443) can help
Shapes with global values (http://visualsignals.typepad.co.uk/vislog/2011/11/shapes-with-global-values.html)
Thanks for the article!
Title: Re: SetAtRef et al.
Post by: spandex on March 14, 2015, 11:14:39 AM
Quote from: wapperdude on March 13, 2015, 03:49:35 PM
Setatref() is the most mysterious function in all of Visio. Appropriately, it has the least amount of documentation.  It is definitely not something for dummies!

While you googled for Setatref, did you search this forum?  There're many posts on the topic.  Let me direct you here for starters, suspect you'll be back with more questions:  [url]http://visguy.com/vgforum/index.php?topic=5968.msg24073#msg24073/url]

Wapperdude
You're right; I missed this thread. That's very helpful. It will take me a while to go through it. Thanks!
Title: Re: SetAtRef et al.
Post by: spandex on March 14, 2015, 11:39:49 AM
Quote from: spandex on March 13, 2015, 02:58:15 PM
I am looking for a "Tutorial for Dummies" on the SetAtRef.* family of functions. I have the Visio 2003 Developer's Survival Pack as well as a pair of entries from a Microsoft blog. Unfortunately, we dummies need a much more detailed explanation. Google did not have much to offer.
In case anyone is interested, here's what I'm trying to accomplish:

I want to be able to change the line rounding in two places and keep them synchronized: the standard Visio UI (invoked e.g. by Format | Line from the right mouse-click menu) and a custom property dialog (invoked by a DOCMD(1312) action as a result of a custom item from a right mouse-click menu).

To complicate things further, I want to add another item to the RMB menu that will enable/disable Rounding. If unchecked, the value of zero will be used. If toggling from unchecked to checked, the most recent non-zero rounding value (from either of the two sources) should be used.

Thanks!

Title: Re: SetAtRef et al.
Post by: spandex on March 14, 2015, 11:52:09 AM
Quote from: vojo on March 13, 2015, 04:14:38 PM
it would be great if somebody on this forum could write a nice tutorial for posting on visio guy.
What the intent is in general
  -human words not abstract speak such as "container", "object", etc
  - Illustrative examples showing both the formula and result image/shape/display
  - Vary the examples to see what its actually doing
That would be fantastic! I imagine that it would be quite an undertaking. I could easily see a whole chapter in a book devoted to it, so perhaps 10-20 pages would be a reasonable estimate.
Title: Re: SetAtRef et al.
Post by: wapperdude on March 14, 2015, 02:50:55 PM
@ Spandex:  couple of things re what you want to do.

1.  Bad news:  SETATREF won't work for what you want to do.  There are only a limited number of shapesheet entries for which it can be used:  https://msdn.microsoft.com/en-us/library/ff765523.aspx  (https://msdn.microsoft.com/en-us/library/ff765523.aspx).

2.  Good news:  you don't need it.  What you do need to use are
   A.  IF fcn to do the conditional checking...
   B.  The SETF(GETREF()) functional construct.

Basic info on these, and all shapesheet info can be found at the referenced link.  Search the forum for setf for examples.

Wapperdude
Title: Re: SetAtRef et al.
Post by: wapperdude on March 14, 2015, 03:24:16 PM
Correction!  MS lied.  SETATREF can be used for the corner rounding...I decided to try it since that is a UI parameter. 

So, for example, you have shape1 and shape2.  Open shape1 shapesheet and scroll to the Line Format section.  In the Rounding cell, enter this formula:  =SETATREF(Sheet.2!Rounding).  That's it.

The cool thing, it's bi-directional.  If you select shape1, change its corner rounding, shape2 inherits that rounding.  In addition, if you select shape2, change its corner rounding, shape1 inherits the rounding.

Moral of the story...try things before making suggestions   ::)  ...and, don't believe everything you read!   :o

HTH
Wapperdude
Title: Re: SetAtRef et al.
Post by: wapperdude on March 14, 2015, 04:17:19 PM
OK, so, my curiousity got the better of me...

Suppose that both shapes had a shapedata entry, Prop.bend.  Now, you want to use Prop.bend to control the rounding in both shapes, plus use the UI for rounding, and of course, not clobber the formulas.  Perfect scenario for SETATREF...mostly.

The temptation would be to do the following for each shape.  Shape1 shapesheet, rounding cell:  =(SETATREF(Prop.bend) + SETATREF(sheet.2!Prop.bend))*0.5.  The 0.5 factor is needed since the two results are additive.  Unfortunately, this only sort of works...the rounding of both shapes responds as expected, but, the Prop.bend cell in sheet.2 doesn't update.  Even if you don't do the 0.5 factor. 

Still wanting to keep this simple, and since SETATREF intercepts the direct changes (which is why the formulas don't get clobbered), the formula can be modified to =SETATREF(Prop.bend)+SETF(GETREF(sheet.2!Prop.bend),Prop.bend).  The SETATREF intercepts the direct change, recalcs the Prop.bend, and updates the Rounding cell.  The SETF fcn gets the Prop.bend cell in sheet.2 and updates it with the value of sheet.1's Prop.bend.  This has the added benefit that the results of the two functions are not additive...pun intended.   ::)

Of course, sheet.2's shapesheet needs similar entries, only, pointing to sheet.1.

Finally, the DblClick event has DOCMD(1312) to directly access the shapedata.

Attached is Visio file of all of the above to help visualize.  Each shape displays its own Prop.Bend and Rounding so you can see the changes in values as they happen.

Enjoy,
Wapperdude
Title: Re: SetAtRef et al.
Post by: JuneTheSecond on March 15, 2015, 04:42:47 AM
I am using SetAtRef to change color of invisible faces of my intelligent cube.
Title: Re: SetAtRef et al.
Post by: spandex on March 15, 2015, 11:15:07 AM
Quote from: wapperdude on March 14, 2015, 04:17:19 PM
OK, so, my curiousity got the better of me...

Suppose that both shapes had a shapedata entry, Prop.bend.  Now, you want to use Prop.bend to control the rounding in both shapes, plus use the UI for rounding, and of course, not clobber the formulas.  Perfect scenario for SETATREF...mostly.

The temptation would be to do the following for each shape.  Shape1 shapesheet, rounding cell:  =(SETATREF(Prop.bend) + SETATREF(sheet.2!Prop.bend))*0.5.  The 0.5 factor is needed since the two results are additive.  Unfortunately, this only sort of works...the rounding of both shapes responds as expected, but, the Prop.bend cell in sheet.2 doesn't update.  Even if you don't do the 0.5 factor. 

Still wanting to keep this simple, and since SETATREF intercepts the direct changes (which is why the formulas don't get clobbered), the formula can be modified to =SETATREF(Prop.bend)+SETF(GETREF(sheet.2!Prop.bend),Prop.bend).  The SETATREF intercepts the direct change, recalcs the Prop.bend, and updates the Rounding cell.  The SETF fcn gets the Prop.bend cell in sheet.2 and updates it with the value of sheet.1's Prop.bend.  This has the added benefit that the results of the two functions are not additive...pun intended.   ::)

Of course, sheet.2's shapesheet needs similar entries, only, pointing to sheet.1.

Finally, the DblClick event has DOCMD(1312) to directly access the shapedata.

Attached is Visio file of all of the above to help visualize.  Each shape displays its own Prop.Bend and Rounding so you can see the changes in values as they happen.

Enjoy,
Wapperdude

Wow, Wapperdude, I'm speechless. I really appreciate your help!

Going through your shapesheets, I have a question: when either of your shapes changes line rounding via the Shape Data dialog (dbl-click), what mechanism causes the Rounding field in the same shape to update?

Thanks so much!
Title: Re: SetAtRef et al.
Post by: spandex on March 15, 2015, 05:34:55 PM
Thanks to everyone's help, I believe that I have what I need:

A copy of the Visio doc is attached. Also attached is a PDF that shows the primary cell changes that are needed to implement this.

Thanks, again, for everyone's help

Title: Re: SetAtRef et al.
Post by: spandex on March 15, 2015, 08:01:37 PM
Long explanation about my ultimate goal follows:

BACKGROUND
This rounding issue is part of an effort to update a stencil I  have been using and tweaking for 15+ years (IIRC, before Microsoft purchased Visio). Two shapes that were distributed with Visio (Visio Technical?) really interested me. One was a circle with a connection point in the center and several connection points around the circumference. They had no special code. The second was a connector whose begin and end points would glue to the centers of two circles. In addition, a control near each end would be glued to a circumference of a circle. The connector would then be drawn between the circumferences of the two circles; the line and arrow(s) would not go inside it. Another control, which I call the AlterCurve control, allowed the user to raise or lower the height of the center of the curve. When AlterCurve was moved or one of the circles was moved, the ends of the connector would move themselves around the circumferences so that the lines/arrows would always point to the centers of the circles.

I modified the connector shape to add two primary features:


The curve was implemented using SplineStart and SplineKnot geometry rows. Over the years, I have added various rectangular shapes, including folder shapes, a database (or "store") shape, and a UML Actor shape.

CHALLENGE
I now need to support a general ellipse, but I needed more information on the Spline rows. Unfortunately,  these row type have been deprecated. I then considered NURBS, but that seemed like extraordinary overkill. I decided to use two straight lines and to utilize rounding to make it "curvy." That's where the rounding requirement comes from. The connector must be completely redone to remove the Spline vestiges.

I have almost everything working, but I need to do a lot of testing.

Question: would this stencil be of interest to anyone? If so, I could attach it to a subsequent post once I have it ready.

Thanks!
Title: Re: SetAtRef et al.
Post by: wapperdude on March 16, 2015, 12:30:17 AM
@spandex: 
QuoteGoing through your shapesheets, I have a question: when either of your shapes changes line rounding via the Shape Data dialog (dbl-click), what mechanism causes the Rounding field in the same shape to update?

The attached drawing shows the SETATREF process as applied to your case.

Wapperdude
Title: Re: SetAtRef et al.
Post by: wapperdude on March 16, 2015, 05:24:00 AM
Not at the level that Vojo was requesting, that would take considerably more time, but here's an update to some simple documentation as pertains to this particular post thread.

There is one disclaimer, on page-3, I state that SETATREF avoids endless looping.  Haven't confirmed that statement, so, just beware!

The Visio file has 3 pages.  It's a small start.

Wapperdude

EDIT:  Ooops.  The sheet.2 diagram should look same as sheet.1 block diagram.
Title: Re: SetAtRef et al.
Post by: spandex on March 25, 2015, 05:28:24 PM
Thanks so much, Wapperdude, for these examples. I just downloaded the latest updates from the What's with SETATREF anyway? topic, and I plan to go through it until I understand SetAtRef.

I implemented Example 2 in the SETATREF Function.docx file, and I'm having a hard time understanding parts of it. I can see how moving the child shape works, but how does moving the parent cause the child to follow? If it's via normal "dependency" recalculation, what part of the PinX/Y formulas are involved? The first of two articles from Microsoft's blog states this:

During the recalc operation, the SETATREF function is transparent. SETATREF(x) = x. In other words, the result of the recalc is just like if there were no SETATREF wrapped around the cell references.

At the risk of seeming pedantic, SetAtRef most frequently seems to have two arguments. So, which of these two are correct for normal recalc:

SetAtRef(x,y) = x
SetAtRef(x,y) = y

Thanks for any help you can provide!
Title: Re: SetAtRef et al.
Post by: wapperdude on March 25, 2015, 08:34:50 PM
I've only seen SETATREF with single argument...best I recall.

Take a look at the latest Visio file...It diagrams basic function of the formula, has examples, progresses to the full syntax implementation...SETATREF(SETATREFEVAL(SETREFEXPR())).
Title: Re: SetAtRef et al.
Post by: spandex on March 26, 2015, 12:01:46 PM
Quote from: wapperdude on March 25, 2015, 08:34:50 PM
I've only seen SETATREF with single argument...best I recall.

I'm likely using incorrect terminology. I copied this from your SETATREF Function.docx file:

Syntax:  SETATREF(reference [,set_expression [,ignore_eval]])

I use the term arguments to refer to the list of comma-separated values inside the parentheses. If this were correct (and it looks like it isn't), SETATREF with two "arguments" (i.e., SETATREF(reference, set_expression)) is the most prevalent usage I've seen.

Quote from: wapperdude on March 25, 2015, 08:34:50 PM
Take a look at the latest Visio file...It diagrams basic function of the formula, has examples, progresses to the full syntax implementation...SETATREF(SETATREFEVAL(SETREFEXPR())).

Fantastic! Thank you SO much for all of your efforts.

Title: Re: SetAtRef et al.
Post by: wapperdude on March 26, 2015, 02:54:38 PM
Ah!  Yes, I would say your terminology is probably correct.  What threw me off was
   SETATREF(x,y) = x
   SETATREF(x,y) = y

While those may be valid statements, context is crucial!  Each represents a step in progress of the function executing.

As an end user, I can only share my experiences and my understanding as a result of those experiences.  So, while I try to be accurate, don't take what I share as authoritative.  Indeed, I still make discoveries and experience "Aha!" moments.

Back to your question about single argument...yes it's valid.  It is one of the MS examples.  Yes, it is the less common form seen. In addition, there are other ways to exploit SETATREF to effectively have two "references".  This last scenario involves placing SETF inside the SETATREF function.

Examples are in the Visio file.

Wapperdude



Title: Re: SetAtRef et al.
Post by: Visisthebest on November 26, 2022, 11:48:16 AM
Wapperdude thank you amazing work on helping us understand SETATREF() better, still getting my head around it but it is already solving my problem with the behavior of the List structure shape. Only SETATREF works for this, GUARD() does nothing to protect my formulas in this case.
Title: Re: SetAtRef et al.
Post by: wapperdude on November 27, 2022, 05:11:11 AM
@Visisthebest:  don't know if you've seen this development, http://visguy.com/vgforum/index.php?topic=6383.msg26747#msg26747 (http://visguy.com/vgforum/index.php?topic=6383.msg26747#msg26747), but it's a quasi tutorial on the Setatref() family of functions.
Title: Re: SetAtRef et al.
Post by: Visisthebest on November 27, 2022, 10:28:14 AM
Yes I meant that topic as well thank you Wapperdude, very useful Visio example files to understand SETATREF functions better!
Title: Re: SetAtRef et al.
Post by: wapperdude on November 27, 2022, 03:29:41 PM
👍