help for rename toolpath...

help for rename toolpath...

lamtuyphong11
Contributor Contributor
849 Views
5 Replies
Message 1 of 6

help for rename toolpath...

lamtuyphong11
Contributor
Contributor

(view in My Videos)

Help me create a renaming macro as shown:
for example: using the same tool, change the name: 1-D10 and 2-D10 ---> 1-D10 and 1+1
Thanks

0 Likes
850 Views
5 Replies
Replies (5)
Message 2 of 6

icse
Advisor
Advisor

Try this macro:

 

 

string list $subFolders = get_folders('Toolpath')
int $index = input choice $subFolders 'Select Folder'


string $lastToolName = ''
int $counter = 0
int $subCounter = 0

foreach $tp in folder($subFolders[$index]) {
	
	if $tp.Tool.Name != $lastToolName {
		$subCounter = 0
		$counter = $counter + 1
		string $newName = $counter + '-' + $tp.Tool.Name
		rename toolpath $tp $newName
	} else {
		$subCounter = $subCounter + 1
		string $newName = $counter + '+' + $subCounter
		rename toolpath $tp $newName
	}
	$lastToolName = $tp.Tool.Name
}

 

 

 

0 Likes
Message 3 of 6

lamtuyphong11
Contributor
Contributor

it's great.Thank you so much....:))

0 Likes
Message 4 of 6

lamtuyphong11
Contributor
Contributor

Can you help me a little more ? ...i want these toolpaths to be able to go into 1 folder. can you help me ...

(view in My Videos)

0 Likes
Message 5 of 6

icse
Advisor
Advisor

It probly get messed up if the selected folder got subfolders.... so use with care

also i added a warning so the macro does not run if the project was not saved before

 

 

if length(project_pathname(0)) == 0 OR project_modified() == 1 {
	message warn 'Please Save Project first'
	return
}

string list $subFolders = get_folders('Toolpath')
int $index = input choice $subFolders 'Select Folder'


string $lastToolName = ''
string $desinationFolder = ''
string $folderName = ''
int $counter = 0
int $subCounter = 0

foreach $tp in folder($subFolders[$index]) {
	
	if $tp.Tool.Name != $lastToolName {
	
		$subCounter = 0
		$counter = $counter + 1
		string $newName = $counter + '-' + $tp.Tool.Name
		
		string $folderPath = $subFolders[$index]
				
		string $tempName = $newName
		$folderName = $newName
		int $i = 1
		while folder_exists($folderPath + '\' + $folderName) { 
			$folderName = $tempName + '_' + $i
			$i = $i + 1
		}
		$desinationFolder = $folderPath + '\' + $folderName
		
		CREATE FOLDER $folderPath $folderName		
		
		if entity_exists(entity('toolpath',$newName)) {
			$newName = new_entity_name('toolpath',$newName)
		}
		
		rename toolpath $tp $newName
		
		EDIT FOLDER $desinationFolder INSERT $newName LAST
		
	} else {
	
		$subCounter = $subCounter + 1
		string $newName = $counter + '+' + $subCounter
		
		if entity_exists(entity('toolpath',$newName)) {
			$newName = new_entity_name('toolpath',$newName)
		}
		
		rename toolpath $tp $newName		
		EDIT FOLDER $desinationFolder INSERT $newName LAST
	}
	
	$lastToolName = $tp.Tool.Name
}

 

 

i'm not quite happy with it so i probly do a rework on the weekend

Message 6 of 6

lamtuyphong11
Contributor
Contributor

It's also great. but it's not complete yet. very succulent you help. Thank you very much

0 Likes