resolved : get wire connector attached to wire note

Started by smr, July 08, 2008, 03:50:31 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

smr

Hello,
I just wrote my first macro and know how to get visio shapes names and wire note text!

I draw an electric diagram with wire connectors and a wire note for each connector to show name of wire.

Now I would like to get by VBA code, the text of the wire note attached to a wire connector, so I will know the name of the wire, or vice-versa, could I get the wire note attached to a particular wire connector?

Thanks in advance for any help

Lars-Erik

I used the macro recorder:
Start a new macro, edit the label of a connector and then stop the macro

It basically gave me this:
Application.ActiveWindow.Page.Shapes.ItemFromID(1).Characters

Where the ItemFromID(1) should be replaced by the connector's shape.

Hope it helps.

(The macro recorder can help a lot with getting commands like this!)

- Lars

smr

Hello, thank you for this help ; it is not the right result I was looking for, but it helped me.

I did what you suggest with recording a macro. What I get is the ID of the wire note, but not the ID of the wire connected to this wire note.

So I looked in detail to the shape sheet of the wire note, and succeed to read a near hidden info on first line, in 1-D Endpoints section, for BeginX and BeginY that says :
"PAR(PNT(Socket outlet.313!Connections.X2,Socket outlet.313!Connections.Y2))"

So I saw the wire name in relation to my wire note!
Next step was how to get with VBA, the content of this shapesheet cell!
after some Google searches, I found some use of CellsSrc property, and the possiblity to access a shape sheet cell content by its name as Cells("BeginX") So I tried to get
MyShape.Shape.Cells("beginx"), but that gave the BeginX value, of course
So I tried
MyShape.Shape.Cells("beginx").formula and that's it! It returns :
PAR(PNT(Socket outlet.313!Connections.X2,Socket outlet.313!Connections.Y2))

Now I should parse the content text and get the first part where shape name is.

Thanks again.

Serge

Visio Guy

Serge,

For the connector shape, look at the Connects collection, and the ToSheet property.

For the connected-to shape (ie: the Box), look at the FromConnects collection, and the FromSheet of each connect item.
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

wapperdude

There is a code example, ShowPageConnections(), at this link: http://msdn.microsoft.com/en-us/library/aa201776(office.10).aspx.  It uses the connect, connects properties as indicated by Visio Guy.  This routine does more than you need, but, it does extract the name (ID) of the dynamic connector and the shapes it is connected to.  I think you will need all of these features to single out particular connectors.
Visio 2019 Pro

smr

Hello,
Thanks for all these useful answers.
The way I mentionned is not safe, because when some connectors are just connected on "geometry" and not to connection points, the ID are not given.

So I solved my problem by giving a name of my own to each electrical shapes I draw, with shape data form and add a user property. Then I parse the shapes and when finding a wire connector shape, I catch this user name value and get the wire length like this :

For Each pag In ThisDocument.Pages
For Each myshape In pag.Shapes
  If InStr(1, shp.Name, "Wire con") Then
   wiredata=myshape.Cells("prop.index").FormulaU & ";" & Round((myshape.LengthIU) * 0.0254, 2)
....

I had a look on the microsoft sub example and it is very interesting. I tried it but for the few shapes I looked in, I saw that the code gives only the Visio name of wire connectors or plugs, but i didn't see if it gives the wire note reference. But this is very interesting for building a net list.
Thanks
Serge


smr

Hello,
I found another (better) solution, using the wapperdude's link ; beneath this link, I learned how to use the ToSheet property!

here is my code to get plugs, outlets... connected to a wire  and add connected shapes elevation to wire length :
(for another Sub, I could filter connected shapes to only catch Wire notes)

For Each pag In ThisDocument.Pages
i=0
    For Each shp In pag.Shapes
         
            If InStr(1, shp.name, "Wire con") Then
            i = i + 1
             ReDim Preserve myArray(i)
             length = 0
             name = shp.Cells("prop.name").FormulaU

              For j = 1 To shp.Connects.Count
               test = InStr(1, shp.Connects.Item(j).ToSheet, "outlet") + InStr(1, shp.Connects.Item(j).ToSheet, "switch") _
               + InStr(1, shp.Connects.Item(j).ToSheet, "light") + InStr(1, shp.Connects.Item(j).ToSheet, "lum")
               
              ' test= InStr(1, shp.Connects.Item(j).ToSheet, "wire note")  to only catch wire notes
             
               If test > 0 Then

                  length = length + Val(shp.Connects.Item(j).ToSheet.Cells("prop.baseelevation").FormulaU)

               End If
             Next
           length = length + Round(shp.LengthIU * 0.0254, 2)    'get metric unit
           myArray(i) = name & ";" & length

        End If
    Next shp
      BubbleSort myArray

     ' print array
Next pag

Thanks for your helps

Serge