×
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

Possible Macro or Catia Setting

Possible Macro or Catia Setting

Possible Macro or Catia Setting

(OP)
This is to address multiple issues I am running into.
If anyone can answer either part of them it would be appreciated.

1.When I open a step file sent to me from another 3D modeling program, it comes in as a single part with multiple bodies.
I know in Creo, I can choose to import the step file as parts or assemblie, is there a way to do this in Catia V5?

2.If this in not possible in Catia, is there a Macro that can rename the part bodies or at least remove symbols that are not allowed in part names, like "/" and "."?
I already have a macro that will split out each part body into parts and create a product out of it, but it fails when there are "/" or "." in the part body names.

RE: Possible Macro or Catia Setting

(OP)
No such luck, still brings in the step file as a part with hundreds of bodies.
When i pull it into Creo 3.0 and select assembly, it brings it in as an assembly.

RE: Possible Macro or Catia Setting

(OP)
That is where i was at with this, I have a macro to replace the symbols in part and product names, but I am unable to find a macro to replace them in part body names.
If anyone could give me a start as to how to write it, that would be appreciated.

RE: Possible Macro or Catia Setting

you have a script that modify part name, that's a good start to also modify solids in parts...

post your code in progress, I'll help.

Eric N.
indocti discant et ament meminisse periti

RE: Possible Macro or Catia Setting

(OP)
Ill get something posted tomorrow, I have no experience creating macros so it will probably need a lot of help.

RE: Possible Macro or Catia Setting

(OP)
So this is my first attempt at this Macro, its just the beginning, but I think with some help in the right direction me and a fellow coworker can get this fixed.
Currently I am just trying to replace a "." with a "_" in the first body. Once I figure this out, Ill try and get it to continue this on the other bodies in that part.


CODE -->

Sub CatMain()

Set oDoc =CATIA.ActiveDocument ' Get current document
Set oPart = oDoc.Part ' Get the part
Set oPartBody = oPart.MainBody ' Grab the mainbody

Set oPartBody1 = oPartBody1.Products
For i = 1 To oPartBody1.Count

ElementName = oPartBody1.Item(i).ReferenceProduct.Parent.Name ' Extract reference name
ElementNumber = oPartBody1.Item(i).PartNumber ' Extract reference number
ElementNumberReplaced = Replace(ElementNumber, ".", "_")

End Sub 

I ran this on a single part body part and it gave me the error message that it failed at "End Sub" and it did not replace the "." with a "_".

RE: Possible Macro or Catia Setting

(OP)
Can anybody help point me in the right direction?

RE: Possible Macro or Catia Setting

sorry about that, was away.

in your catia installation you'll find a catiav5automation.chm file (or something very similar but still .chm) check the structure of the part object. You should find a Bodies collection in the part object

if you do something like

CODE --> vba

for each mybody in oPart.bodies
mybody.name = replace( mybody.name,".","_")
next

Eric N.
indocti discant et ament meminisse periti

RE: Possible Macro or Catia Setting

(OP)
With your help and other message boards I have come up with the following code:

CODE --> VBA

Sub FixPartBodyNames()

Dim myPart As Part
Set myPart = CATIA.ActiveDocument.Part

Dim myBody As Body

Dim newName As String
Dim newCharacter As String
newCharacter = " "

For Each myBody In myPart.Bodies 'loop through all the bodies in the part
    newName = myBody.Name 'get the current body's name
    newName = Replace(newName, ".", newCharacter) 'replace all "." with "_"
    newName = Replace(newName, "/", newCharacter) 'replace all "/" with "_"
    newName = Replace(newName, "\", newCharacter) 'replace all "/" with "_"
    newName = Replace(newName, " ", newCharacter) 'replace all "/" with "_"
    newName = Replace(newName, "*", newCharacter) 'replace all "/" with "_"
    newName = Replace(newName, " ", newCharacter) 'replace all "/" with ""
    myBody.Name = newName 'rename the current body with the revised name
Next

MsgBox "All Done!"
End Sub 

This does exactly what I want it to do, except I would like it in CATScript.
I am very new to coding and am struggling to figure out how to rework this to run in CATScript.

RE: Possible Macro or Catia Setting

(OP)
That did it, thanks for the help.

Here is the updated code for anyone to use in the future:

CODE --> CATScript

Sub CATMain()

Dim myPart As Part
Set myPart = CATIA.ActiveDocument.Part

Dim myBody As Body

Dim newName As String
Dim newCharacter As String
newCharacter = " "

For Each myBody In myPart.Bodies 'loop through all the bodies in the part
    newName = myBody.Name 'get the current body's name
    newName = Replace(newName, ".", newCharacter) 'replace all "." with "_"
    newName = Replace(newName, "/", newCharacter) 'replace all "/" with "_"
    newName = Replace(newName, "\", newCharacter) 'replace all "/" with "_"
    newName = Replace(newName, "*", newCharacter) 'replace all "/" with "_"
    myBody.Name = newName 'rename the current body with the revised name
Next

MsgBox "All Done!"
End Sub 

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