Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro to list bodies from multiple parts

Status
Not open for further replies.

mrawlinc

Industrial
Nov 19, 2012
36
0
0
SI
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?

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
 
Replies continue below

Recommended for you

Status
Not open for further replies.
Back
Top