Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

.AddNewComponent - naming fail

Status
Not open for further replies.

iscariot

Mechanical
Oct 15, 2009
154
DE
I don't understand why I cannot add products and rename them using below code:

Code:
Sub CATMain()
	Dim TopNodeDoc As Document
	Set TopNodeDoc = CATIA.ActiveDocument

	Dim TopNode As Product
	Set TopNode = TopNodeDoc.Product

	Dim newNode As Product
	Set newNode = TopNode.Products.AddNewComponent("Product","")

	newNode.Name = "test1"
	newNode.PartNumber = "test2"
End Sub

It works once, I delete the new created product and after that it does not work anymore.


Using below code it works but it is not what I need.
Code:
Set newNode = TopNode.Products.AddNewProduct("Product")

I need this type of product:
Capture_saxk81.jpg


instead of this one:
Capture1_m0thpr.jpg


What am I doing wrong? :)
 
Replies continue below

Recommended for you

Try this. This is working with me.

Code:
Sub CATMain()
CATIA.StartCommand ("Clear History")
Dim selection1
Set selection1 = CATIA.ActiveDocument.Selection

Dim product1 As Product


Dim products1 As Products


Dim Status As String

Dim Filter1(0)
        Filter1(0) = "Product"

        selection1.Clear

        Status = selection1.SelectElement2(Filter1, "Select a product to insert the new product", True)
   
        If selection1.Count = 0 Then
            Exit Sub
        End If
        
Set product1 = selection1.Item(1).Value

Set products1 = product1.Products

Dim PN As String

PN = InputBox("Insert the Part Number of product")

Dim product2 As Product
Set product2 = products1.AddNewComponent("Product", "")

product2.PartNumber = PN
product2.Name = PN

End Sub

Tiago Figueiredo
Tooling Engineer

Youtube channel:
 
Thanks.
This solved the issue:
Code:
CATIA.StartCommand ("Clear History")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top