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: 

Renumber Toolpath

11 REPLIES 11
SOLVED
Reply
Message 1 of 12
Pedro_Valente
378 Views, 11 Replies

Renumber Toolpath

Hello everyone,

 

I need a MACRO to help me renumber the toolpaths inside folder.

The macro must do is DELETE 3 frist charters, and renumber with 3 new charters I gave.

 

Example:

020 - dfasdfgfg

021 - asdfasdf

025 - afasdfads

026 - asdfadfa

 

I run MACRO, select toolpaths I want renumber. Then I gave number 200 and macro remove 020, 021, 025, 026 and renumber with 200, 201, 202, 203......... Keep the entire name of toolpah except 3 frists numbers. 

I realy need re-organize toolpahs and takes me a lot of time change name one by one...

 

Please be kind to help me,

I already look entire forum trying to find. But nothing with 3 frists characters

 

I left some pictures to be like samples.

 

Thanks in advace for any help.

 

Best regards

Captura de ecrã 2024-06-11 090013.pngCaptura de ecrã 2024-06-11 090557.pngCaptura de ecrã 2024-06-11 090636.png

11 REPLIES 11
Message 2 of 12
icse
in reply to: Pedro_Valente

try this:

entity list $tps = input entity multiple toolpath 'Select Toolpaths:'
int $startNumb = input 'Start Number'


foreach $tp in $tps {
	string $newName = $startNumb + substring($tp.Name, 3)
	if entity_exists('toolpath',$newName) {
		$newName = new_entity_name('toolpath',$newName)
	}
	
	rename toolpath ${tp.Name} ${newName}
	
	$startNumb = $startNumb + 1
}

 

at least it should give you a good starting point, im currently not able to test it becose i dont have a powermill licence atm.

Message 3 of 12
Pedro_Valente
in reply to: icse

That was an nice begin. I apreciate that. Thank you.

Now I need to limit numbers to 3 digits. I got  something here maybe that helps.

This Macro is to re-name NCPROGRAMS, just need adapt to Toolpaths and insert on your help.

If I rename toolpath with number 10, this macro put an new 0 before, completing 3 desire digits.

 

// ----------------------------------------------------------------------------------
// Macro to renumber programs incrementing by 1 each time and adding leading zeros until field width is achieved, currently at 3 characters
// ==================================================================================


Function main(){
//Variables - Variáveis
String msg = ""
Int num_length = ""
int num = 0
string snum = ""
string NC = ""
int count = 0

//Set required field width for number
//Defina a largura do campo necessária para o número
int field_width = 3

$msg = "Selecione os programas para renomear FANUC"
//$msg = "Select programs to re-number"

//Cria uma lista de todos os programas em sessão
//Create a list of all programs in session
ENTITY LIST NCP = INPUT ENTITY MULTIPLE NCProgram $msg

$msg = "Digite o primeiro numero do programa (3 Digitos)"
//$msg = "Enter first Program number"

//O número do programa não excede a largura do campo
//Check number does not exceed field_width
Do {
$num = input $msg
//Retorna o comprimento da imputação do número
//Returns length of number imput
$num_length = length($num)

If ($num_length > $field_width) {
$msg = "Numero muito longo! - Digite novamente com 4 digitos"
//$msg = "Number too long! - Re-enter"
}

} while ($num_length > $field_width)

//loop sobre cada programa selecionado e renumerar
//loop over each selected program and re-number
FOREACH $pg IN NCP {
	ACTIVATE NCProgram $pg.Name
	$num_length = length($num)
	$snum = $num
	if ($num_length < $field_width) {
		//chama a função para adicionar zeros à esquerda até que a largura do campo seja alcançada
		//call function to add leading zeroes until field width is achieved
		call leading_zeroes($num, $snum, $num_length, $field_width)
		}

	RENAME NCProgram $pg.Name $snum
	$num = $num + 1
	}

DEACTIVATE NCProgram



STRING MacroFilePath = macro_path(false) + "\Ren_Fanuc_NC-Apoio.mac"
MACRO $MacroFilePath


}



//This macro puts the prefix (User input 'ProjectName') after each ncprogram name



 

Function leading_zeroes(int num, output string snum, int num_length, int field_width) {
//Verifica a largura do campo não mais ou menos que 3 caracteres
//Check field width not more or less than 3 characters

$snum = $num
Do {
//increment snum by adding leading zero
$snum = "0" + $snum
//incrementa snum adicionando zero à esquerda
//get lenth of $snum string
$num_length = length($snum)
} while ($num_length < $field_width)

}

 

 

Message 4 of 12
icse
in reply to: Pedro_Valente

can you test this:

