×
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

[CatiaV5] Changing name of part in macro

[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

RE: [CatiaV5] Changing name of part in macro

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

https://picasaweb.google.com/102257836106335725208

RE: [CatiaV5] Changing name of part in macro

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

RE: [CatiaV5] Changing name of part in macro

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

RE: [CatiaV5] Changing name of part in macro

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

RE: [CatiaV5] Changing name of part in macro

Hi,

Quote (At the right of the photo what i want, and at the left what i get. )


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

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