Macro to create and populate a folder

Macro to create and populate a folder

Beta_Librae
Advocate Advocate
1,399 Views
18 Replies
Message 1 of 19

Macro to create and populate a folder

Beta_Librae
Advocate
Advocate

Good Afternoon All,

 

Trying to get this macro to run. Seems like it should be fairly simple, but can't wrap my Peabrain around it.

The first block runs, the second block runs, can't get it to run as a whole. Any help would be greatly appreciated.

 

 

FUNCTION Main()  {
     CREATE FOLDER "Toolpath" ;
     ACTIVATE FOLDER "Toolpath\Folder1"
     RENAME FOLDER "Toolpath\Folder1"
}

FOREACH toolpath IN folder ("TOOLPATH")  {
            STRING $Path = dirname(pathname(toolpath))
            IF $Path == 'Toolpath' {
                EDIT FOLDER ; INSERT $toolpath LAST
            }
}

 

DEACTIVATE FOLDER


Kind Regards,
Not cnc, you can call me Peabrain
0 Likes
Accepted solutions (3)
1,400 Views
18 Replies
Replies (18)
Message 2 of 19

TK.421
Advisor
Advisor

put everything inside your main()

 

FUNCTION Main()  {
     CREATE FOLDER "Toolpath" ;
     ACTIVATE FOLDER "Toolpath\Folder1"
     RENAME FOLDER "Toolpath\Folder1"

 

      FOREACH toolpath IN folder ("TOOLPATH")  {
            STRING $Path = dirname(pathname(toolpath))
            IF $Path == 'Toolpath' {
                EDIT FOLDER ; INSERT $toolpath LAST
            }
       }

        DEACTIVATE FOLDER

}


the numbers never lie
0 Likes
Message 3 of 19

Beta_Librae
Advocate
Advocate

Thanks for the reply. I thought it was the brackets but couldn't get it.

 

Now it's holding up on line 7.

 

cnc_0-1681237867939.png

 

Wants to call the folder "STRING"?


Kind Regards,
Not cnc, you can call me Peabrain
0 Likes
Message 4 of 19

TK.421
Advisor
Advisor

ran it through the debugger. you have to take out the rename folder command in there & then use DOCOMMAND to create and activate it with a specific name.  i tried the below and it works 

FUNCTION Main()  {
	STRING fName = INPUT "Enter Folder Name: "
	STRING myCmd = "CREATE FOLDER" + '"Toolpath"' + $fName
	DOCOMMAND $myCmd

	$myCmd = "ACTIVATE FOLDER " + '"Toolpath\' + $fName + '"'
	DOCOMMAND $myCmd



	FOREACH tp IN folder ("TOOLPATH")  {
		STRING $Path = dirname(pathname(tp))
		IF $Path == 'Toolpath' {
			EDIT FOLDER ; INSERT $tp LAST
		}
	}
	DEACTIVATE FOLDER
}

 

 


the numbers never lie
0 Likes
Message 5 of 19

Beta_Librae
Advocate
Advocate

Hate to be a pain in the ass, but now it's holding up on line 4.

 

cnc_0-1681241500916.png

 

If it worked for you, I'm not sure what I'm doing wrong.

Running it through the ribbon, and the macro list. Same result.


Kind Regards,
Not cnc, you can call me Peabrain
0 Likes
Message 6 of 19

TK.421
Advisor
Advisor

hmmmm. i just ran it again and it ran fine. did you copy & paste everything that was in there? 


the numbers never lie
0 Likes
Message 7 of 19

Beta_Librae
Advocate
Advocate

Hey, sorry, I'd left for the day.

 

I'm sure I did copy everything. Deleted it all and copied again. This is what I've got.

 

cnc_0-1681300816420.png

Closed my session, reopened, and tried again. I got the same result.

Running it out of the "Choose"  button. it gets as far as naming the folder, but doesn't create it.

cnc_1-1681301068309.png

Holds up here again on line 4?

