Language="VBSCRIPT" Sub CATMain() ' ********************************************* ' Simuliere Export aus einem anderen System ' Baue eine einfache Produktstruktur auf ' Titanic ' ASSEMBLY_A.1 ' Modell.1 ' Modell.2 ' Modell.1 ' Modell.2 ' ********************************************* Dim sDocPath As String 'Erstmal leer 'Create a new product document object by adding a document with the Product 'type to the document collection of the CATIA application. Dim oProductDoc As Document Set oProductDoc = CATIA.Documents.Add("Product") 'Retrieve the root product. Dim oRootProd As Product Set oRootProd = oProductDoc.Product 'Declare the root product's part number and name. oRootProd.PartNumber = "Titanic" oRootProd.Name = "Steam_Ship_Titanic" 'Retrieve the product's collection of root product Dim oRootProducts As Products Set oRootProducts = oRootProd.Products 'Add ASSEMBLY_A to the root product 'Add the Assembly as a new component in the collection with its part number 'and name. Dim oAss As Product Set oAss = oRootProducts.AddNewProduct("ASSEMBLY_A") 'oAss.PartNumber = "Ass_Number" 'oAss.Name = "Ass_Name" 'Retrieve the product's collection of the ASSEMBLY Dim oAssProducts As Products Set oAssProducts = oAss.Products ' Add Mod1 to the Assembly (Modell.1) Dim oMod1 As Product Set oMod1 = oAssProducts.AddNewProduct("Modell") 'Add Model to ASSEMBLY 'Set oMod1 = oRootProducts.AddNewProduct("Modell") 'Add Model to TopProduct 'oMod1.PartNumber = "Model1_PartNumber" 'oMod1.Name = "Model1_Name" 'Get the reference of the Mod1 Dim oModRef1 As Product Set oModRef1 = oMod1.ReferenceProduct 'Add a second Model (Mod2) using the existing product's reference. Dim oMod2 As Product Set oMod2 = oAssProducts.AddComponent(oModRef1) 'Set oMod2 = oRootProducts.AddComponent(oModRef1) 'oMod2.Name = "Model2_Name" ' Add oMod2A as Reference to the Top Product (Modell.1) Dim oMod2A As Product Set oMod2A = oRootProducts.AddComponent(oModRef1) ' Add oMod2B as Reference to the Top Product (Modell.1) Dim oMod2B As Product 'Set oMod2B= oAssProducts.AddComponent(oModRef1) Set oMod2B = oRootProducts.AddComponent(oModRef1) CATIA.ActiveWindow.ActiveViewer.Reframe ' ..... ' ' Do Something ... ' ..... ' ********************************************* ' Exportiere die CAD Produktstruktur in eine Datei ' ' processProduct oRootProd, 0 ' ********************************************* End Sub ' --------------------------------------------------- ' * processProduct -- ' --------------------------------------------------- sub processProduct ( oProduct as Product , iLevel as integer ) '/* ' * Export the product information to file ' */ exportProduct oProduct, iLevel ''/* ' * Process the children products ' */ dim oChildProduct as Product dim i as integer for i = 1 to oProduct.Products.Count Set oChildProduct = oProduct.Products.Item(i) processProduct oChildProduct, iLevel + 1 next End Sub ' --------------------------------------------------- ' exportProduct -- ' ' --------------------------------------------------- Sub exportProduct ( oProduct as Product , iLevel as integer ) Dim i as Integer Dim sLeerzeichen As String sLeerzeichen = "" Dim sTab as String sTab = " " For i = 0 to iLevel-1 sLeerzeichen = sLeerzeichen & sTab Next 'Info dbg2file iLevel & "|" & sLeerzeichen & oProduct.Name & "|PATH=" & oProduct.Parent.Name End Sub ' --------------------------------------------------- ' Write to Logfile ' ' --------------------------------------------------- Sub dbg2file (sLine As String) ' ------------------------------------------ ' Get the file system object Dim oFileSys As FileSystem Set oFileSys = CATIA.FileSystem Dim sExpsFile As String sExpsFile = "D:/TMP/DMU/VBA_DMU.log" Set oFileSys = CATIA.FileSystem If (oFileSys.FileExists(sExpsFile)) Then Set oFile = oFileSys.GetFile(sExpsFile) Else Set oFile = oFileSys.CreateFile(sExpsFile, False) End If Set oTextStream = oFile.OpenAsTextStream("ForAppending") oTextStream.Write sLine + Chr(10) oTextStream.Close End Sub