I am trying to extract part locations from an assembly file. I've been successful UNTIL I come to a part/subAssembly where the workAxes is orientated differently then the overall assembly axis. Is it possible to compare the local axis to the global axis? If the answer is 'yes', can sample code be posted (i.e. dim sameOrientation as bool; sameOrientation = ... )?
Also, once I know that "sameOrientation = false," how would one convert local coordinantes to global coordinates?
Thank you,
lemensk
Solved! Go to Solution.
Solved by lemensk. Go to Solution.
The component position and orientation relative to the assembly coordinate system is defined by the matrix object that is returned by the ComponentOccurrence.Transformation property.
Hope the following links could help you to move in the right direction.
Examing the Matrix and other Inventor Math and Geometry Objects
http://modthemachine.typepad.com/files/mathgeometry.pdf
Occurrences, Contexts, Definitions, Proxies
http://adndevblog.typepad.com/manufacturing/2013/07/occurrences-contexts-definitions-proxies.html
http://modthemachine.typepad.com/my_weblog/2009/04/positioning-assembly-occurrences.html
Below is the answer to my question, each part is considerded to have the same axis.
'CODE START ---------------------------------
Sub printParts()
Dim inventDoc As Inventor.AssemblyDocument
Dim deltaX, deltaY, deltaZ, avgX, avgY, avgZ, minX, minY, minZ, maxX, maxY, maxZ As Double
Dim fileName, strg As String
Dim partOccur As Inventor.ComponentOccurrence
Set inventDoc = ThisApplication.ActiveDocument
fileName = inventDoc.DisplayName
For Each partOccur In inventDoc.ComponentDefinition.Occurrences.AllLeafOccurrences 'For each part included in the assembly
strg = partOccur.Name & ";" & partOccur.RangeBox.minPoint.X & ";" & partOccur.RangeBox.minPoint.Y & _
";" & partOccur.RangeBox.minPoint.Z
Open "C:\Temp\" & fileName & ".txt" For Append As #1 'Open txt file and Append
Print #1, strg 'Print String
Close #1 'Close txt file
Next
End Sub
'CODE STOP ---------------------------------