I have a Catia design of a product assembly. It has few parts and the whole product is comprised of these parts. I am able to generate the excel file but can't retain the hierarchy of the tree structure. How to export the tree structure of the Catia product tree to a XML file using either vbscript or catscript?
Asked
Active
Viewed 2,936 times
2 Answers
1
Save the CATProduct as txt file, this will give you the hierarchy of the tree structure.
For me hierarchy is something like below (and is obtained by saving the CATProduct directly from CATIA without any automation).
To have a more detailed answer, you can see the vbscript code bellow (you can improve, write the MsgBox to another file, or increase the number of levels for example). Hope now answer is almost complete.
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

ferdo
- 178
- 4
-
The hierarchy information is not obtained while saving it as a text file.Rather should be saved as a Listing Report or BOM file.Thanks anyway for your reply. – nilakantha singh deo Mar 31 '16 at 11:48
-
Am I wrong in my assumption? Please see the improved response. – ferdo Mar 31 '16 at 18:57
-
Nope ,your are perfectly right .Only that the tab spaces give you perception of the hierarchical information.To recreate a tree you need to parse it further.In the other approach below it quantifies the hierarchical info by putting numbers in front of each line. – nilakantha singh deo Apr 04 '16 at 13:10
0
see the image herethe macro to get the BOM is attached. get Bill of material catia
create a macro file and add the following.Change the path accordingly
*
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
*

nilakantha singh deo
- 966
- 15
- 29
-
the text file thus generated has hierarchical info and can be parsed as xml. – nilakantha singh deo Mar 31 '16 at 11:49