- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I want to start by saying I am by no means a programmer but managed to copy and paste together some stuff.
At our company we need to make tables of the coordinates of Tie-In Points, where our customers can set up the required connections in advance. Right now they are measuring and inserting all the coordinates by hand into a table in our drawings, which is a ridiculous amount of dumb work in my opinion.
So, I want to automate it.
Currently, I have code working that pulls the coordinates (Center Point) from all occurences of which the iProperty "Title" = Tie-In Point. This would allow us to make a specific part that you copy, paste and constrain on the appropriate locations. It gives those coordinates in mm already (the x10 factor), as this is required. Note that I run this code in a drawing document, and it pulls the main model / assembly from the drawing as reference.
I feel like I'm missing two steps to achieve what I want:
1. I want to number the coordinate values. This would mean that the first Tie-In Point would have the variables xCoord1, yCoord1, zCoord1, then the second point gets xCoord2, yCoord2, etc. Is there a way to automate these variables for "xCoordn"? Because it is unknown at the start how many points would be needed.
These variables could all be written into a table using the table creation feature, which seems easy enough. But, since the amount of points is unknown as stated above, the table length would be unknown as well.
2. Is there a way to make it so that a table is filled in using "Row 1 = Headers; Row 2 = xCoordn, yCoordn, zCoordn; Row 3 = xCoordn+1, yCoordn+1, zCoordn+1, etc."?
I imagine this would be possible using the same sequence integer for both questions I have (i=1, and for every occurence i+1). This could determine the length of the table as well as name the variables.
My current code, which just pops up text boxes with the coordinates, is as follows:
I'm gonna try and get the code working for the table using some values and reply to this thread if it works
Public Sub Main()
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisDrawing.ModelDocument
Dim oAsmDef As AssemblyComponentDefinition
oAsmDef = oAsmDoc.ComponentDefinition
Dim oOccs As ComponentOccurrences = oAsmDoc.ComponentDefinition.Occurrences
Call TraverseAssembly(oAsmDef, oOccs)
End Sub
Function TraverseAssembly(oAsmDef As AssemblyComponentDefinition, oOccs As ComponentOccurrences)
Dim oWPProxy As WorkPointProxy
Dim oOcc As ComponentOccurrence
For Each oOcc In oOccs
Dim TitleCheck= oOcc.Definition.Document.PropertySets.Item("Inventor Summary Information").Item("Title").Value
If TitleCheck = "Tie-In Point" Then
Dim oWP As WorkPoint
For Each oWP In oOcc.Definition.WorkPoints
If Not oWP.Name.Contains("Center Point") Then Continue For
i=i+1
Call oOcc.CreateGeometryProxy(oWP, oWPProxy)
Dim xCoord, yCoord, zCoord As Double
xCoord = oWPProxy.Point.X * 10
yCoord = oWPProxy.Point.Y * 10
zCoord = oWPProxy.Point.Z * 10
oLine = "X: " & Round(xCoord, 3) & vbLf & "Y: " & Round(yCoord, 3) & vbLf & "Z: " & Round(zCoord, 3)
MsgBox(oLine, , oWP.Name)
Next
If oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
'step into subassembly
oSubOccs = oOcc.SubOccurrences
Call TraverseAssembly(oAsmDef, oSubOccs)
End If
End If
Next
End Function
Solved! Go to Solution.