can you try this:
entity list $ncs = input entity multiple ncprogram 'select nc programs wich should be renamed:'
if size($ncs) < 1 {
return
}
foreach $nc in $ncs {
if size(components($nc)) < 1 {
continue
}
string list $tpsuffixes = {}
foreach $tp in components($nc) {
int $i = add_last($tpsuffixes, tokens($tp.Name,'_')[0])
}
string $newNcName = join($tpsuffixes,'_And_') + '_' + components($nc)[0].Tool.Name
if $nc.Name == $newNcName {
continue
}
if entity_exists('ncprogram',$newNcName) {
$newNcName = new_entity_name('ncprogram',$newNcName)
}
rename ncprogram ${nc.Name} ${newNcName}
}