Visio Guy

Visio Discussions => Shapes & Templates => Topic started by: VMey on October 01, 2014, 09:30:27 PM

Title: [SOLVED] Trouble with relative position of line shape's label
Post by: VMey on October 01, 2014, 09:30:27 PM
Hello,

This is my first time posting on any Visio forum so I apologize for not using the proper terminology.

I'm using a stencil developed by someone else and I am trying to resolve an annoying issue.  I've attached supporting files that should be descriptive enough that you don't need to read EVERYTHING below, but I've been detailed just in case.

The stencil is for data flow diagrams and the shape in question is a data flow shape, an arc-shaped line with an arrow and a descriptive label.  The arc is comprised of two end points and two control handles.  One control handle adjusts the arc shape (Control1), and the other control handle adjusts the label position independently (Control2).  (Control1 and Control2 are arbitrarily assigned for this post only, not official variables)

Upon initial placement and population of the label, any action upon the line results in the label and the line moving relative to each other, and this is how we want it to be.  Adjusting Control1 results in the label mirroring the position of that control handle, the same relative distance and position.  Increasing the height of the arc increases the height of the label, for example.  Similarly, adjusting the endpoints either by angle or by width results in the label moving relatively

However, this label can get decoupled and forever cease to move relatively anymore.  This happens by changing Control2, that is repositioning the label independently.  Once this occurs, it no longer moves relatively with Control1.  It DOES still move with the endpoints though.  So if I've lifted the label an inch above the arc, and then rotate using the endpoints, the label also rotates, maintaining horizontal orientation, but staying the same distance from the line.  But if I change the Control1 position, say change it from arcing upward to a steep downward arc, the label will remain where it was last dragged, and can never be recoupled again.  You just have to keep repositioning the label as you make adjustments, or delete the shape and drag from the stencil again.

I have attached sample files to demonstrate this, a .vss file and a .vsd file.

The cause identified, but solution unknown
Looking at the ShapeSheet, I have identified technically what has gone wrong, but I do not know how to fix it, as this is the first time I've attempted such an adjustment (I'm used to Excel Visual Basic, this is a whole different paradigm!)

When originally placed, the Controls section of the ShapeSheet contains two items, Controls.Row_1 and Controls.Row_1, which correspond to Line Arc Position, or Control1, and Label Position, or Control2.  By default, Controls.Row_2 column X and Y are populated with formulas, "Controls.Row_1" (aka align the centers), and "Controls.Row_1.Y+0.1875" (aka position the label 3/16ths of an inch above the line).  So when Control1 is moved up and down, these fields don't change, and that's why it works.

But when Control2 is moved, the formula-driven values go away and are replaced with actual, descriptive values, such as X=Width*.95 and Y=.5313 in, so there's no longer that relative, formula-based attachment to Control1.  The reason it stays relative with the endpoints is, I THINK, due to the Text Transform section, TxtPinX/Y and TxtLocPinX/Y, which both have formulas in them (Controls.Row_2, Controls.Row_2.Y, TxtWidth*0.5, and TxtHeight*0.5).


So!  What do I do to keep from decoupling Control2 from my Control1 movements when I want to make positional adjustments?

The attached VSD shows each stage, with 1a-1c demonstrating movement without changing the position of Control2, and 2a-2d demonstrating movement WITH changing position of Control2.

Thanks for any help.
Title: Re: Trouble with relative position of line shape's label
Post by: wapperdude on October 02, 2014, 12:48:09 AM
Thorough is good!

The problem is that when the 2nd control point is moved, it clobbers any reference to the 1st control point.  To solve this, you need to use the setatref function.  See this post, and look at my solution:  http://visguy.com/vgforum/index.php?topic=5450.msg21617#msg21617. (http://visguy.com/vgforum/index.php?topic=5450.msg21617#msg21617.)

I believe you need to do the similar steps.

Wapperdude
Title: Re: Trouble with relative position of line shape's label
Post by: wapperdude on October 02, 2014, 01:17:31 AM
Ooops!  You're using inches.  OK.  Here are the specific changes, since there are already two rows in the User-defined cells.

Add two new rows, and set their initial values as:
User.Row_3 = 0
User.Row_4 = 0.15

Then in the Controls Section, Controls.Row_2 line:
X Value =SETATREF(User.Row_3,SETATREFEVAL(SETATREFEXPR(Width*0.425)-Controls.Row_1))+Controls.Row_1

Y Value =SETATREF(User.Row_4,SETATREFEVAL(SETATREFEXPR(0.25 in)-Controls.Row_1.Y))+Controls.Row_1.Y

That should do it.

Wapperdude
Title: [SOLVED]Re: Trouble with relative position of line shape's label
Post by: VMey on October 02, 2014, 03:39:12 PM
Wapperdude,

Thanks so much for your help.  I was able to apply this to a number of shapes in our stencil set, and I've passed on the changes to our Visio SME.  Everything appears to work wonderfully.

Later on I'll have to dig into those function names and see if I can understand exactly what's going on :)

All the best,
VMey
Title: Re: [SOLVED] Trouble with relative position of line shape's label
Post by: wapperdude on October 02, 2014, 04:49:55 PM
Great!

Just a warning about setatref:  it is not easy to understand, and less easy to use.

Wapperdude
Title: Re: [SOLVED] Trouble with relative position of line shape's label
Post by: Yacine on October 02, 2014, 05:02:57 PM
I can confirm Wapperdude's statement. Everytime I need a setatrefexpr, I need to ask him for help.  :o ;D
Title: Re: [SOLVED] Trouble with relative position of line shape's label
Post by: VMey on October 02, 2014, 09:48:48 PM
Doesn't exactly make things all crystal clear, but for others who find their way to this question, here's the Microsoft article on the SETATREF Function.

SETATREF: http://msdn.microsoft.com/en-us/library/ms425563%28v=office.12%29.aspx (http://msdn.microsoft.com/en-us/library/ms425563%28v=office.12%29.aspx)
Title: Re: [SOLVED] Trouble with relative position of line shape's label
Post by: wapperdude on October 02, 2014, 10:05:57 PM
That's a major part of the problem, setatref is not intuitively obvious, and the documentation is pretty sparse.

There was a site that had some helpful setatref examples and explanations:  blogs.msdn.com › Visio Insights.  I don't think it's actively supported any more since V2010 & V2013 came out.  The articles are still there, but the pictures (at least for me) have disappeared.  That's unfortunate, because you need the pictures to understand the articles.  But here's the references:
http://blogs.msdn.com/b/visio/archive/2006/09/26/771488.aspx (http://blogs.msdn.com/b/visio/archive/2006/09/26/771488.aspx)
http://blogs.msdn.com/b/visio/archive/2006/09/29/777101.aspx (http://blogs.msdn.com/b/visio/archive/2006/09/29/777101.aspx)

Unfortunately, those were two of the best articles dealing with setatref.

Wapperdude