0

I need to extract the product tree of the CATpart from CATIA. I want to do this using macro's and I have code that works for CATproducts:

Sub CATMain()
Dim productDocument1
Set productDocument1 = CATIA.ActiveDocument
'Input box to select txt or xls
Dim exportFormat
exportFormat = "txt" 
'Input box to enter name of file
Dim partName
partName = Inputbox ("Please enter the file name.")
'Input box to enter file location
Dim oLocation
oLocation = "C:\Users\xvreeswijk\Documents\Programs\Input\"
productDocument1.ExportData oLocation & partName & "." & _
exportFormat,"txt"
End Sub

But when I want to use this for a CATpart I get the error: The method of ExportData failed. Is this possible using vba macro's or is another way easier?

1 Answers1

0

Here a example to get the names of bodies and hybridbodies of a part (only top level entries)

Sub CATMain()

    Dim oPartDocument as PartDocument
    Dim sListofBodies as String
    Dim oBody as Body
    dim oHybridBody as Hybridbody

    Set oPartDocument = CATIA.ActiveDocument
    Set oPart = oPartDocument.Part
    
    for each oBody in oPart.Bodies
        if Not oBody.InBooleanOperation then
            sListofBodies = sListofBodies & oBody.Name & Chr(10)
        end if  
    next
    
    MsgBox sListofBodies

    sListofBodies = ""
    
    for each oHybridBody in oPart.HybridBodies
        sListofBodies = sListofBodies & oHybridBody.Name & Chr(10)  
    next

    MsgBox sListofBodies

End Sub
Shrotter
  • 350
  • 3
  • 9
  • I was trying to export the sListofBodies into a txt file using the ExportData but that doesn't work. Is there another way to export the data into a txt file? – XanderVreeswijk Mar 30 '22 at 11:45
  • There a several solutions: e.g. using _TextStream_ from the catia API, using _TextStream_ from the _FileSystemObject_ – Shrotter Mar 30 '22 at 12:09