How to glue line to shape but maintain line orientation on shape resize

Started by Budgie, September 20, 2008, 09:01:32 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.


Hi guys, 

   Using Visio 2003 pro..

  I am creating network diagrams using my own custom templates/stencils.  I have drawn a generic box shape to represent a 'network device' and then use a small, straight line with an offset text box (hangs just below the line) to represent an 'interface' (i.e. "GE0/0").  This all works nice; the line serves as a nice delineator between multiple interfaces and either end of the 'interface' line auto glues to the either side of the 'network device' shape. 

  My problem is when I make the shape bigger (i.e. make it taller so I can fit more 'interfaces' in it) the line end that is glued to the shape moves vertically with the shape wall as the shape is scaled however the other end of the line end (that isn't glued to anything) remains in the same location thus the 'interface' line ends up being angled up/down depending on whether I made the shape taller or shorter.

  Is there something I can do to maintain my 'interface' line as a flat/horizontal item?  For example; move both ends of the line up/down when I make the shape taller/shorter.  Also, I want the 'interface' lines in my 'network device' shape to move with the shape.  i.e. if I relocate my device shape I want all the interface lines to remain glued to the shape and relocate with it whereas now they just bunch up....

   I'm happy to look at other ways of doing this if there's an easier way.  Note: I have looked at using 'connection points' in the shapes however this means a stencilled 'network device' shape has to be pre-formatted with a given number of 'interface' connections points plus, as you make the 'network device' shape taller/shorter the spacing between the connectors changes (which I don't want to happen).

  All advice greatfully accepted.

  I have attached an example which hopefully makes the easier to understand

cheers Tony


This ought to solve your problem.   :) First, protecting the height, width, rotation doesn't help because Visio overwrites the connector endpoint with a formula.   :( But, select the connector (line) and either right click to select shapesheet (if in Developer mode) or menu bar>Window>show shapesheet.  The 1st section ought to be 1-D Endpoints.  Change the entry for EndX to be something like:  GUARD(BeginX+25 mm).  The 25 mm is the horizontal distance of your line.  Do a similar change for EndY.  This "slaves" both the x- and y- dimensions of the end point to the begin point.  The Guard fcn, hopefully, prevents Visio from clobbering your formula.  But, dynamic connectors are weird, so beware.   :P
Visio 2019 Pro


Slight correction.  This technique does NOT work with the dynamic connector.  It does work with the line tool.  Sorry about the confusion.  :'(
Visio 2019 Pro


Thanks Wapperdude,  I'll try this tomorrow and post the results.

Note: after posting my question I did some more playing and did find a simple (but dodgy) solution.  In my network device shape I added and grouped a line at the inside shape location of the other end of the line (i.e. the line end that wasn't glued to the shape edge).  I hid this new line at the back of the shape but this new line meant the 'interface' line now glues at both ends (one end on the shape edge and the other on the new line).  This works kinda ok but occasionally the glue'ing goes out of wack and the line ends up angled anyway.  I'll try your method tomorrow.

cheers tony


Hi Wapperdude, I've just tried your fix and that seems to work a treat (so far).  I need to do some more testing but seems to be working fine.  FYI, I set the EndX=GUARD(BeginX+10 mm) and EndY=GUARD(BeginY+0 mm)

Thanks heaps for your help, I'll let you how this works out.

cheers Tony


  Wapperdude provided a neat fix for my problem (thanks  :)) but I now have another issue.  I've noticed that my 1-D 'interface' line only glues on the left hand side to shapes.  When I drag my 'interface' line next to a shape the left side of the line glues (turns red) to shapes and stays glued when I resize the shape however the right side of the line looks like it glues (also turns red when you move it over a shape edge) however after dropping the line the glue is gone.  When I resize my shape the lines glued on the right side/ends don't move.  I've noted that if you select the 'interface' line the left end of the line has an 'X' whereas the right end has an '+', I assume this is denoting some kind of line end, glue difference but don't know what/how to fix it.  I can resolve my issue by rotating my line 180degrees (and my text box) however this fix would mean I would need two 'interface' line stencils, one that glues on the left (normal) side and another that glues on the right (180degree rotated left) side....

Again hoping you guys can assist.

cheers Tony


I don't have your file in front of me at the moment, but a couple of points.  In my test case, even though I have snap and glue to geometry enabled, when you place the line on the geometry edge, the connector point must be red when you release the line, otherwise, it has not glued.

2nd, if you also have lines that extend either to the left or right, not to mention upwards and downwards, then the "fix" needs to be modified such that a single version will work.  That is, the line shape needs to become smarter.  One approach would be as follows:
A.)  Open the shape sheet for your line.
B.)  Right click to add two sections:  User Defined and Actions.
C.)  Edit the User Defined section and change the name "Row_1" to "Right", and the entry for the Value cell is "1" (no quotes.)  The new row name will be User.Right.
D.)  Edit the Action section.
       1.)  Optional -- change name from "Row_1" to "Title", and set the Menu entry to "_Line Direction"
       2.)  Add a 2nd row, change name to "Right" and edit the following cells as follows:
                Action = SETF(GetRef(User.Right),1)
                Menu = "_Right"  with the quotes
                Checked = User.Right=1
       3.)  Add a 3rd row, change the name to "Left".  Make the same edits as in 2.) except change the "1" to "0"

E.)  Edit the 1-D Endpoints Section entries
        1.)  BeginX = GUARD(IF(User.Right,(BeginX+2 in),(BeginX-2 in))) where the 2 in is your value and units.

F.)  Check the Connection Points Section -- you may have to add it to the shape sheet.  You probably want to change the Type /C entry to be a 1.

If only left and right are options, then you're done.  If you want to have the lines extend upwards and downwards, then you need to duplicate the above steps for the cases "Down" and "Up".

Now, if you right click on your line shape, you have the option to select the line extension to either the left or right.  It's taken longer to write this than it does to do the edits!   :P

Sure HTH!!!   ;D
Visio 2019 Pro



  not sure how you're thinking this stuff up but it works!!  I did run into a problem whereby when using your new code; when I flipped my line to the other side (via the new user action) the 'interface' text also flipped 180 deg (text was upside down) but I fixed this by setting the TEXT BLOCK FORMAT, TxtAngle to "=GUARD(IF(User.Right,(0 deg),(180 deg)))"   See, I can hack someone elses good work but cant create my own code.... :P

   This fix works fine (thanks heaps for your help) however it's not very elegant (please don't take this as a criticism, I really do appreciate your help but I think the plebs using the template will forget to 'flip the line' using the action and thus lose line gluey'ness..) so if you've any other solutions/ideas I'm all ears.   Having said all that though, you've delivered a solution that works and I really appreciate it.

thanks again Tony


Hey!  No problem.  The ideas just come from extensions of things done in the past.  BTW, keep hacking, that's a good way to learn.  Regarding the text rotation, you might want to check out this link:  For shapesheet background:

I understand your concern about the left - rightedness solution.  Actually felt there might be an issue there.  Not sure the of the best way to attack it.  Well, I know what would be nice, just have no idea how, perhaps someone will pick up on this...What would be nice is, as you drag the line over the shape that you want to connect to, the line senses whether you are left or right of center and automatically changes direction upon gluing.  But that's involved and I think would involve VBA code.   :P  Alternatively, it might be possible to remind the user by adding a Shape Screen Tip.  That way, when you hover over the line, a message will pop-up reminding the user to set the orientation.   ???  Go to menu bar > Insert > Shape Screen Tip.

Visio 2019 Pro