Macro Gurus Help Please

Macro Gurus Help Please

markdiGXTYE
Contributor Contributor
981 Views
8 Replies
Message 1 of 9

Macro Gurus Help Please

markdiGXTYE
Contributor
Contributor

So I know there is a lot of information about toolpath renaming, but I require a specific naming scheme for my company's internal needs. I would like to pull the toolpath folder name and change the order of the characters, add "OP" and an A,B,C and so on if the toolpath has the same name. Here's a screenshot of what I'm looking for:

Toolpath Name.PNG


Any help is appreciated!

0 Likes
Accepted solutions (1)
982 Views
8 Replies
Replies (8)
Message 2 of 9

cfastNJWK6
Advisor
Advisor

Could you upload a picture of what the toolpath names look like before and how you would like them to look after the macro is ran?

0 Likes
Message 3 of 9

markdiGXTYE
Contributor
Contributor

I would like it to replace the toolpaths with what I have named to the way it looks on the screen snip. Plus I would like to run the macro off an active folder containing the toolpath folders. That's why I thought pulling the toolpath folder name might work out better, the toolpath folders will be named already.

0 Likes
Message 4 of 9

cfastNJWK6
Advisor
Advisor

You will have to be very consistent with how you name your folders for this type of macro to work.  Right now it looks like you want to take the third character of the folder name and make that the first character of the toolpath name.  Then add "OP".  Then add the first character of the folder name.  Then add the last 2 characters of the folder name.  If that name already exists in the folder, add the next letter of the alphabet to the end of the toolpath name.

 

Does that logic seem correct?

0 Likes
Message 5 of 9

markdiGXTYE
Contributor
Contributor

Yes, exactly. Unless there is an easier solution then pulling the folder name

0 Likes
Message 6 of 9

cfastNJWK6
Advisor
Advisor

Something like this should be close to what you are looking for:

STRING LIST $Alphabet = {'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 LIST $TpFolders = get_folders('toolpath')

INT $TpFolder = INPUT CHOICE $TpFolders "Select Folder"
STRING $FolderPath = $TpFolders[0]
STRING $FolderName = $TpFolders[0]
$FolderName = replace($FolderName, "Toolpath\", "")

STRING $TpBaseName = ""
$TpBaseName = substring($FolderName, 2, 1) + "OP" + substring($FolderName, 0, 1) + substring($FolderName, 3, 2)

INT $counter = 0
FOREACH $tp IN folder($FolderPath) {
	
	STRING $NewName = $TpBaseName
	IF entity_exists(entity('Toolpath', $NewName)) {
		$NewName = $NewName + $Alphabet[$counter]
		$Counter = $Counter + 1
		}
	RENAME TOOLPATH $tp $NewName
	
	}
0 Likes
Message 7 of 9

markdiGXTYE
Contributor
Contributor

Thanks for taking the time to write this out. It doesn't work exactly as expected, it seems to just read the top folder in the toolpath tree. Any way to use the name from the active folder?

0 Likes
Message 8 of 9

cfastNJWK6
Advisor
Advisor
Accepted solution

The previous macro will use whatever folder you select in the drop-down menu.  This one will use the active folder:

STRING LIST $Alphabet = {'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 LIST $TpFolders = get_folders('toolpath')

//INT $TpFolder = INPUT CHOICE $TpFolders "Select Folder"
INT $TpFolder = ACTIVE_FOLDER()
STRING $FolderPath = $TpFolders[0]
STRING $FolderName = $TpFolders[0]
$FolderName = replace($FolderName, "Toolpath\", "")

STRING $TpBaseName = ""
$TpBaseName = substring($FolderName, 2, 1) + "OP" + substring($FolderName, 0, 1) + substring($FolderName, 3, 2)

INT $counter = 0
FOREACH $tp IN folder($FolderPath) {
	
	STRING $NewName = $TpBaseName
	IF entity_exists(entity('Toolpath', $NewName)) {
		$NewName = $NewName + $Alphabet[$counter]
		$Counter = $Counter + 1
		}
	RENAME TOOLPATH $tp $NewName
	
	}
0 Likes
Message 9 of 9

markdiGXTYE
Contributor
Contributor

Cool, I have something that works. Thanks for the help!