Community
PowerMill Forum
Welcome to Autodesk’s PowerMill Forums. Share your knowledge, ask questions, and explore popular PowerMill topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Rename with incremental number and letter

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
evo80
402 Views, 7 Replies

Rename with incremental number and letter

Good Day,

I have a macro which will incrementally number selected toolpaths, however, I'd like to number selected toolpaths as such 1a 1b 1c etc. or 2a 2b 2c etc.

Just a wee snippet of my incremental numbering macro.

IF $powermill.Status.MultipleSelection.First OR $powermill.Status.MultipleSelection.Total == 0 {
reset localvars
string $new_name = ""
STRING Strategy = 'null'

DIALOGS MESSAGE OFF
DIALOGS ERROR OFF
GRAPHICS LOCK
   


//starting number
INT StartNumber = INPUT "Start at #?"
INT start = $StartNumber
STRING start1 = $StartNumber 
INT i = $start1


//set text to replace and new text
STRING oldText =  "."
STRING newText =  ","
}

  FOREACH $tp IN explorer_selected_entities() {

	  If $tp.Strategy == 'drill' AND $tp.drill.type == 'single_peck' {
        
          

RENAME TOOLPATH $tp.Name ${ i + tp.Strategy + tp.drill.type + tp.Tool.name + "-T" + tp.tool.number  }

$i = $i + 1
}
7 REPLIES 7
Message 2 of 8
amin13751387
in reply to: evo80

only suggestion;
If you have problem with dot in Toolpaths name, you can use REPLACE command.
STRING $newName = replace($tp.name, "." , ",")
rename toolpath ; $newName
Message 3 of 8
icse
in reply to: evo80

string list $abc = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}
int $index = 0
foreach $tp in $explorer_selected_entities() {
	string $newname = $tp.Name + $abc[$index]
	if entity_exists('toolpath',$newname) {
		$newname = new_entity_name('toolpath',$newname)
	}
	rename toolpath ${tp.Name} ${newname}
	$index = $index + 1
	if $index > 25 {
		$index = 0
	}
}
Message 4 of 8
evo80
in reply to: icse

@icse ,

Thanks, that worked great.

Here is my code.

I have a pop up asking what number to start at, how do I modify to also ask which letter to start from als

IF $powermill.Status.MultipleSelection.First OR $powermill.Status.MultipleSelection.Total == 0 {
reset localvars
string $newname = ""
STRING Strategy = 'null'

DIALOGS MESSAGE OFF
DIALOGS ERROR OFF
GRAPHICS LOCK

//starting number
INT StartNumber = INPUT "Start at #?"
INT start = $StartNumber
STRING start1 = $StartNumber 
INT i = $start1
$tp.name = ""


string list $abc = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}
int $index = 0
foreach $tp in $explorer_selected_entities() {
	string $newname = $i +  $abc[$index] + '-' + $tp.Strategy + $tp.Tool.name + "XY" + $tp.Thickness + "Z" + $tp.axial_thickness + "-T" + $tp.tool.number 
			if entity_exists('toolpath',$newname) {
		$newname = new_entity_name('toolpath')
		}
	rename toolpath ${tp.Name} ${newname}
	STRING $newName1 = replace($newname, ".0" , "" )
    rename toolpath $newname $newName1 
		$index = $index + 1
	if $index > 25 {
		$index = 0
	}
}

DEACTIVATE Toolpath
DEACTIVATE TOOL
UNDRAW TOOL ALL

DIALOGS MESSAGE ON
DIALOGS ERROR ON
GRAPHICS UNLOCK

o?

I've tried a few things with no success

Message 5 of 8
icse
in reply to: evo80

you could do something like this:

 

IF $powermill.Status.MultipleSelection.First OR $powermill.Status.MultipleSelection.Total == 0 {
reset localvars
string $newname = ""
STRING Strategy = 'null'

DIALOGS MESSAGE OFF
DIALOGS ERROR OFF
GRAPHICS LOCK

//starting number
INT StartNumber = INPUT "Start at #?"
INT start = $StartNumber
STRING start1 = $StartNumber 
INT i = $start1
$tp.name = ""


string list $abc = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}
int $index = input choice $abc 'select start letter'

