Help with creating a Macro
Help with creating a Macro
(OP)
In short, I need a macro to search through the whole assembly in Catia V5 and rename or remove *.1 from the instance name.
I got up to a point where I was able to search the whole assembly, select all the parts with a *.1, but it looks for that specific part name.
Any ideas?
I got up to a point where I was able to search the whole assembly, select all the parts with a *.1, but it looks for that specific part name.
Any ideas?





RE: Help with creating a Macro
Can you post what you have now (code) and a picture with what you want in fact?
I think I know what you want but just to be sure (rename is a little bit different then remove...)
Regards
Fernando
https://picasaweb.google.com/102257836106335725208
RE: Help with creating a Macro
Basic: I need a macro that will remove spaces from the part name (and instance name if able). So for example; DVR Front Door Lower Ring will change to DVRFrontDoorLowerRing.
I usually get rather large assemblies and we have to take these assemblies into another program. When it converts the geometry, it changes any spaces and periods to underscores and I end up having to go through all the part names and change them.
This is the macro. I did change a little bit, so there might be a line that is irrelevant or useless.
Sub CATMain()
Language="VBSCRIPT"
Set Documents = CATIA.documents
For Each Item In Documents
If Right(item.Name, 10) = "CATProduct" Then
Set CurrentProduct = item.Product.Products
For i = 1 To CurrentProduct.count
CurrentPartNumber = CurrentProduct.item(i).PartNumber
k = 1
For j = 1 to CurrentProduct.count
CurrentLine = CurrentProduct.item(j).PartNumber
If CurrentLine = CurrentPartNumber Then
CurrentProduct.item(j).Name = CurrentPartNumber
k = k + 1
End If
Next
Next
End If
Next
End Sub
RE: Help with creating a Macro
To replace a string (in your case a blank space) only in PartNumber you can use in a CATScript
Language="VBSCRIPT"
Sub CATMain()
Set productDocument1 = CATIA.ActiveDocument
Set product1 = productDocument1.Product
Set products1 = product1.Products
Dim StrToBeReplaced
Dim sLF
sLF = Chr(10)
StrToBeReplaced = InputBox("Write here string to be replaced", "Input for String to be replaced", "A string", vbOKCancel)
If StrToBeReplaced = False Then
Exit Sub
End If
Dim StrUsedForReplace
StrUsedForReplace = InputBox("Write here string to be used for replace", "Input for String to be used for replace", "A string", vbOKCancel)
If StrUsedForReplace = False Then
Exit Sub
End If
For i = 1 To products1.Count
ElementNumber = products1.Item(i).Partnumber ' Extract reference number
ElementNumberReplaced = Replace(ElementNumber, StrToBeReplaced, StrUsedForReplace)
products1.Item(i).Partnumber = ElementNumberReplaced
Next
End Sub
Regards
Fernando
https://picasaweb.google.com/102257836106335725208