[VBA] Compart Local WorkAxes to Global WorkAxes

[VBA] Compart Local WorkAxes to Global WorkAxes

Anonymous
Not applicable
935 Views
2 Replies
Message 1 of 3

[VBA] Compart Local WorkAxes to Global WorkAxes

Anonymous
Not applicable

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

0 Likes
Accepted solutions (1)
936 Views
2 Replies
Replies (2)
Message 2 of 3

Vladimir.Ananyev
Alumni
Alumni

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

 

Positioning Assembly Occurrences

http://modthemachine.typepad.com/my_weblog/2009/04/positioning-assembly-occurrences.html

 


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 3

Anonymous
Not applicable
Accepted solution

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 ---------------------------------

0 Likes