Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

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

Status
Not open for further replies.

tpalsl125

Automotive
Apr 24, 2015
44
DE
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:
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:
Sub CATMain()

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

End Sub
 
Replies continue below

Recommended for you

Hi Ferdo. I'm working in a Product not in a CATPart.
 
Hi, Ferdo, Thank you for your reply.

Yes, I know what you mean..

But I thought the new way to do it..
 
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
 
Hi, lardman
Thank you for your reply.
I tried with your code.
But it doesn't work.
Can you check my code?
Code:
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top