×
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

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

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

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

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

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

Hallo,

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

CODE --> CATScript

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

https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...

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

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

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