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!

Help with creating a Macro

Status
Not open for further replies.

FTARunner

Automotive
Sep 12, 2012
3
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?
 
Replies continue below

Recommended for you

Just to update; I got a macro that renamed the instance name to be the same as the part name. That works great but I wasn't looking at the whole problem.

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
 
Hi

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

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor