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!

Creating some bodies and assemles with one click with names

Status
Not open for further replies.

Dialga1

Mechanical
Jan 1, 2023
15
I added example about what am I needed in picture. Is this possible to create parts and assembles like this with 1 macro? I tried my best but I got stuck.

Code:
Language="VBSCRIPT"

Sub CATMain()

Set documents1 = CATIA.Documents

Set partDocument1 = documents1.Item("Part1.CATPart")

Set part1 = partDocument1.Part

Set bodies1 = part1.Bodies

Set body1 = bodies1.Add()

part1.Update 

Set body2 = bodies1.Add()

part1.Update 

Set body3 = bodies1.Add()

part1.Update 

Set body4 = bodies1.Add()

part1.Update 

Set body5 = bodies1.Add()

part1.Update 

Set body6 = bodies1.Add()

part1.Update 

Set body7 = bodies1.Add()

part1.Update 

Set body8 = bodies1.Add()

part1.Update 

Set shapeFactory1 = part1.ShapeFactory

shapeFactory1.AddNewAssemble body2

Set shapes1 = body1.Shapes

Set assemble1 = shapes1.Item("KABUK.1")

part1.UpdateObject assemble1

Set assemble2 = shapes1.Item("Assemble.2")

part1.UpdateObject assemble2

Set assemble3 = shapes1.Item("Assemble.3")

part1.UpdateObject assemble3

Set assemble4 = shapes1.Item("Assemble.4")

part1.UpdateObject assemble4

Set assemble5 = shapes1.Item("Assemble.5")

part1.UpdateObject assemble5

Set assemble6 = shapes1.Item("Assemble.6")

part1.UpdateObject assemble6

part1.Update 

Set body9 = bodies1.Add()

part1.Update 

shapeFactory1.AddNewAssemble body9

part1.Update 

End Sub
 
 https://files.engineering.com/getfile.aspx?folder=eccbdf55-2b04-4031-a591-09009ec6caa4&file=Snipaste_2023-01-31_11-36-18.png
Replies continue below

Recommended for you

I,

I would select the bodies, with selectelement3, then make the add.
here some ideas to implement it. In case of doubts, please post your current code.


Code:
InputObjectType(0)="Body" 
 Status=Selection.SelectElement3(InputObjectType,"Select bodies", _
                                 true,CATMultiSelTriggWhenSelPerf,false)
 if (Status = "Cancel") then Exit Sub

After make a loop to cycle between all selected bodies.

Code:
for i=1 to selection.count
Set body1 = Selection.item(i).value
Dim add1 = shapeFactory1.AddNewAdd(body1)
add1.Name = body1.name
next

part1.update


Tiago Figueiredo
Tooling Engineer

Youtube channel:
 
Azzazil said:
is this possible in 3DExperience?
This is from a post from ENOVIA community
5bwne-title_o1_csparl.jpg


Regards
Fernando

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor