×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Help with creating a Macro

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?

RE: Help with creating a Macro

Hi,

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

(OP)
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

RE: Help with creating a Macro

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

https://picasaweb.google.com/102257836106335725208

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources