×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

.AddNewComponent - naming fail

.AddNewComponent - naming fail

.AddNewComponent - naming fail

(OP)
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:


instead of this one:


What am I doing wrong? :)

RE: .AddNewComponent - naming fail

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:
https://www.youtube.com/channel/UC1qdlBeJJEgMgpPLV...

RE: .AddNewComponent - naming fail

(OP)
Thanks.
This solved the issue:

CODE -->

CATIA.StartCommand ("Clear History") 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources