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!

Instance name alteration Macro in CATIA V5

Status
Not open for further replies.

MerolaAlba

Automotive
Oct 19, 2017
12
PT
Hi everyone,

I need to make a macro to alter the instance name of selected accessories in several assemblies and sub assemblies using input boxes in CATIA V5. i'm fairly new to CATIA and CATScript and need help with this macro because it doesn't work in sub assemblies.
Can someone please help me?
I've gotten this far using the internet and several macros that i found and tweaked. and this thread really helped me thread560-340850, but i can't go any further on my own.
The macro is written in CATScript.
Thanks in advance.

Sub CATMain()

Dim oSelection As Selection
Set oSelection = CATIA.ActiveDocument.Selection

If oSelection.Count < 1 then
MsgBox "Pick some ejectors using cad selection."

Else

'****** Inputbox for Instance name alteration *****
Dim NewIName As String
NewIName = InputBox("Please input the desired Instance Name. Example: E","Instance name alteration","E")

'****** Inputbox for instance number increment *****
Dim NewINumber As Integer
NewINumber = InputBox("Please input the initial number for the 1st ejector. Example: 1","Instance numbering alteration","1")

Dim oBody
Dim InstName As Body

For oBody = 1 to oSelection.Count
Set InstName = oSelection.Item(oBody).Value

'****** Instance name alteration *****
InstName.Name= NewIName & NewINumber
NewINumber=NewINumber+1
Next

End if

End Sub
 
Replies continue below

Recommended for you

your code seems to work on selection only, if you want it to work on non selected sub assembly of selected element you have to include more (recursive) code. Check the ListingNames sub in the example you mentioned.

inside your
Code:
For oBody = 1 to oSelection.Count
[...]
next
you could include a call to a recursive sub...

Eric N.
indocti discant et ament meminisse periti
 
@itsmyjob

thanks for your reply.
I've tried to include the recursive more recursive code, but i can't seem to work it out.
Can you help me with this?
 
@drewmumaw

I've looked at your thread but as i mentioned in my original post i don't know where or even what to include in my code.
Can you please help me?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top