entity list $tps = input entity multiple toolpath 'Select Toolpaths:'
int $startNumb = input 'Start Number'


foreach $tp in $tps {
	
	//this shoud add leading zeros if the lenght of the number is less than 3 digits
	string $prefix = substring('000', 0, 3 - length(string($startNumb))) + $startNumb
	
	
	string $newName = $prefix + substring($tp.Name, 3)
	if entity_exists('toolpath',$newName) {
		$newName = new_entity_name('toolpath',$newName)
	}
	
	rename toolpath ${tp.Name} ${newName}
	
	$startNumb = $startNumb + 1
}

 

this probably gets messed up if you enter a number longer/closeto 3 digits

Message 5 of 12
Pedro_Valente
in reply to: icse

Thank You for the help.

I tryed start with only 1 and macro goes to 001. For a mess I input 998 and it make a mess. But no problem for me.

 

 

Captura de ecrã 2024-06-11 111118.png

Message 6 of 12
icse
in reply to: Pedro_Valente

if the number goes past 999 you could reset it to 1 so you dont mess up the formating:

entity list $tps = input entity multiple toolpath 'Select Toolpaths:'
int $startNumb = input 'Start Number'


foreach $tp in $tps {
	
	//this shoud add leading zeros if the lenght of the number is less than 3 digits
	string $prefix = substring('000', 0, 3 - length(string($startNumb))) + $startNumb
	
	
	string $newName = $prefix + substring($tp.Name, 3)
	if entity_exists('toolpath',$newName) {
		$newName = new_entity_name('toolpath',$newName)
	}
	
	rename toolpath ${tp.Name} ${newName}
	
	$startNumb = $startNumb + 1
	if $startNumb > 999 {
		$startNumb = 1
	}
}
Message 7 of 12
Pedro_Valente
in reply to: icse

Thank you one more time.

 

Can you please check another thing ?

 

If the number exist, just replace.

 

Sample:

 

100_gsgs

101_afgasfg

105_afasdf

106_asdfa

 

After run Macro (starting in 100):

 

100_gsgs_1

101_afgasfg_1

102_afasfd

103_asdfa

 

Macro put _1 at end because number 100 already exists. Is it possible do something about it?

 

Thank you

Message 8 of 12
icse
in reply to: Pedro_Valente

entity list $tps = input entity multiple toolpath 'Select Toolpaths:'
int $startNumb = input 'Start Number'


foreach $tp in $tps {
	
	//this shoud add leading zeros if the lenght of the number is less than 3 digits
	string $prefix = substring('000', 0, 3 - length(string($startNumb))) + $startNumb
	
	
	string $newName = $prefix + substring($tp.Name, 3)
	
	if $tp.Name == $newName {
		continue
	}
	
	if entity_exists('toolpath',$newName) {
		$newName = new_entity_name('toolpath',$newName)
	}
	
	rename toolpath ${tp.Name} ${newName}
	
	$startNumb = $startNumb + 1
	if $startNumb > 999 {
		$startNumb = 1
	}
}
Message 9 of 12
Pedro_Valente
in reply to: icse

Not yet, if Macro found same number it just continue.

 

Sample:

110_qwerty

111_qwerty

111_ytrewq

111_qwertyu

120_qwerty

121_qwerty

 

Macro does:

 

110_qwerty

111_qwerty

111_ytrewq

111_qwertyu

112_qwerty

113_qwerty

Message 10 of 12

Look at screen recorder

Message 11 of 12
icse
in reply to: Pedro_Valente

ahh yea i forgot to increment the number before skipping... its kinda hard i cant test the macro by myselve sorry for that ^^

THX for the clip it helped a lot.

 

entity list $tps = input entity multiple toolpath 'Select Toolpaths:'
int $startNumb = input 'Start Number'


foreach $tp in $tps {
	
	//this shoud add leading zeros if the lenght of the number is less than 3 digits
	string $prefix = substring('000', 0, 3 - length(string($startNumb))) + $startNumb
	
	
	string $newName = $prefix + substring($tp.Name, 3)
	
	if $tp.Name == $newName {
	
		$startNumb = $startNumb + 1
		
		if $startNumb > 999 {
			$startNumb = 1
		}
		
		continue
	}
	
	if entity_exists('toolpath',$newName) {
		$newName = new_entity_name('toolpath',$newName)
	}
	
	rename toolpath ${tp.Name} ${newName}
	
	$startNumb = $startNumb + 1
	
	if $startNumb > 999 {
		$startNumb = 1
	}
}

 

 

 

Message 12 of 12
Pedro_Valente
in reply to: icse

Step by Step this Macro grows and turns perfect for me.

Thank you very much.

 

With Best Regards

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report