Rename toolpath macro

Rename toolpath macro

todd.murphy8YH67
Contributor Contributor
1,266 Views
7 Replies
Message 1 of 8

Rename toolpath macro

todd.murphy8YH67
Contributor
Contributor

Good day,

I am looking for a Macro that will add a prefix to all selected toolpaths, but with a variable .

 

i want to add "OP 10"

then next toolpath add "OP 20"

"OP 30" and so on...

 

i have searched pretty well in forums and can not find one that suits this.

if so can anyone help me out?

0 Likes
Accepted solutions (2)
1,267 Views
7 Replies
Replies (7)
Message 2 of 8

TK.421
Advisor
Advisor

here's the one I use. you'll have to modify it to suit your needs


the numbers never lie
0 Likes
Message 3 of 8

todd.murphy8YH67
Contributor
Contributor
thanks for the solution, it does exactly what you said . I was hoping there was anymore solutions out there?
0 Likes
Message 4 of 8

icse
Advisor
Advisor
Accepted solution

i use following macros to Prefix or Suffix any selected entity in powermill explorer, except for folders.

I've bound em to  [control + y] and [shift + control + y]

 

Prefix:

 

 

entity LIST $input = explorer_selected_entities()
if size($input) <= 0 {
	return
}
string $prefix = input "Prefix"

if $prefix == ' ' {
	return
}

foreach $et in $input {
	string $newName = $prefix + $et.Name
	string $tempName = $newName
	int $i = 1
	while entity_exists($et.RootType, $newName) { 
		$newName = $tempName + '_' + $i
		$i = $i + 1
	}
	string $cmd = "Rename " + et.RootType + ' "' + $et.Name + '" "' + $newName + '"'	
	DoCommand $cmd
}

 

 

 

Suffix:

 

 

entity LIST $input = explorer_selected_entities()
if size($input) <= 0 {
	return
}
string $suffix = input "Suffix"

if $suffix == ' ' {
	return
}

foreach $et in $input {
	string $newName =  $et.Name + $suffix
	string $tempName = $newName
	int $i = 1
	while entity_exists($et.RootType, $newName) { 
		$newName = $tempName + '_' + $i
		$i = $i + 1
	}
	string $cmd = "Rename " + et.RootType + ' "' + $et.Name + '" "' + $newName + '"'	
	DoCommand $cmd
}

 

 

 

 

Following macro adds a prefix and an increasing number to the name:

 

entity LIST $input = explorer_selected_entities()
if size($input) <= 0 {
	return
}
string $prefix = input "Prefix"

if $prefix == ' ' {
	return
}

int $counter = 0

foreach $et in $input {
	$counter = $counter + 10
	string $newName = $prefix + '_' + $counter + '_' + $et.Name
	string $tempName = $newName
	int $i = 1
	while entity_exists($et.RootType, $newName) { 
		$newName = $tempName + '_' + $i
		$i = $i + 1
	}
	string $cmd = "Rename " + et.RootType + ' "' + $et.Name + '" "' + $newName + '"'	
	DoCommand $cmd
}

 

 I couldn't test it because I'm not at work...

0 Likes
Message 5 of 8

todd.murphy8YH67
Contributor
Contributor

Beautiful, thanks a lot @icse , only thing i wished it asked which programs, but the fix was for me to highlight all toolpaths prior to running the macros.

0 Likes
Message 6 of 8

icse
Advisor
Advisor

Do you want to execute this on all toolpaths within an NC program?

 

Something like this?

entity $nc = input entity ncprogram "Chose NC PGM"
foreach $tp in components($nc) {
	//do the rename
}

 

0 Likes
Message 7 of 8

todd.murphy8YH67
Contributor
Contributor

@icse ,

No just what is in the toolpath folder.

0 Likes
Message 8 of 8

icse
Advisor
Advisor
Accepted solution

like this?

entity $input= input entity multiple toolpath "Chose"
foreach $tp in $input {
	//do the rename
}
0 Likes