foreach $tp in $explorer_selected_entities() {
	string $newname = $i +  $abc[$index] + '-' + $tp.Strategy + $tp.Tool.name + "XY" + $tp.Thickness + "Z" + $tp.axial_thickness + "-T" + $tp.tool.number 
			if entity_exists('toolpath',$newname) {
		$newname = new_entity_name('toolpath')
		}
	rename toolpath ${tp.Name} ${newname}
	STRING $newName1 = replace($newname, ".0" , "" )
    rename toolpath $newname $newName1 
		$index = $index + 1
	if $index > 25 {
		$index = 0
	}
}

DEACTIVATE Toolpath
DEACTIVATE TOOL
UNDRAW TOOL ALL

DIALOGS MESSAGE ON
DIALOGS ERROR ON
GRAPHICS UNLOCK

 

 

or better :

 

IF $powermill.Status.MultipleSelection.First OR $powermill.Status.MultipleSelection.Total == 0 {
reset localvars
string $newname = ""
STRING Strategy = 'null'

DIALOGS MESSAGE OFF
DIALOGS ERROR OFF
GRAPHICS LOCK

//starting number
INT StartNumber = INPUT "Start at #?"
INT start = $StartNumber
STRING start1 = $StartNumber 
INT i = $start1
$tp.name = ""


string list $abc = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}
string $userInput = input 'start char'

int $index = 0
if member($abc, $userInput) {
	$index = get_index($abc, $userInput)
}

foreach $tp in $explorer_selected_entities() {
	string $newname = $i +  $abc[$index] + '-' + $tp.Strategy + $tp.Tool.name + "XY" + $tp.Thickness + "Z" + $tp.axial_thickness + "-T" + $tp.tool.number 
			if entity_exists('toolpath',$newname) {
		$newname = new_entity_name('toolpath')
		}
	rename toolpath ${tp.Name} ${newname}
	STRING $newName1 = replace($newname, ".0" , "" )
    rename toolpath $newname $newName1 
		$index = $index + 1
	if $index > 25 {
		$index = 0
	}
}

DEACTIVATE Toolpath
DEACTIVATE TOOL
UNDRAW TOOL ALL

DIALOGS MESSAGE ON
DIALOGS ERROR ON
GRAPHICS UNLOCK

 

Message 6 of 8
evo80
in reply to: evo80

@icse ,

That's just the ticket!

Cheers!

Message 7 of 8
evo80
in reply to: icse

So this works great @icse,

Just out of curiosity, what would the code be to automatically add a value into the Letter user input box, say a default 'a' for instance?

 

Message 8 of 8
icse
in reply to: evo80

IF $powermill.Status.MultipleSelection.First OR $powermill.Status.MultipleSelection.Total == 0 {
reset localvars
string $newname = ""
STRING Strategy = 'null'

DIALOGS MESSAGE OFF
DIALOGS ERROR OFF
GRAPHICS LOCK

//starting number
INT StartNumber = INPUT "Start at #?"
INT start = $StartNumber
STRING start1 = $StartNumber 
INT i = $start1
$tp.name = ""


string list $abc = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}
string $userInput = 'a'
$userInput = input 'start char'

int $index = 0
if member($abc, $userInput) {
	$index = get_index($abc, $userInput)
}

foreach $tp in $explorer_selected_entities() {
	string $newname = $i +  $abc[$index] + '-' + $tp.Strategy + $tp.Tool.name + "XY" + $tp.Thickness + "Z" + $tp.axial_thickness + "-T" + $tp.tool.number 
			if entity_exists('toolpath',$newname) {
		$newname = new_entity_name('toolpath')
		}
	rename toolpath ${tp.Name} ${newname}
	STRING $newName1 = replace($newname, ".0" , "" )
    rename toolpath $newname $newName1 
		$index = $index + 1
	if $index > 25 {
		$index = 0
	}
}

DEACTIVATE Toolpath
DEACTIVATE TOOL
UNDRAW TOOL ALL

DIALOGS MESSAGE ON
DIALOGS ERROR ON
GRAPHICS UNLOCK

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report