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