Dynamic Connector's Text Randomly Moves

Started by SirHandyMan, February 18, 2014, 06:59:19 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

SirHandyMan

I found the Visio Guy article for having a connector's text follow the connector. 
http://www.visguy.com/2010/02/09/text-along-a-connectors-path-in-microsoft-visio-2010/

I am using Visio 2013 Professional along with the shapesheet code provided by Ilya Kharlamov (posted on 10/14/2012 in the comments section of the article).
 

User.angPathEnd=ANGLEALONGPATH(Geometry1.Path,User.pathFraction)
User.pntPathEnd=POINTALONGPATH(Geometry1.Path,User.pathFraction)
User.TextAngle=User.angPathEnd+GRAVITY(User.angPathEnd)
User.TextPin=PNT(PNTX(User.pntPathEnd)-TxtLocPinX*COS(User.angPathEnd),PNTY(User.pntPathEnd)-TxtLocPinX*SIN(User.angPathEnd))
User.txtState=2
User.pathFraction==((User.txtState-1)/2)+((1-((User.txtState-1)/2))*TxtWidth/PATHLENGTH(Geometry1.Path))
Action.Row_1.Action=""
Action.Row_1.Menu="Text Orientation"

Action.Row_2.Action=SETF(GetRef(TxtPinX),"SETATREF(Controls.TextPosition)")+SETF(GetRef(TxtPinY),"SETATREF(Controls.TextPosition.Y)")+SETF(GetRef(TxtAngle),0)+SETF(GetRef(Controls.TextPosition.YCon),0)+SETF(GetRef(User.txtState),0)
Action.Row_2.Menu="Position by Control Handle"
Action.Row_2.Checked=User.txtState=0

Action.Row_3.Action=SETF(GetRef(TxtPinX),"GUARD(User.TextPin)")+SETF(GetRef(TxtPinY),"GUARD(User.TextPin)")+SETF(GetRef(TxtAngle),"User.TextAngle")+SETF(GetRef(Controls.TextPosition.YCon),5)+SETF(GetRef(User.txtState),1)+SETF(GetRef(Para.HorzAlign),User.txtState-1)
Action.Row_3.Menu="Start"
Action.Row_3.Checked=User.txtState=1

Action.Row_4.Action=SETF(GetRef(TxtPinX),"GUARD(User.TextPin)")+SETF(GetRef(TxtPinY),"GUARD(User.TextPin)")+SETF(GetRef(TxtAngle),"User.TextAngle")+SETF(GetRef(Controls.TextPosition.YCon),5)+SETF(GetRef(User.txtState),2)+SETF(GetRef(Para.HorzAlign),User.txtState-1)
Action.Row_4.Menu="Mid"
Action.Row_4.Checked=User.txtState=2

Action.Row_5.Action=SETF(GetRef(TxtPinX),"GUARD(User.TextPin)")+SETF(GetRef(TxtPinY),"GUARD(User.TextPin)")+SETF(GetRef(TxtAngle),"User.TextAngle")+SETF(GetRef(Controls.TextPosition.YCon),5)+SETF(GetRef(User.txtState),3)+SETF(GetRef(Para.HorzAlign),User.txtState-1)
Action.Row_5.Menu="End"
Action.Row_5.Checked=User.txtState=3


The code works perfectly and the connectors behave as expected until I save/close the file and open it again.  When I open the Visio file, sometimes a connector' text will be just fine and sometimes the text be in a different part of the diagram, or even hidden.  I have a diagram with ~40 of these connectors, created from the same master, and they seem to behave differently each time I open the Visio document. 

If I make a change to one of the problem connectors (move, disconnect, reconnect), then the text repositions itself to the proper location again and all is well until I close and reopen the file.  Then I have to go through each problem connector and modify it in some way to get the text to behave again.

NOTE: I tried the two solutions provided by Visio Guy in his article and I get the same behavior.

So here are my questions:

Is this happening because of a flaw in the code, or because of a bug in Visio 2013?

Is there a way to protect (lock) the position of the text to prevent this from happening?

Does anyone have any other suggestions on how to get the text position to be reliable when reopening the file?

Thank you!

SirHandyMan

Here are some screen captures of the problem.

In the master's shapesheet, the following values are being set:

txtAngle=GUARD(User.TextAngle)
txtPinX=GUARD(User.TextPin)
txtPinY=GUARD(User.TextPin)

JuneTheSecond

#2
It smells like a matter on calculating coordinates in sub shapes.
I recommend for you to check LOC function or PAR function.
For example
txtPinX=GUARD(LOC(User.TextPin))
or
txtPinX=GUARD(PAR(User.TextPin))
There are other very confusing functions, LOCTOPAR, etc..

Best Regards,

Junichi Yoda
http://june.minibird.jp/

SirHandyMan

Thank you for the suggestions JuneTheSecond.  I tried your approaches and they didn't help the problem.

I really think it is a bug in Visio 2013.  I saved the file in Visio 2010 format and used Visio 2010 to open it.  I can manipulate/save the file in Visio 2010, close it and open it back up in Visio 2010 and everything appears as expected.

I did find a work-around in Visio 2013.  When I open the file, I perform a "CTRL+A" (select all), go to the "DESIGN" tab, click on the "Connectors" button and change the connectors to "Straight".  Then type "CTRL+Z" (undo).  All connector text then appears as expected.

SirHandyMan

So, it might not be a bug in Visio 2013, but it may be a conflict with theme effects that Visio 2013 applies.

I opened the Visio 2010 version of the file in Visio 2013, and everything continued to behave as expected.

When I originally performed a save-as and converted the file from the 2013 format to the 2010 format, I received a message from the Visio Compatibility Checker that gradient and theme effects would be removed.

Now that I have narrowed the problem down to the theme effects, does anyone have any theories as to what might be conflicting with this code?  I think I'll just keep it in the Visio 2010 format for now, but I'd like to find the root cause if possible.