After Inserting a Part in a Product, How To Get the Instance Name
After Inserting a Part in a Product, How To Get the Instance Name
(OP)
Hello, All
I found the below script to insert a Part in a Product.
But I really don't know, how can I get the instance name of inserted Part1?
For example, there is a part in a product. Maybe the tree will be like this.
Product1
ㄴPart1 (Part1.1)
And if I use above the script, then it will be like this.
Product1
ㄴPart1 (Part1.1)
ㄴPart1 (Part1.2) ---> Here is what I want to get the instance name of inserted Part1, "Part1.2".
If I use this script, there is no Selection.
That is reason why I can't get the instance name.
Can anybody help or give me any tips?
I found the below script to insert a Part in a Product.
CODE --> VBA
Path(0) = "C:\Part1.CATPart" CATIA.ActiveDocument.Product.Products.AddComponentsFromFiles Path, "All"
But I really don't know, how can I get the instance name of inserted Part1?
For example, there is a part in a product. Maybe the tree will be like this.
Product1
ㄴPart1 (Part1.1)
And if I use above the script, then it will be like this.
Product1
ㄴPart1 (Part1.1)
ㄴPart1 (Part1.2) ---> Here is what I want to get the instance name of inserted Part1, "Part1.2".
If I use this script, there is no Selection.
That is reason why I can't get the instance name.
Can anybody help or give me any tips?





RE: After Inserting a Part in a Product, How To Get the Instance Name
CODE --> VBA
It may be .PartNumber, can't remember.
RE: After Inserting a Part in a Product, How To Get the Instance Name
Thanks for your reply.
I've jsut tried to do with your script.
But unfortunatly, I'm very very beginner about macroes and it doesn't work.
Could you check the below script?!
CODE --> vba
Path(0) = "C:\Users\Desktop\Part1.CATPart" oPart = CATIA.ActiveDocument.Product.Products.AddComponentsFromFiles Path, "All" <--- Here is a error line. msgbox oPart.NameRE: After Inserting a Part in a Product, How To Get the Instance Name
The new part should be the last part in the assembly, so you could try:
Path(0) = "C:\Users\Desktop\Part1.CATPart"
CATIA.ActiveDocument.Product.Products.AddComponentsFromFiles Path, "All"
Dim oPartInstance as Product
Set oPartInstance = CATIA.ActiveDocument.Product.Products.Item(CATIA.ActiveDocument.Product.Products.count)
msgbox oPartInstance.Name
You may need to save the product before an instance name is assigned.
RE: After Inserting a Part in a Product, How To Get the Instance Name
Thank you so much. Now I can work. :)