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
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)
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 SubRegards
Fernando
https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...
RE: CATIA macro adds bodies (name_1) to new body (new_name_1)
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
RE: CATIA macro adds bodies (name_1) to new body (new_name_1)
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.
Regards
Fernando
https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU