从Catia treeview生成xml文件

时间:2015-07-20 09:23:23

标签: xml vbscript catia

我有一个产品组装的Catia设计。 零件很少,整个产品由这些零件组成。 我能够生成excel文件但不能保留树结构的层次结构。 如何使用vbscript或catscript将Catia产品树的树结构导出到XML文件?

2 个答案:

答案 0 :(得分:1)

将CATProduct保存为txt文件,这将为您提供树结构的层次结构。

对于我来说,层次结构类似于下面(并且通过直接从CATIA保存CATProduct而不进行任何自动化来获得)。

enter image description here

要获得更详细的答案,您可以看到下面的vbscript代码(您可以改进,将MsgBox写入另一个文件,或者增加级别数量)。希望现在回答几乎完成。

Const ForReading = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("c:\Temp\X-WING.txt", ForReading)  ''name of file and path saved from CATIA, this can be also automated.
strContents = objFile.ReadAll
objFile.Close
arrLines = Split(strContents, vbCRLF)

For Each strLine in arrLines
CharacterCount1 = Len(strLine) - Len(Replace(strLine, " ", ""))
CharacterCount = Len(strLine) - Len(Replace(strLine, "|-", "")) 

If CharacterCount > 0  And CharacterCount1 > 6 Then

        If CharacterCount1 = 7 Then 
        CharacterCount1 = "Level 1" 
          ElseIf CharacterCount1 = 13 Then 
        CharacterCount1 = "Level 2" 
         ElseIf CharacterCount1 = 19 Then 
        CharacterCount1 = "Level 3"
        ''You can add/improve the code for more levels
          End If 

MsgBox CharacterCount1 & strLine
End If 

Next

答案 1 :(得分:0)

see the image here附加了BOM的宏。 get Bill of material catia

创建一个宏文件并添加以下内容。相应地更改路径

*

Language="VBSCRIPT"
Sub CATMain()
Set productDocument1 = CATIA.ActiveDocument
Set product1 = productDocument1.Product
Set assemblyConvertor1 = product1.GetItem("ListingReport")
Dim array1
'assemblyConvertor1.SetCurrentFormat array1
assemblyConvertor1.Print "TXT", "C:\Users\Labuser\Desktop\testPW.txt", product1
End Sub

*