×
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

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

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.

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

Can you do:

CODE --> VBA

OPart = CATIA.ActiveDocument.Product.Products.AddComponentsFromFiles Path, "All" 
sInstanceName = oPart.Name 

It may be .PartNumber, can't remember.

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

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

Path(0) = "C:\Users\Desktop\Part1.CATPart"
oPart = CATIA.ActiveDocument.Product.Products.AddComponentsFromFiles Path, "All"   <---  Here is a error line.
msgbox oPart.Name 

RE: After Inserting a Part in a Product, How To Get the Instance 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.

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

(OP)
Hello,Lardman

Thank you so much. Now I can work. :)

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