<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Get the ID of a snapped device in VBA Forum</title>
    <link>https://forums.autodesk.com/t5/vba-forum/get-the-id-of-a-snapped-device/m-p/1986459#M25002</link>
    <description>In MEP/ABS, is there a possible VB solution that would allow a wire to read and store the ID's of the two devices that the wire is snapped onto? The scenario would be, for example, two receptacles (electrical device type objects) with a wire snapped onto the electrical end connector of each receptacle. Is there an approach using VB that would allow the wire to read the ID of each receptacle and then store those two ID's in two properties within the extended data of the wire?&lt;BR /&gt;
&lt;BR /&gt;
For testing purposes, I went ahead and put together the attached drawing that contains two receptacles connected by a wire. The wire is snapped onto the receptacles using an MEP snap, and hence the program will keep the wire attached in the event that a receptacle is moved. I created a property set definition for the wire, and have attached the extended data. For the time being, the extended data just consists of two text properties as a placeholder for where I want the ID's of the receptacles to be stored. What I want to do is automatically populate those two properties with the ID of the devices that the ends of the wire are snapped onto. Preferably I would want the property to automatically clear and update in the event that a device is deleted or the wire is snapped onto another device. I've tried to figure out where exactly the program stores the data which keeps track of the fact that the wire is snapped onto a certain device, but I can't track down what I need. I'm hoping someone here can shed some light on the whole thing.</description>
    <pubDate>Tue, 05 Jun 2007 17:36:02 GMT</pubDate>
    <dc:creator>rdswords</dc:creator>
    <dc:date>2007-06-05T17:36:02Z</dc:date>
    <item>
      <title>Get the ID of a snapped device</title>
      <link>https://forums.autodesk.com/t5/vba-forum/get-the-id-of-a-snapped-device/m-p/1986459#M25002</link>
      <description>In MEP/ABS, is there a possible VB solution that would allow a wire to read and store the ID's of the two devices that the wire is snapped onto? The scenario would be, for example, two receptacles (electrical device type objects) with a wire snapped onto the electrical end connector of each receptacle. Is there an approach using VB that would allow the wire to read the ID of each receptacle and then store those two ID's in two properties within the extended data of the wire?&lt;BR /&gt;
&lt;BR /&gt;
For testing purposes, I went ahead and put together the attached drawing that contains two receptacles connected by a wire. The wire is snapped onto the receptacles using an MEP snap, and hence the program will keep the wire attached in the event that a receptacle is moved. I created a property set definition for the wire, and have attached the extended data. For the time being, the extended data just consists of two text properties as a placeholder for where I want the ID's of the receptacles to be stored. What I want to do is automatically populate those two properties with the ID of the devices that the ends of the wire are snapped onto. Preferably I would want the property to automatically clear and update in the event that a device is deleted or the wire is snapped onto another device. I've tried to figure out where exactly the program stores the data which keeps track of the fact that the wire is snapped onto a certain device, but I can't track down what I need. I'm hoping someone here can shed some light on the whole thing.</description>
      <pubDate>Tue, 05 Jun 2007 17:36:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/get-the-id-of-a-snapped-device/m-p/1986459#M25002</guid>
      <dc:creator>rdswords</dc:creator>
      <dc:date>2007-06-05T17:36:02Z</dc:date>
    </item>
    <item>
      <title>Re: Get the ID of a snapped device</title>
      <link>https://forums.autodesk.com/t5/vba-forum/get-the-id-of-a-snapped-device/m-p/1986460#M25003</link>
      <description>Hi&lt;BR /&gt;
I thought better yet instead of ID to&lt;BR /&gt;
use object Handle&lt;BR /&gt;
If I understand you correctly you wanted&lt;BR /&gt;
to add xdata to the wire object&lt;BR /&gt;
Here is an example&lt;BR /&gt;
Keep in mind that it was tested in A2007 only&lt;BR /&gt;
because I have not worked with AEC/ABS before&lt;BR /&gt;
In this case you can test in in AutoCAD drawing you&lt;BR /&gt;
uploaded here&lt;BR /&gt;
Hth&lt;BR /&gt;
&lt;BR /&gt;
~'J'~&lt;BR /&gt;
&lt;BR /&gt;
Option Explicit&lt;BR /&gt;
&lt;BR /&gt;
Sub WireXDataSet()&lt;BR /&gt;
     Dim oSset As AcadSelectionSet&lt;BR /&gt;
     Dim oEnt&lt;BR /&gt;
     Dim objWire As AcadObject&lt;BR /&gt;
