Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

After Inserting a Part in a Product, How To Get the Instance Name

Status
Not open for further replies.

tpalsl125

Automotive
Apr 24, 2015
44
Hello, All

I found the below script to insert a Part in a Product.

Code:
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?
 
Replies continue below

Recommended for you

Can you do:
Code:
OPart = CATIA.ActiveDocument.Product.Products.AddComponentsFromFiles Path, "All" 
sInstanceName = oPart.Name

It may be .PartNumber, can't remember.
 
Hallo, Lardman.

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:
Path(0) = "C:\Users\Desktop\Part1.CATPart"
[COLOR=#EF2929]oPart = CATIA.ActiveDocument.Product.Products.AddComponentsFromFiles Path, "All"   <---  Here is a error line.
[/color]msgbox oPart.Name
 
Sorry I wasn't sure if it would work:(

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.
 
Hello,Lardman

Thank you so much. Now I can work. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor