' *****************************************************************************
' Purpose: Create A Product Structure document containing
' an external component.
' Assumtions: Opens CAAPstHull.CATPart in the CATDocView
' Author:
' Languages: VBScript
' Locales: English
' CATIA Level: V5R6
' *****************************************************************************
Sub CATMain()
' -----------------------------------------------------------------------------------------------
' Optional: allows to find the sample wherever it's installed
Dim sDocPath As String
sDocPath = CATIA.SystemService.Environ("CATDocView")
If (Not CATIA.FileSystem.FolderExists(sDocPath)) Then
Err.Raise 9999, , "No Doc Path Defined"
End If
' ------------------------------------------------------------------------------------------------
'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("roduct")
'Retrieve the root product.
Dim oRoot As Product
Set oRoot = oProductDoc.Product
'Retrieve the root product collection of products.
Dim oRootCol As Products
Set oRootCol = oRoot.Products
'Open the Part Document
Dim oPartDoc As Document
Set oPartDoc = CATIA.Documents.Read("D:\图\1\1\Jin41200.CATProduct")
'Add a new component from the already opened part document.
Dim oNewComponent As Product
Set oNewComponent = oRootCol.AddExternalComponent(oPartDoc)
Dim rProduct As Product
Set rProduct = oNewComponent.Products.Item(1).ReferenceProduct
Dim MyProduct As Product
Set MyProduct = oRootCol.AddNewComponent("roduct", "111")
'-----------------------下面两段改名字没反应,改不动,我试过树型里第一层以下的名称都改不动---------------------------------
Dim MyNewProduct As Product
Set MyNewProduct = oNewComponent.Products.AddComponent(rProduct)
MyNewProduct.Name = "444"
Set MyNewProduct = MyProduct.Products.AddNewProduct("222")
MyNewProduct.Name = "333"