×
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

(VBScript) Without the Selection, How to Add Bodies on the Product?

(VBScript) Without the Selection, How to Add Bodies on the Product?

(VBScript) Without the Selection, How to Add Bodies on the Product?

(OP)
Hello, Guys

I think this is very simple script, but I can't make it.

I made a script to add bodies on Product, not open the window a part.

Of course, I can make it with the selection.

But I don't know how to add bodies without the selection on the Product.

Could you check below my scripts?

The first script is with the Selection, the second script is without the selection.

CODE --> VBScript

Sub CATMain()

Set Selection1 = CATIA.ActiveDocument.Selection
Set Selection2 = Selection1.Item(1).Value

Set partDocument1 = CATIA.Documents.Item(Selection2.Name+".CATPart")

Set part1 = partDocument1.Part
Set bodies1 = part1.Bodies
Set body1 = bodies1.Add()
part1.Update 

End Sub 

CODE --> VBScript

Sub CATMain()

Set partDocument1 = CATIA.Documents.Item(1)
Set part1 = partDocument1.Part
Set bodies1 = part1.Bodies
Set body1 = bodies1.Add()
part1.Update 

End Sub 

RE: (VBScript) Without the Selection, How to Add Bodies on the Product?

(OP)
Hi Ferdo. I'm working in a Product not in a CATPart.

RE: (VBScript) Without the Selection, How to Add Bodies on the Product?

(OP)
Hi, Ferdo, Thank you for your reply.

Yes, I know what you mean..

But I thought the new way to do it..

RE: (VBScript) Without the Selection, How to Add Bodies on the Product?

If you are working in a product, how do you know documents.item(1) is a part in that product? Document 1 could be the product, and your macro will fail.

If the first item in the product is a part, you could set the part like this:
Set product1 =Catia.activedocument.product
set part1 = product1.products.item(1).parent.part
Item(1) is the instance level of the first part
.parent is the document of the first part
.part is the part

RE: (VBScript) Without the Selection, How to Add Bodies on the Product?

(OP)
Hi, lardman
Thank you for your reply.
I tried with your code.
But it doesn't work.
Can you check my code?

CODE --> VBScript

Set product1 = CATIA.Activedocument.product
Set part1 = product1.products.item(1).parent.Part
'Set partDocument1 = CATIA.Documents.Item(1)
'Set part1 = partDocument1.Part
Set bodies1 = part1.Bodies
Set body1 = bodies1.Add()
part1.Update 

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