Trying to build a VBA code in inventor 2010...help needed

Trying to build a VBA code in inventor 2010...help needed

Anonymous
Not applicable
953 Views
1 Reply
Message 1 of 2

Trying to build a VBA code in inventor 2010...help needed

Anonymous
Not applicable

Hello guys,

 

I'm trying to build a VBA code in inventor 2010 to export the Center of gravity coordinates (X,Y,Z) from an inventor assembly to an excel sheet.

 

But I'm not able to get the iproperties for the COG from my assembly.

 

Is there somebody can help me ?

 

Thanks

0 Likes
Accepted solutions (1)
954 Views
1 Reply
Reply (1)
Message 2 of 2

wayne.brill
Collaborator
Collaborator
Accepted solution

Hello,

 

You could get the COG from the assembly document. Here is a VBA example I tried. It prints the same values I see in the iProperties dialog to the VBA Immediate window.

 

Public Sub GetCOG()
   Dim oDoc As Inventor.Document
   Set oDoc = ThisApplication.ActiveDocument
 
   Dim UoM As UnitsOfMeasure
   Set UoM = oDoc.UnitsOfMeasure
  
   Dim oCenOfMassX As Double
   oCenOfMassX = oDoc.ComponentDefinition.MassProperties.CenterOfMass.X
   oCenOfMassY = oDoc.ComponentDefinition.MassProperties.CenterOfMass.Y
   oCenOfMassZ = oDoc.ComponentDefinition.MassProperties.CenterOfMass.Z
 
   Debug.Print UoM.ConvertUnits(oCenOfMassX, kDatabaseLengthUnits, kDefaultDisplayLengthUnits)
   Debug.Print UoM.ConvertUnits(oCenOfMassY, kDatabaseLengthUnits, kDefaultDisplayLengthUnits)
   Debug.Print UoM.ConvertUnits(oCenOfMassZ, kDatabaseLengthUnits, kDefaultDisplayLengthUnits)
 
End Sub

 

Wayne Brill

Autodesk Developer Network



Wayne Brill
Developer Technical Services
Autodesk Developer Network

0 Likes