&lt;BR /&gt;
     Dim fcode(1) As Integer&lt;BR /&gt;
     Dim fdata(1) As Variant&lt;BR /&gt;
     Dim dxfcode, dxfdata&lt;BR /&gt;
     Dim i As Integer&lt;BR /&gt;
     Dim setName As String&lt;BR /&gt;
&lt;BR /&gt;
     fcode(0) = 0&lt;BR /&gt;
     fdata(0) = "ACAD_PROXY_ENTITY"&lt;BR /&gt;
     fcode(1) = 8&lt;BR /&gt;
     fdata(1) = "E-Wire-Pwr,E-Recp-Pwr" ' layers for wire and devices&lt;BR /&gt;
     dxfcode = fcode&lt;BR /&gt;
     dxfdata = fdata&lt;BR /&gt;
     setName = "$WireSet$" ' dummy name&lt;BR /&gt;
&lt;BR /&gt;
     For i = 0 To ThisDrawing.SelectionSets.Count - 1&lt;BR /&gt;
          If ThisDrawing.SelectionSets.Item(i).Name = setName Then&lt;BR /&gt;
               ThisDrawing.SelectionSets.Item(i).Delete&lt;BR /&gt;
               Exit For&lt;BR /&gt;
          End If&lt;BR /&gt;
     Next i&lt;BR /&gt;
&lt;BR /&gt;
     Set oSset = ThisDrawing.SelectionSets.Add(setName)&lt;BR /&gt;
&lt;BR /&gt;
     MsgBox "To the first select wire" &amp;amp; vbCr &amp;amp; _&lt;BR /&gt;
            "Tnen select left device," &amp;amp; vbCr &amp;amp; _&lt;BR /&gt;
            "To the end select right device"&lt;BR /&gt;
&lt;BR /&gt;
     oSset.SelectOnScreen dxfcode, dxfdata&lt;BR /&gt;
&lt;BR /&gt;
     If oSset.Count &amp;lt;&amp;gt; 3 Then&lt;BR /&gt;
          MsgBox "Wrong quantity of objects selected"&lt;BR /&gt;
          Exit Sub&lt;BR /&gt;
     End If&lt;BR /&gt;
&lt;BR /&gt;
     Set oEnt = oSset.Item(0)&lt;BR /&gt;
     If oEnt.ObjectName = "AcDbZombieEntity" Then&lt;BR /&gt;
          MsgBox "Good boy"&lt;BR /&gt;
          Set objWire = oEnt&lt;BR /&gt;
     End If&lt;BR /&gt;
&lt;BR /&gt;
     Dim DataType(0 To 2) As Integer&lt;BR /&gt;
     Dim Data(0 To 2) As Variant&lt;BR /&gt;
     Dim appName As String&lt;BR /&gt;
     ' Return the xdata for the proxy object&lt;BR /&gt;
     Dim xdataOut As Variant&lt;BR /&gt;
     Dim xtypeOut As Variant&lt;BR /&gt;
&lt;BR /&gt;
     objWire.GetXData "", xtypeOut, xdataOut&lt;BR /&gt;
     If Not IsEmpty(xdataOut) Then&lt;BR /&gt;
          MsgBox "XData is already there:" &amp;amp; vbCr &amp;amp; _&lt;BR /&gt;
                 "AppName: " &amp;amp; xdataOut(0) &amp;amp; vbCr &amp;amp; _&lt;BR /&gt;
                 "Left device handle: " &amp;amp; xdataOut(1) &amp;amp; vbCr &amp;amp; _&lt;BR /&gt;
                 "Right device handle: " &amp;amp; xdataOut(2)&lt;BR /&gt;
          Exit Sub&lt;BR /&gt;
     Else&lt;BR /&gt;
          appName = "Electrical Devices Handles"     ' &amp;lt;-- change appname here&lt;BR /&gt;
          DataType(0) = 1001: Data(0) = "Electrical Devices Handles"&lt;BR /&gt;
          DataType(1) = 1000: Data(1) = oSset.Item(1).Handle     'left device handle&lt;BR /&gt;
          DataType(2) = 1000: Data(2) = oSset.Item(2).Handle     'right device handle&lt;BR /&gt;
          objWire.SetXData DataType, Data&lt;BR /&gt;
     End If&lt;BR /&gt;
     'check for embedded data&lt;BR /&gt;
     objWire.GetXData "", xtypeOut, xdataOut&lt;BR /&gt;
     If Not IsEmpty(xdataOut) Then&lt;BR /&gt;
          MsgBox "XData was added succesfully:" &amp;amp; vbCr &amp;amp; _&lt;BR /&gt;
                 "AppName: " &amp;amp; xdataOut(0) &amp;amp; vbCr &amp;amp; _&lt;BR /&gt;
                 "Left device handle: " &amp;amp; xdataOut(1) &amp;amp; vbCr &amp;amp; _&lt;BR /&gt;
                 "Right device handle: " &amp;amp; xdataOut(2)&lt;BR /&gt;
     End If&lt;BR /&gt;
