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!

Possible Macro or Catia Setting

Status
Not open for further replies.

jzecha

Aerospace
Jan 20, 2016
235
US
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.
 
Replies continue below

Recommended for you

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.
 
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.
 
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
 
Ill get something posted tomorrow, I have no experience creating macros so it will probably need a lot of help.
 
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 "_".
 
Can anybody help point me in the right direction?
 
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:
for each mybody in oPart.bodies
[indent]mybody.name = replace( mybody.name,".","_")
[/indent]
next



Eric N.
indocti discant et ament meminisse periti
 
With your help and other message boards I have come up with the following code:

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

 
That did it, thanks for the help.

Here is the updated code for anyone to use in the future:
Code:
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top