Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations cowski on being selected by the Eng-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
Joined
Nov 19, 2012
Messages
36
Location
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
 
Part's main body can be accessed with Part.MainBody property.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top