Rename all the entities in a model using TCL script.


Updated by Altair Forum User
Hello Friends,
I want to rename all the entities in a model with some prefix.
For example:
Component Name: 51002134 to New Name: PSHELL_51002134
Can anyone please provide me a TCL script to do it.
Sort by:
1 - 2 of
21

Altair Forum User

Updated by Altair Forum User
proc rename_things { } {
variable sFrom
variable sTo
variable colValues
foreach col [array names colValues] {
if {$colValues($col) == 1} {
foreach setName [hm_entitylist $col name] {
if {[set newName [string map [list $sFrom $sTo] $setName]]!= $setName} {
catch {*renamecollector $col $setName $newName}
}
}
}
}
}
proc initColNames { } {
variable colNames
set colNames(nameList) [list comps props materials loadcols sets groups beamsectcols systemcols shapes vectorcols]
set colNames(comps) 'Components'
set colNames(props) 'Propertys'
set colNames(materials) 'Materials'
set colNames(loadcols) 'Load Collectors'
set colNames(groups) 'Groups'
set colNames(beamsectcols) 'Beam Section Collectors'
set colNames(systemcols) 'System Collectors'
set colNames(vectorcols) 'Vector Collectors'
set colNames(shapes) 'Shapes'
set colNames(sets) 'Entity Sets'
}
proc buildGUI { } {
variable colNames
variable sFrom
variable sTo
variable colValues
set sFrom ''
set sTo ''
set curNs [namespace current]
# destroy window if it already exist
if {[winfo exists .build_renameGui]} {
destroy .build_renameGui
}
# create window
set build_expand [ hwt::CreateWindow build_renameGui \
-windowtitle 'Modify Names : Altair Hyd' \
-post \
-noGeometrySaving \
-geometry 260x320 \
-minSize 260 320 \
-noCommandArea \
]
::hwt::KeepOnTop $build_expand
set build_expandPanel [hwt::WindowRecess $build_expand];
# okCancleFrame
set okcanFrame [frame $build_expand.ok]
pack $okcanFrame -side top -anchor e
set okButton [button $okcanFrame.ok -width 10 -text ' OK ' -command 'destroy .build_renameGui; ${curNs}::rename_things']
set cancelButton [button $okcanFrame.cancel -width 10 -text 'Discard' -command { destroy .build_renameGui; } ]
pack $cancelButton $okButton -side right -padx 4 -pady 4 -anchor e
# build fram
set stringsFrame [frame $build_expandPanel.stringsframe]
pack $stringsFrame -side top -anchor n
set labelFrom [label $stringsFrame.labelfrom -text 'Search for:' ]
set valueFrom [entry $stringsFrame.valuefrom -textvariable ${curNs}::sFrom -width 25]
grid $labelFrom -row 0 -column 0 -columnspan 2 -padx 5 -sticky e
grid $valueFrom -row 0 -column 2 -padx 5 -sticky w
set labelTo [label $stringsFrame.labelto -text 'Replace with:' ]
set valueTo [entry $stringsFrame.valueto -textvariable ${curNs}::sTo -width 25]
grid $labelTo -row 1 -column 0 -columnspan 2 -padx 5 -sticky e
grid $valueTo -row 1 -column 2 -padx 5 -sticky w
set colFrame [hwt::LabeledFrame $build_expandPanel.colframe ' Affected Entitys: ' \
-side left -anchor nw -padx 2 -pady 10 -justify left ]
set row 2
array unset colValues
foreach col $colNames(nameList) {
set colValues(${col}) 0
# Default wert...
set label [label $colFrame.label$col -text $colNames($col)]
set check [checkbutton $colFrame.check$col -variable ${curNs}::colValues(${col}) -onvalue 1]
grid $check -row $row -column 0 -padx 2
grid $label -row $row -column 1 -padx 2 -sticky w
incr row
#foreach
}
return 1
}
## end proc buildGUI
proc ::run {args} {
initColNames
buildGUI
}
run 0


Updated by Altair Forum User
you can rename its work like textpad, it replaces property name material name also