Rename CATIA V5 Product and Parts
Rename CATIA V5 Product and Parts
(OP)
Hi to everyone.
I've a problem, i need to rename an assembly (and all sub-assembly and parts) changing only a the first part of the name.
EX :
all my files start with a code of 7 numbers, i need to change only this 7 numbers in all files
1234567_aaa.catproduct
1234567_bbb_catpart
1234567_ccc_catproduct
1234567_ddd_catpart
must become
7654321_aaa.catproduct
7654321_bbb_catpart
7654321_ccc_catproduct
7654321_ddd_catpart
There's a way (macro ??) to speed up the saving of these files ?
Thank you !
I've a problem, i need to rename an assembly (and all sub-assembly and parts) changing only a the first part of the name.
EX :
all my files start with a code of 7 numbers, i need to change only this 7 numbers in all files
1234567_aaa.catproduct
1234567_bbb_catpart
1234567_ccc_catproduct
1234567_ddd_catpart
must become
7654321_aaa.catproduct
7654321_bbb_catpart
7654321_ccc_catproduct
7654321_ddd_catpart
There's a way (macro ??) to speed up the saving of these files ?
Thank you !





RE: Rename CATIA V5 Product and Parts
indocti discant et ament meminisse periti
RE: Rename CATIA V5 Product and Parts
Also, the save management feature in CATIA allows you to apply a pattern to file names.
Drew Mumaw
www.textsketcher.com
www.drewmumaw.com
RE: Rename CATIA V5 Product and Parts
You would still need to manually edit the part and product properties inside Catia though.
I use DOS to do somethings in milliseconds that Windows can't do at all.
It's class.
Here's the procedure, but be careful. If you don't know what you're doing you can wipe out your PC in a nanosecond.
Go to the START menu
Select Run
Type in command
A black DOS window should appear.
You then type in the following command, but obviously editing it to suit where you have stored the files.
My example will have the files located a few folders deep from the root of the hard drive C
I purposely use only maximum 8 character folder names since DOS only allowed 8 characters.
(There is a way to use long names but it involves more complicated filename typing using squiggles etc).
REN C:\TESTFOLD\MYFILES\1234567*.* 7654321*.*
That will do them all in one hit.
Just note there is a space between 1234567*.* and 7654321*.*
Just type EXIT when you want to leave the DOS window
You can also freely use the ? wildcard to represent a single character, as opposed to the * which represents any group of characters.
I'm amazed Windows has no features like this, or if it has, I have never heard of them.
P.S. If in doubt at all what you're doing, practice on a trash PC that you don't mind eliminating
RE: Rename CATIA V5 Product and Parts
indocti discant et ament meminisse periti
RE: Rename CATIA V5 Product and Parts
I tried to make a macro, but i'm not very good with these kind of programming.
Could someone help me ?
@MRSSPOCK @itsmyjob
I have many link between files, i must do the process IN catia, I need to mantain those links
Thanks to everyone !
RE: Rename CATIA V5 Product and Parts
Can the script be in VBA or CATScript?
If you can use VBA (alt+f11 to open the VBA editor) you can probably use something like the following. I did not test it, so I would try it on a test structure. There may be other properties you want to rename...this is just an idea based on what little I know about the issue. It doesn't account for all the error states of a part number.
CODE --> VBA
Sub CATMain() Dim oDocument as Document Set oDocument = Catia.activedocument Dim oRootProduct as product Dim oProduct as product Dim oSelection as Selection Set oSelection = oDocument.selection Dim oSelectionLB Set oSelectionLB = oSelection Dim sOldNumber as String Dim sNewNumber as String Dim aSelectionFilter(0) = "Product" If TypeName (oDocument) = "Product" then set oRootProduct = oDocument.Product oSelection.Clear sMessage = "Select a part to renumber" MsgBox sMessage oSelectionLB.SelectElement2 aSelectionFilter, sMessage, True If oSelection.Count = 0 then Msgbox "Macro Canceled by user" exit sub Else sOldNumber = oSelection.Item(1).Value.Nomenclature oSelection.Clear sNewNumber = "A" i=0 Do until Len(sNewNumber) = 7 and IsNumeric(sNewNumber) = True and Val(sNewNumber) = Int(sNewNumber) sNewNumber = InputBox("Type new 7 digit number) i=i+1 If i = 5 then Msgbox "You can only enter a 7 digit number, exit macro" end sub end if Loop For i=1 to oRootProduct.products.Count Set oProduct = oRootProduct.Products.Item(i) If oProduct.PartNumber = sOldNumber then oProduct.Nomenclature = replace(oProduct.Nomenclature, sOldNumber, sNewNumber) oProduct.PartNumber = replace(oProduct.PartNumber, sOldNumber, sNewNumber) oProduct.Name = replace(oProduct.name, sOldNumber, sNewNumber) end if Next End if Else MsgBox "Product not loaded, exit macro" end sub End if End SubRE: Rename CATIA V5 Product and Parts
Hi,
Yes, i can use the VBA
All inside the product there are many parts and products, it's a very big assembly so i need a macro that rename all the files in my assembly
1234567_aaa.catproduct
This is an example where all "1234567" must renamed in "7654321" without changing the 3 letters after the names
Thanks
RE: Rename CATIA V5 Product and Parts
CODE --> VBA
Sub CATMain() Dim oDocument as Document Set oDocument = Catia.activedocument Dim oRootProduct as product Dim oProduct as product Dim oSelection as Selection Set oSelection = oDocument.selection Dim sOldNumber as String Dim sNewNumber as String If TypeName (oDocument) = "Product" then oSelection.Clear set oRootProduct = oDocument.Product sOldNumber = Left(oRootProduct.Nomenclature,7) sNewNumber = "A" i=0 Do until Len(sNewNumber) = 7 and IsNumeric(sNewNumber) = True and Val(sNewNumber) = Int(sNewNumber) sNewNumber = InputBox("Type new 7 digit number) i=i+1 If i = 5 then Msgbox "You can only enter a 7 digit number, exit macro" exit sub end if Loop oSelection.Clear oSelection.Search ("type=Product,all") For i=1 to oSelection.Count Set oProduct = oSelection.Item(i).Value If instr(oProduct.PartNumber, sOldNumber) <> 0 then oProduct.Nomenclature = replace(oProduct.Nomenclature, sOldNumber, sNewNumber) oProduct.PartNumber = replace(oProduct.PartNumber, sOldNumber, sNewNumber) oProduct.Name = replace(oProduct.name, sOldNumber, sNewNumber) end if Next oSelection.Clear MsgBox "Macro Complete" Else MsgBox "Product not loaded, exit macro" exit sub End if End SubRE: Rename CATIA V5 Product and Parts
I run your script on CATIA in the "first" product, but it doesn't work
I see only the message "product not loaded, exit macro" .. Why ?
it seems that does not recognize the product ..
thank you so much
RE: Rename CATIA V5 Product and Parts
If TypeName (oDocument) = "ProductDocument" then
RE: Rename CATIA V5 Product and Parts
Now the problem is in the line
"Do until Len(sNewNumber) = 7 and IsNumeric(sNewNumber) = True and Val(sNewNumber) = Int(sNewNumber)"
RE: Rename CATIA V5 Product and Parts
Since it is looking for a number, maybe use
CODE --> vba
RE: Rename CATIA V5 Product and Parts
The error is "type Mismatch"
and is in the line "Do until Len(sNewNumber) = 7 and IsNumeric(sNewNumber) = True and Val(sNewNumber) = Int(sNewNumber)"
I try to change the value of sNewNumber from "A" to "1", but it doestn't work
Thank You
RE: Rename CATIA V5 Product and Parts
CODE --> vba
RE: Rename CATIA V5 Product and Parts
Now the macro run, but it doesn't rename, right ?
RE: Rename CATIA V5 Product and Parts
http://www.eng-tips.com/viewthread.cfm?qid=340850
RE: Rename CATIA V5 Product and Parts
Use below macro in CATVba....
for using this macro, follow below steps
1) first create new assembly from old assembly by using File->new from
2) run this macro...
3) In first input box , "enter string to be replaced" ..... as in your case it is "1234567"
4) In second input box, "enter replaced string".............. as in your case it is "7654321"
5) Use file save management to save all child parts and assembly at new location
Sub CATMain()
Dim root As Document
Set root = CATIA.ActiveDocument
Dim docs As Documents
Set docs = CATIA.Documents
If (root.Path <> "") Then
MsgBox "Please Use This macro on Unsaved Product"
Exit Sub
End If
If (TypeName(root) <> "ProductDocument") Then
MsgBox "Please open Assembly File"
Exit Sub
End If
Dim FstInp, SndInp As String
FstInp = InputBox("Please Enter String to be Replaced")
SndInp = InputBox("Please Enter String to Replace")
If FstInp <> "" And SndInp <> "" Then
root.Product.PartNumber = Replace(LCase(root.Product.PartNumber), LCase(FstInp), LCase(SndInp))
Call ALLTREE(root, FstInp, SndInp) ' callin procedure
Else
MsgBox "Input not reached correctly"
Exit Sub
End If
End Sub
Sub ALLTREE(Froot As ProductDocument, FstStr, SndStr)
Dim objFPrd As Product
Set objFPrd = Froot.Product
Dim objFPrds As Products
Set objFPrds = objFPrd.Products
For i = 1 To objFPrds.Count
Dim objFIns As Product
Set objFIns = objFPrds.Item(i)
objFIns.Name = Replace(LCase(objFIns.Name), LCase(FstStr), LCase(SndStr))
objFIns.PartNumber = Replace(LCase(objFIns.PartNumber), LCase(FstStr), LCase(SndStr))
If (TypeName(objFIns.ReferenceProduct.Parent) = "ProductDocument") Then
Call ALLTREE(objFIns.ReferenceProduct.Parent, FstStr, SndStr) 'if instance is product then calling the procedure
End If
Next
End Sub
RE: Rename CATIA V5 Product and Parts
This code worke But in replace "ABC" & "abc" is same!!!!
Please edite your code.
Very Thanks.
RE: Rename CATIA V5 Product and Parts
if you want to contribute and bring better stuff to the community I suggest you do your work and share it.
so pretty please, do some work, and thanks for sharing.
(sorry if I sound rude, I did not finish my morning coffee yet)
indocti discant et ament meminisse periti
RE: Rename CATIA V5 Product and Parts
______
Alex ,
RE: Rename CATIA V5 Product and Parts
Thanks to forum member
I mean,
Change the name of Part & Product that start by Non-Number:
ABC****=Dce***
but this code :
ABC*** => dce***
Pleas help me for Non-Numbers in name
Best Regards
RE: Rename CATIA V5 Product and Parts
@3DPLM
remove LCase from the replace string and use vbTextCompare as argument, then you will get the desired result
check below lines
objFIns.Name = Replace(objFIns.Name, FstStr, SndStr, , , vbTextCompare)
objFIns.PartNumber = Replace(objFIns.PartNumber, FstStr, SndStr, , , vbTextCompare)