将 CATpart 的产品树保存到 txt 文件中

Saving the product tree of a CATpart into a txt file

我需要从 CATIA 中提取 CATpart 的产品树。我想使用宏来执行此操作,并且我有适用于 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

但是当我想将其用于 CATpart 时,出现错误:ExportData 方法失败。这可能使用 vba 宏还是其他更简单的方法?

这是一个获取零件的主体和混合体名称的示例(仅限顶级条目)

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