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.
Solved! Go to Solution.
Solved by MegaJerk. Go to Solution.
Try :
Set oCOM = invDoc.ComponentDefinition.MassProperties.CenterOfMass
instead.
Hope that solves it!
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.