Automatic Cable Labels

Started by gunslingor, January 24, 2013, 01:17:44 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

gunslingor

I've designed a number of 3D isometric shapes, and I've gotten pretty good at it. However, I've never really designed a smart shape and I have a need for one now. So any references, tutorials, advice, code or solutions is appreciated to either get me started or to due it for me =).

What I need to accomplishs is as follows:
a) All my shapes have a unique ID associated with them. Right now these are just assigned using the shape text, but I could also apply these to the shape  sheets name property.
b) So, say two shapes are connected via a connector line (blue for ethernet). What I'd like to be able to do is to drop the flow chart oval shape and cut the line connecting the two shapes (easy enough to do). The hard part I need help with comes next.
c) I then need this oval shape's shape text to become "[unique ID of first shape]>[unique ID of second shape]". Later I'd like to be able to turn this into "[unique ID of first shape] port [port of first shape]>[unique ID of second shape] port [port of second shape]".

Basically it'll be an auto-cable-tagging shape so we can maintain consistent cable tagging conventions.

Any advice is appreciated.

aledlund

Can you share with us what version/edition of Visio you're using for this?
al

gunslingor

#2
yeah, Visio 2010. I've been working with the following code snippet found online:

Public Sub GetOutgoingShapes()
'Use Shape.ConnectedShapes to get the shapes that are outgoing connections from a shape
    Dim shp As Visio.Shape
    Dim shpIDs() As Long
    Dim i As Integer

    If ActiveWindow.Selection.Count = 0 Then
        MsgBox ("select a shape with connections")
        Exit Sub
    Else
        Set shp = ActiveWindow.Selection(1)
    End If

    shpIDs = shp.ConnectedShapes(visConnectedShapesAllNodes, "")
    For i = 0 To UBound(shpIDs)
        Debug.Print ActivePage.Shapes.ItemFromID(shpIDs(i)).Name
    Next
End Sub


[help needed here]
I am experienced with VBA in access, but zero experience in visio. I'm pretty sure I can work with this code, but there are pieces missing in my education. First I need to get this code to assign the results to the shapes text rather than the debug window. Then I need to figure out events so that this code runs whenever connections change.

[not needed here]
I suspect I'll be able to figure out this last part which is to do some type of sub string operation to pull out only certain data from each connected shape name. My shape names are in this format XXXX-XXX-XXX-XX.XX-X and I only want the "XX.XX" part.

[help needed here]
Once I get all that working properly, I'll have to deal with off page connectors... AHHHHHH! i.e. I don't want the off page connectors name to be involved, only where it goes on another page (which will be a separate file). Modified: on second thought, it may not be terrible if its the off page connector... but preferablly not.

Thanks!

aledlund

Will the name always by in five parts? Do you intend to create your own network shapes (goes to the question of how the connection points may or may not be named)? Can you share a simple drawing with your names applied (three or four shapes and connectors should be enough)?
al

gunslingor

QuoteWill the name always by in five parts?
5 parts minimum, the 6th part only comes into play if more than one device is in the same rack and row, like two PC towers. Here is an excerpt from the key diagram explaining the details of the device tags.

I've redacted the company department fields for obvious reasons, but here's the other allowed values


Note that if the device is not housed in a rack, then the XX.XX part needs to be something else along the lines "WS1OP" for workstation 1 operators or "ORCSRVPRI" for oracle server primary. Because of this, I'm fairly certain the best way to substring this will be to count until the 4th "-" and stop at the fifth"-" OR end of string. Do this for both tags and add a ">" inbetween. Ports I'm sure will be more tricky, but I don't need to worry about that for a long time (6 months to a 1 year).

QuoteDo you intend to create your own network shapes (goes to the question of how the connection points may or may not be named)?
The network diagrams I am working on are 50% complete with roughly 500 devices so far. As a HARD and fast rule, I only use explicitly defined connection points to link shapes with connectors. Now, most of my shapes are from the "VSDfx-Generic-3D" Stencil, but I found I had to relayout the connection points because they weren't symetrical and too few; So I used guides to add connection points in a semi symertical way (helps maintain even spacing between lines leaving the shape. I have NOT worried about the names of connection points... but I see where you are going with this.. port numbers right? If so, absolutely this seems like a valid solution.... but I want to ignore port numbers for now (mainly because I'm 50% done with the diagram and need to finish the rest in 3 months time, I've I start worrying about port numbers now it'll delay the release by 6months to a year). I have created my own shapes as well, and grabbed some from other stencils, but generally when I make my own shape I use an existing shape and just widdle down opening groups until I can edit the thing. Then I reassign connection points as described above.

QuoteCan you share a simple drawing with your names applied (three or four shapes and connectors should be enough)?

Sure, here's a quick sample, changed slightly to protect the names of the innocent =). The actual drawings are huge, on 44x34 sheets:
https://docs.google.com/file/d/0B71fEvZJKoXBZnBkTE9PQ3E2ZHM/edit

aledlund

That should be enough to get started.
tks,
al

aledlund


aledlund

Gunslingor,
this should help get you started. The macro scans the page looking for the label shape and then finds the endpoints, parses the text based on what you described and comes up with the location field. It will also post some errors and messages if it finds some error types. What do I mean by errors.
a.) directionality of inbound and outbound is determined by where you start and end connectors. For label A the connectors start at the label, so this gives you two outbound connectors and no inbound connector (can't define source and sink)
b.) text formatting, you left out some required hyphens so the parser flagged the shapes in the immediate window (the jpg I attached)
Some suggestions

rather than relying on parsing a text stream which can have errors in it, put the data into shapedata in the shapes and draw it directly from there ( you can then use datagraphics rather than text)

Rather than building custom connectors that only have color changes, use dynamic connectors with shapedata tied to color, etc.

You can have off-page connectors with labels on them, David Parker shows some of that on his blog
http://blog.bvisual.net/

hth,
al

gunslingor

Wow thanks. This should be enough to lead me down the right path. I didn't think I'd have to deal with inbound/outbound, I mean most of these connections are bidirectional ethernet so as of now where I started and ended a connection is entirely arbitrary. Thanks for taking the time, I'll review in full and get this baby workin.

gunslingor

My code is coming along. I'm parsing the two connected shapes effectively, and I can assign this to the tag's shape text. The only problem is that this code only runs when manually initiated, and only for the selected shape. I'd like for it to run whenever the connections to the tag change, but I don't think there is any event for this. How does this code effect DB efficiencies? I mean, if I manage to get it working such that the text changes whenever the connections change, and I put say 300 of these on the drawing for all the ethernet cables... is the size or speed of the DB going to be effected?

Also, what's the best way to ensure this code can only run for the cable tag shape and no other shapes... wouldn't want all my network shapes to be relabeled by mistake.

Thanks

aledlund

None of this code will have an effect on the database operation because it happens after the shapes are placed onto a drawing.

The code fires manually because we haven't implemented a device handler to call it. My thoughts on the  flow would to be drop the connector on the page, place your label shape into the end shapes and when that completes call the label routine.

Right now the code looks specifically for the shape you are using for the label and then validates it be making sure you have a single inbound and outbound connector before looking for the connected end-shapes.

Ethernet (CSMA/CD 802.3) by design is a half-duplex operation and requires separate inbound and outbound paths for full-duplex, most people 'cheat' by just drawing a single physical cable while think logical connection. That's why I always put a duplex shapedata flag on the link and the port (simplex, half, full) and then handle any unique requirements in code. We don't normally think about it with fibre (how many single strand links do you have :-)).


al

aledlund

by the way if you call the macro from an event you might want to modify it so that it doesn't search the entire page for the shape/connectors you want to modify.
al