I did try running it again through the macro list.

cnc_2-1681301419302.png

Same result.

I'm running 2023 Ultimate without the updates. Don't think that matters though, the macro should run on much older versions too.

I really appreciate the help. Any other suggestions would be great.

 


Kind Regards,
Not cnc, you can call me Peabrain
0 Likes
Message 8 of 19

TK.421
Advisor
Advisor

huh... i'm at a loss! I retyped the whole thing and ran it again & i have success. run it through the macro debugger step by step and see what you get

 

try something simple to see if it runs:

 

STRING myCmd = "MESSAGE INFO 'asdfasdfasdf'"
DOCOMMAND $myCmd

the numbers never lie
0 Likes
Message 9 of 19

Beta_Librae
Advocate
Advocate

Ok, thanks for the help, I'll do that.

 

May the Force be with you!


Kind Regards,
Not cnc, you can call me Peabrain
0 Likes
Message 10 of 19

TK.421
Advisor
Advisor

i'll keep thinking too. lmk what the debugger shows you. maybe @Sean571  has an idea??


the numbers never lie
0 Likes
Message 11 of 19

Beta_Librae
Advocate
Advocate

Running it through now. Same result. It holds up on line 4.

 

cnc_0-1681305211612.png

 


Kind Regards,
Not cnc, you can call me Peabrain
0 Likes
Message 12 of 19

TK.421
Advisor
Advisor
Accepted solution

ah-HA! it does not like the space in the folder name. put an underscore or hyphen or camel case (drillingBottom) and you'll be golden

 


the numbers never lie
0 Likes
Message 13 of 19

Beta_Librae
Advocate
Advocate

OH YAA!!

That's funny. Silly thing.

 

Thanks again for your help. Greatly appreciated!


Kind Regards,
Not cnc, you can call me Peabrain
Message 14 of 19

urizenYHS3W
Advocate
Advocate

I don't know why you are using DOCOMMAND as the CREATE FOLDER command accepts variables.

0 Likes
Message 15 of 19

TK.421
Advisor
Advisor
It does? I didn’t know that. Has it always accepted variables?

the numbers never lie
0 Likes
Message 16 of 19

urizenYHS3W
Advocate
Advocate
Accepted solution

Since 2012.

 

DOCOMMAND was add in the first instance to handle any commands that didn't accept variables. But quickly the most of commands were updated to allow variables. There may be a handful left where DOCOMMAND is needed. As I recall most uses originally were to handle something like PRINT = Block.Limits.$par because people didn't know that you could do PRINT = Block.Limits[$par]

 

0 Likes
Message 17 of 19

TK.421
Advisor
Advisor
Accepted solution

Interesting, I didnt know that! @Beta_Librae  you can shorten your code using this:

STRING fName = INPUT "folder name"
CREATE FOLDER "Toolpath" $fName ACTIVATE FOLDER ${"Toolpath\"+$fName}
 
Thanks for the history lesson @urizenYHS3W !

the numbers never lie
0 Likes
Message 18 of 19

Beta_Librae
Advocate
Advocate

Good Morning!

 

Thanks for the update.

I was happy with the code that you'd provided me first. Wasn't gonna change it because I'd created for most of the folders in the explorer. The only reason I did was because it gave the ability to use spaces in the name. That was nice.

 

This was a group of macros that I'd come across on here years ago. Can't remember who posted it. It gave the ability to create and name folders. I wanted to take it a step further and have it drag unfoldered entities into that named folder. With your help I think it works pretty well, so I'd like to share it all on here now.

 

I run it from a macro button on the ribbon called "Choose"

cnc_0-1681475159529.png

 

Hopefully other think it's a cool like I do and get some use out of it.

 

 


Kind Regards,
Not cnc, you can call me Peabrain
Message 19 of 19

TK.421
Advisor
Advisor

Thanks! I'll add this to my right click menu! I didnt think to try it with spaces; glad to know that works!


the numbers never lie
0 Likes