- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am trying to develop an add in that allows a user to select a User coordinate system (UCS) in any part or sub assembly within the active top level assembly and then do some really cool stuff. I am unsure how to get the occurrence from the selected UCS to create the geometry proxy so I can get the transformation within the context of the top level assembly. Can somebody share an example of how to go about doing this?
Below is the just of where I am currently at with the code. This does not work as I expected. The output for the proxy is the same as the UCS. The output for both is correct at the part level the UCS is in not the top level. Output as follows...
Proxy ?
X 71.2562842475752
Y -86.2648285528555
Z -12.7341406841421
UCS
X 71.2562842475752
Y -86.2648285528555
Z -12.7341406841421
It seems there should be a more direct way to get the occurrence than going through the iterations. This method will also be an issue in the case of more than one occurrence of the same component as there is a chance it will not select the correct occurrence.
Public Sub CCTExecutionCommand()
Dim Doc As Document = g_IApp.ActiveDocument
Dim ADoc As AssemblyDocument = TryCast(Doc, AssemblyDocument)
If ADoc Is Nothing Then Exit Sub
Dim SSet As SelectSet = Doc.SelectSet
Dim TMat As Matrix
For Each Sel As Object In SSet
Dim UCS As UserCoordinateSystem = TryCast(Sel, UserCoordinateSystem)
If UCS IsNot Nothing Then
Dim MyOC As ComponentOccurrence = Nothing
For Each O As ComponentOccurrence In ADoc.ComponentDefinition.Occurrences
Try
If O.Definition Is UCS.Parent Then
MyOC = O
Exit For
End If
Catch ex As Exception
End Try
Next
Dim GProx As Object = Nothing
If MyOC IsNot Nothing Then MyOC.CreateGeometryProxy(UCS, GProx)
Dim UCSProxy As UserCoordinateSystemProxy = TryCast(GProx, UserCoordinateSystemProxy)
If UCSProxy IsNot Nothing Then
TMat = UCSProxy.Transformation
Debug.Print("")
Debug.Print("Proxy ?")
Debug.Print("X " & TMat.Translation.X)
Debug.Print("Y " & TMat.Translation.Y)
Debug.Print("Z " & TMat.Translation.Z)
TMat = UCS.Transformation
Debug.Print("")
Debug.Print("UCS")
Debug.Print("X " & TMat.Translation.X)
Debug.Print("Y " & TMat.Translation.Y)
Debug.Print("Z " & TMat.Translation.Z)
Exit For
End If
End If
Next
End Sub
Please advise!!!
Solved! Go to Solution.