0

I have searched forever for a macro that would let me remove "." and "/" from Catia v5 Part Body names.

Has anyone ever seen a macro like this?

I have a part that reads into Catia with more than one Part Body in them with those symbols. I want to run this macro so i could then run a macro I already have that creates separate parts from each one of the part bodies and assembles them into a product. The macro that creates separate parts fails because the "." and "/" are not allowed in part names.

J.Zecha
  • 1
  • 5

1 Answers1

0

Your macro could be something like this that loops through all of the bodies in the part and renames them using the replace function successively:

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 " "
    myBody.Name = newName 'rename the current body with the revised name
Next

MsgBox "All Done!"
End Sub
GisMofx
  • 982
  • 9
  • 27
  • This is great, I appreciate the help. Could you help me convert this to CATScript or CATVBS? – J.Zecha Feb 04 '16 at 19:41
  • @J.Zecha How are you using this in a CATScript? Are you trying to run a batch? Alternatively, you can add some code to this script to loop through all the files in a folder and sub folders. Is that what you want? – GisMofx Feb 04 '16 at 23:23
  • I use it inside Catia V5 out of the Macro menu. This VBA code does everything I need it to. I have a bunch of other CATScripts that are in one directory and I would like to keep this Macro in that directory. But, the way Catia reads Macros, you have to change directories between VBA and Scripts. I hope that answers all the your questions. – J.Zecha Feb 05 '16 at 18:17