mrawlinc
Industrial
- Nov 19, 2012
- 36
Hi!
I would need a bit of explanation why my code skips parts with only one body (PartBody) so it's name is not listed in immediate?
I would need a bit of explanation why my code skips parts with only one body (PartBody) so it's name is not listed in immediate?
Code:
Sub CATMain()
Dim RootProduct As Product
Set RootProduct = CATIA.ActiveDocument.Product
'first check if document is part or product
If InStr(CATIA.ActiveDocument.name, ".CATProduct") < 1 Then
MsgBox RootProduct.name & " NI Assembly!"
Exit Sub
End If
' count of parts and instances
Dim PartsCount As Integer
PartsCount = RootProduct.Products.Count
Dim BodyCount As Integer
Dim oPart As Part
Dim curentBody As body
' loop trough parts
For i = 1 To PartsCount
Set oPart = RootProduct.Products.Item(i).ReferenceProduct.Parent.Part
Debug.Print oPart.name
BodyCount = oPart.Bodies.Count
' loop trough bodies
For k = 1 To BodyCount
Set curentBody = oPart.Bodies.Item(k)
Debug.Print curentBody.name
Next
Next
End Sub