Continue to Site

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!

[CatiaV5] Changing name of part in macro

Status
Not open for further replies.

us01

New member
Oct 29, 2012
14
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

sanstitre3mz.jpg


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
 
Replies continue below

Recommended for you

my photo didn't appear, so i repost it
Thx

 
OK, look at bellow solution (in a CATScript)

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

 
Hello sir,

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
 
my code

Sub CATMain()

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

 
I tried to follow your steps,



Sub CATMain()

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
 
Hi,


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....

[highlight #FCE94F]Set oDoc = CATIA.ActiveDocument ' Get current document
Set oPart = oDoc.Part ' Get the part[/highlight]
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

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor