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!

CATIA macro adds bodies (name_1) to new body (new_name_1)

Status
Not open for further replies.

Macro2015

Automotive
Jan 19, 2015
10
SI
Hi!

i would like to program a macro that will select:

-all Bodies named "name_1" and add them to new body with name "new group 1"
-all Bodies named "name_2" and add them to new body with name "new group 2"
-all Bodies named "name_3" and add them to new body with name "new group 3".


i successfully wrote this code on my CATIA R20, and works OK. It adds all bodies in new body. But then i tried to run a macro on CATIA R19 and R24, but it doesnt work! In R19/R24 it doesn't add all bodies named "name_1" but it adds only one body in new body! please anyone could tell me what could be the problem? see code below.. (only for one name_1)



I appreciate any response, thank you in advance

-----------------


Sub CATMain()

Dim partDocument1 As PartDocument
Set partDocument1 = CATIA.ActiveDocument
Set objSel = partDocument1.Selection
Dim part1 As Part
Set part1 = partDocument1.Part
Dim bodies1 As Bodies
Set bodies1 = part1.Bodies

Set shapeFactory1 = part1.ShapeFactory
Set bodies1 = part1.Bodies

Dim body1 As Body
Set body1 = bodies1.Item("PartBody")

Dim shapes1 As Shapes
Set shapes1 = body1.Shapes
objSel.Clear
'******************name_1*********************
objSel.Search ("Name=name_1,all")
objcount = objSel.Count


Set body1 = bodies1.Add()
body1.Name = "new_name_1"
Set body1 = bodies1.Item("new_name_1")
part1.InWorkObject = body1

For i = 1 To objcount
Set body11 = bodies1.Item("name_1")
Set add1 = shapeFactory1.AddNewAdd(body11)

Next
objSel.Clear

End Sub
 
Replies continue below

Recommended for you

Hallo,

In CATSCript, (only for name_1), hope you'll get the idea.

Code:
Language="VBSCRIPT"
Sub CATMain()

Dim partDocument1 As Document
Set partDocument1 = CATIA.ActiveDocument

Dim part1 As Part
Set part1 = partDocument1.Part

Dim bodies1 As Bodies
Set bodies1 = part1.Bodies

Dim body1 As Body

Set body1 = bodies1.Add()
body1.Name = "new_name_1"
Set body1 = bodies1.Item("new_name_1")
part1.InWorkObject = body1

part1.Update 

Dim selection1 As Selection
Set selection1 = partDocument1.Selection

selection1.Search "Name=*name_1'.'*,all"
n = selection1.Count

Dim shapeFactory1 As Factory
Set shapeFactory1 = part1.ShapeFactory

Dim i As Integer

For i = 2 To n+1
Dim body2 As Body
Set body2 = bodies1.Item(i)

Dim assemble1 As Assemble
Set assemble1 = shapeFactory1.AddNewAssemble(body2)
Next

part1.UpdateObject assemble1
Part1.Update 

End Sub

Regards
Fernando

 
Thank you Fernando for answer. I found out what was wrong. The problem is that this code was written in CATIA with enabled HYBRID design. When I was trying to run this macro in CATIA with disabled HYBRID design iz didn't work.

Now I have no idea how to write the previous code for CATIA wich is running in NON HYBRID DESIGN ENVIRONMENT.

any suggestions?

thank you in advance,
Jon
 
Hi,

This is one of the reasons why most companies are using such kind of options. I never tried to create a macro with other option.

Options.jpg


Regards
Fernando

- Romania
- EU
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top