Community
Inventor Forum
Welcome to Autodesk’s Inventor Forums. Share your knowledge, ask questions, and explore popular Inventor topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

VBa help needed

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
Anonymous
415 Views, 3 Replies

VBa help needed

Hi, I try to develop a vba code to get the coordonates of each part of an assembly and after export them to an excel file.

 

After several inspiration on some forums I build this : 

 

Public Sub Export_Layout_COG()

If MsgBox("Cette Macro va exporter les coordonnées du COG de chaque layout, continuer ?", vbYesNo) = vbYes Then
Dim RefDoc As Document
Set RefDoc = ThisApplication.ActiveDocument
Refdocdisplayname = RefDoc.DisplayName
teston = Right$(Refdocdisplayname, 3)
If teston <> "iam" Then GoTo 1 Else
For Each invDoc In RefDoc.AllReferencedDocuments
Dim objUOM As UnitsOfMeasure
Dim oCOM As Point
Set objUOM = RefDoc.UnitsOfMeasure
Set oCOM = invDoc.MassProperties.CenterOfMass
Dim cogx As String
Dim cogy As String
Dim cogz As String
cogx = objUOM.GetStringFromValue(oCOM.X, UnitsTypeEnum.kDefaultDisplayLengthUnits)
cogy = objUOM.GetStringFromValue(oCOM.Y, UnitsTypeEnum.kDefaultDisplayLengthUnits)
cogz = objUOM.GetStringFromValue(oCOM.Z, UnitsTypeEnum.kDefaultDisplayLengthUnits)
MsgBox invDoc.DisplayName + " Cog X = " + cogx
MsgBox invDoc.DisplayName + " Cog Y = " + cogy
MsgBox invDoc.DisplayName + " Cog Z = " + cogz
Next
0
MsgBox ("Les coordonnées des COG ont été exportées")
GoTo 2
1
MsgBox ("Le fichier courant n'est pas un assemblage")
2
End If
End Sub

 

The code return an error on the red line, I don't catch why, if somebody have an idea and could help me to fix it....

 

Thanks in advance.

3 REPLIES 3
Message 2 of 4
MegaJerk
in reply to: Anonymous

Try :   

Set oCOM = invDoc.ComponentDefinition.MassProperties.CenterOfMass

 instead. 

Hope that solves it!  

 



If my solution worked or helped you out, please don't forget to hit the kudos button 🙂
iLogicCode Injector: goo.gl/uTT1IB

GitHub
Message 3 of 4
Anonymous
in reply to: Anonymous

Unfortunately not....returns :  method 'center of mass' of object 'mass properties' failed...

Message 4 of 4
Anonymous
in reply to: Anonymous

I figure it out !!! There was a part that is not a solid part in the assembly I tested, i deleted the item and it works !! Youhou, thanks !

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report