[VBA] Location of a part in an assembly file

[VBA] Location of a part in an assembly file

Anonymous
Not applicable
1,461 Views
2 Replies
Message 1 of 3

[VBA] Location of a part in an assembly file

Anonymous
Not applicable

Is it possible to identify the location of a part in an assembly file?

 

I cannot access (or find access to) global locations, just local.  You may ask, whats the problem?  Well, right now, I have 10 subAssemblies and they are all "located" at (0,0,0), which means I have 10 solids sharing the exact same space. This problem can be easily fixed if I can compare the Global Origin to a Local Origin, but I can only find the "work axes origin" which is worthless to me.

 

Any assistence/material would be appriciated.

 

Thank you,

-lemensk

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

Vladimir.Ananyev
Alumni
Alumni

Location and orientation of the component in the assembly coordinate system is controlled by component’s matrix object.

Could you please look at this thread

http://forums.autodesk.com/t5/Inventor-Customization/VBA-Compart-Local-WorkAxes-to-Global-WorkAxes/m...


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.  Surprised how hard it was to get such simple code:

 

'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