&lt;BR /&gt;
End Sub</description>
      <pubDate>Tue, 05 Jun 2007 19:40:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/get-the-id-of-a-snapped-device/m-p/1986460#M25003</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-06-05T19:40:39Z</dc:date>
    </item>
    <item>
      <title>Re: Get the ID of a snapped device</title>
      <link>https://forums.autodesk.com/t5/vba-forum/get-the-id-of-a-snapped-device/m-p/1986461#M25004</link>
      <description>I ran it, but it didn't work at all for me. It wouldn't accept my selection of the wire or devices. That type of operation is not what I'm looking for anyways. I need something that will look at wire type objects in an MEP drawing,  then grab the ID's of the devices attached to each wire and and add those ID's to the extended data of each wire. This needs to be continuous and automatic. The whole point is so that each wire automatically knows what equipment it is connected to, and I'm doing this so that we can automatically generate wire schedules using schedule table styles in MEP, and have the tables populate themselves without any interaction from the user. I can already populate the fields pertaining to the wires (like number and size of conductors), but I am looking for a way to have wires pass on device ID's to a schedule table in the same way that they pass their own extended data to the table. Hence, if I can get a script to take the device ID's and store them as properties in the extended data of wires, then my problem is solved. This really is an MEP/ABS specific problem, and there isn't going to be any AutoCAD style approach that is going to work (since property sets, MEP snaps, etc. do not exist in AutoCAD).</description>
      <pubDate>Tue, 05 Jun 2007 20:07:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/get-the-id-of-a-snapped-device/m-p/1986461#M25004</guid>
      <dc:creator>rdswords</dc:creator>
      <dc:date>2007-06-05T20:07:05Z</dc:date>
    </item>
    <item>
      <title>Re: Get the ID of a snapped device</title>
      <link>https://forums.autodesk.com/t5/vba-forum/get-the-id-of-a-snapped-device/m-p/1986462#M25005</link>
      <description>Sorry I can't help you with MEP/ABS&lt;BR /&gt;
I have AutoCAD on machine only&lt;BR /&gt;
I think there is need request help&lt;BR /&gt;
from Jeff Mishler or somebody else&lt;BR /&gt;
who works with this stuff&lt;BR /&gt;
&lt;BR /&gt;
~'J'~</description>
      <pubDate>Tue, 05 Jun 2007 20:14:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/get-the-id-of-a-snapped-device/m-p/1986462#M25005</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-06-05T20:14:52Z</dc:date>
    </item>
    <item>
      <title>Re: Get the ID of a snapped device</title>
      <link>https://forums.autodesk.com/t5/vba-forum/get-the-id-of-a-snapped-device/m-p/1986463#M25006</link>
      <description>OK, I used the data extraction wizard to dump all of the drawing data to an Excel file, and within the Excel file I found something that may be exactly what I'm looking for. "Autodesk.Aec.Building.Elec.DataServices.ConnectedObjects" appears within the wire data, and I wanted to see if someone here knows if I might be able to utilize this using VBScript in a formula property (in the property set for wires). If I could just get formula property that would automatically grab and store that data then I would be all set to do what I need to.&lt;BR /&gt;
&lt;BR /&gt;
Edit: I found that wire objects contain a method called ConnectedObjects with a return type Autodesk.Aec.Building.Elec.DataServices.ConnectedObjects. I really need to get past this hurdle if anyone knows how I might access this data through VBScript.

Message was edited by: rdswords</description>
      <pubDate>Fri, 08 Jun 2007 13:03:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/get-the-id-of-a-snapped-device/m-p/1986463#M25006</guid>
      <dc:creator>rdswords</dc:creator>
      <dc:date>2007-06-08T13:03:50Z</dc:date>
    </item>
  </channel>
</rss>

