VojtaR
Automotive
- Apr 2, 2020
- 20
Hello,
I have a macro which add a prefix to everything I select (Geometrical sets, bodies, sketches, lines, outputs, surface features, parameters etc...)
Would someone be able to modify it, so it have the same function + when I run it again on already renamed features, it will change its prefix. I do not mind to use a special sign, for "ending" the prefix, so it recognizes, that it was already renamed and it will change only its prefix. e.g. Body.1 (first rename)--> Hello__Body.1 (second rename)--> WOW__Body.1
Macro looks like this:
Thank you for your inputs.
I have a macro which add a prefix to everything I select (Geometrical sets, bodies, sketches, lines, outputs, surface features, parameters etc...)
Would someone be able to modify it, so it have the same function + when I run it again on already renamed features, it will change its prefix. I do not mind to use a special sign, for "ending" the prefix, so it recognizes, that it was already renamed and it will change only its prefix. e.g. Body.1 (first rename)--> Hello__Body.1 (second rename)--> WOW__Body.1
Macro looks like this:
Code:
Sub CATMain()
Dim PartDocument1 As Document
Set PartDocument1 = CATIA.ActiveDocument
Dim Part1 As Part
Set Part1 = PartDocument1.Part
Dim Parameters1 As Parameters
Set Parameters1 = Part1.Parameters
Dim Parameter1 As Parameter
Dim oSel as selection
On Error Resume Next
Set objSel = PartDocument1.Selection
if Err.Number<>0 then
msgbox("error")
objSel=oSel.SelectElement2(inputobject, "You have to select Apropriate Geometrical set for rename function", true)
on Error Goto 0
end if
gsname= objSel.item(1).value.name
objSel.Search ("'Generative Shape Design'.,sel")
DIM Text AS STRING
Dim vstup as string
Dim nazev as string
vstup=inputbox("Please input text before parametrs name:")
For i = 1 to objSel.Count
Text=""
Text= vstup&"_"&objSel.Item(i).value.name
objSel.Item(i).value.name =Text
next
objSel.Search (gsname)
objSel.Search ("CATKnowledgeSearch.InternalParameter,sel")
For i = 1 to objSel.Count
Text=""
pozice=InStrRev(objSel.Item(i).value.name, "\",-1)
nazev= right(objSel.Item(i).value.name,len(objSel.Item(i).value.name)-pozice)
Text=Left(objSel.Item(i).value.name, pozice-2)
pozice2 = InStrRev(Text, "\",-1)
Text=Mid(Text, pozice2+1 ,Len(Text)-16-pozice2 )
' msgbox("text: "&text)
' msgbox("nazev: "&nazev)
Text=vstup & "_" & nazev
' msgbox(text)
objSel.Item(i).value.rename (Text)
Next
End Sub
Thank you for your inputs.