[CatiaV5] Changing name of part in macro
[CatiaV5] Changing name of part in macro
(OP)
Hello,
i'm "David" from France, here to approuve my Catia level(And English too). Actually i'm working in a space company.
I want to built a macro, to creat a "part" with 4 "corps", each one is named differently.
My problem : i creat a macro, i rename my 4 "corps". but when i run the macro, the 4 "corps" aren't renamed

At the right of the photo what i want, and at the left what i get.
I searched on the forum but i found nothing ... sorry if i recreated a subject already discussed
THX
i'm "David" from France, here to approuve my Catia level(And English too). Actually i'm working in a space company.
I want to built a macro, to creat a "part" with 4 "corps", each one is named differently.
My problem : i creat a macro, i rename my 4 "corps". but when i run the macro, the 4 "corps" aren't renamed

At the right of the photo what i want, and at the left what i get.
I searched on the forum but i found nothing ... sorry if i recreated a subject already discussed
THX





RE: [CatiaV5] Changing name of part in macro
Thx
[url=http://www.hostingpics.net/viewer.php?id=154110San...]
RE: [CatiaV5] Changing name of part in macro
The picture is good to have an idea, it will be also good to have your code to see it, maybe it will be easier to fix.
Regards
Fernando
https://picasaweb.google.com/102257836106335725208
RE: [CatiaV5] Changing name of part in macro
Language="VBSCRIPT"
Sub CATMain()
Dim partDocument1 As Document
Set partDocument1 = CATIA.ActiveDocument
Dim selection1 As Selection
Set selection1 = partDocument1.Selection
selection1.Search "CATPrtSearch.BodyFeature,all"
oCount = selection1.Count2
For i = 1 To oCount
selection1.Item2(i).Value.Name = "Corps de piece." & i
Next
Set oDoc =CATIA.ActiveDocument ' Get current document
Set oPart = oDoc.Part ' Get the part
Set oPartBody = oPart.MainBody ' Grab the mainbody
oPartBody.Name = "Corps principal" ' Rename Body
End Sub
Regards
Fernando
https://picasaweb.google.com/102257836106335725208
RE: [CatiaV5] Changing name of part in macro
First of All, i'would like to thank you for your response.
I actually want to do what you see on the right of the arrow
- IPN-Po-XY-XY-XY
+IPN-PO-XXXX
+NIN-ø-XXXX
+FICTIONDIEN
+GURAGE
BUT WHEN I have done the macro, i get "corps principal" (it's in French, but it means "principal body" etc
Thx
RE: [CatiaV5] Changing name of part in macro
Dim documents1 As Documents
Set documents1 = CATIA.Documents
Dim partDocument1 As PartDocument
Set partDocument1 = documents1.Add("Part")
Dim part1 As Part
Set part1 = partDocument1.Part
Dim bodies1 As Bodies
Set bodies1 = part1.Bodies
Dim body1 As Body
Set body1 = bodies1.Add()
part1.Update
Dim body2 As Body
Set body2 = bodies1.Add()
part1.Update
Dim body3 As Body
Set body3 = bodies1.Add()
part1.Update
End Sub
RE: [CatiaV5] Changing name of part in macro
Dim partDocument1 As PartDocument
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()
part1.Update
Dim body2 As Body
Set body2 = bodies1.Add()
part1.Update
Dim body3 As Body
Set body3 = bodies1.Add()
part1.Update
Set oDoc = CATIA.ActiveDocument ' Get current document
Set oPart = oDoc.Part ' Get the part
Set oPartBody = oPart.MainBody ' Grab the mainbody
oPartBody.Name = "IPN-PO-XXXX-XX" ' Rename Body
Set oDoc = CATIA.ActiveDocument ' Get current document
Set oPart = oDoc.Part ' Get the part
Set oPartBody = oPart.MainBody ' Grab the mainbody
oPartBody.Name = "NIN-ø-XXXX" ' Rename Body
Set oDoc = CATIA.ActiveDocument ' Get current document
Set oPart = oDoc.Part ' Get the part
Set oPartBody = oPart.MainBody ' Grab the mainbody
oPartBody.Name = "FICTATION ' Rename Body"
Set oDoc = CATIA.ActiveDocument ' Get current document
Set oPart = oDoc.Part ' Get the part
Set oPartBody = oPart.MainBody ' Grab the mainbody
oPartBody.Name = "GURAGE" ' Rename Body
End Sub
but it didn't work
RE: [CatiaV5] Changing name of part in macro
So, in my macro you get what you want (at least in first post you were describing that you want what is on the right side of the arrow, this is what I understood) but now I see you want in fact something else.
In my code, Grab the mainbody means get the PartBody which is MainBody in Part (or "corps principal" - by the way, I can talk french, not so well because I didn't do it for a long time).
There is only one mainbody so you have to rename it only once. In same way you can rename the others bodies (body1, body2...). Let first group as it is
Set oDoc = CATIA.ActiveDocument ' Get current document
Set oPart = oDoc.Part ' Get the part
Set oPartBody = oPart.MainBody ' Grab the mainbody
oPartBody.Name = "IPN-PO-XXXX-XX" ' Rename Body
What is on yellow color, you don't need, is already stated, you need to change it for body1, body2....
Set oDoc = CATIA.ActiveDocument ' Get current document
Set oPart = oDoc.Part ' Get the part
Set oPartBody = oPart.MainBody ' Grab the body1 not MainBody and change also the name of oPartBody
oPartBody.Name = "NIN-ø-XXXX" ' Rename Body
I will let you to modify everything....
Regards
Fernando
https://picasaweb.google.com/102257836106335725208