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: 

Macro to create and populate a folder

18 REPLIES 18
SOLVED
Reply
Message 1 of 19
Beta_Librae
970 Views, 18 Replies

Macro to create and populate a folder

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
18 REPLIES 18
Message 2 of 19
TK.421
in reply to: Beta_Librae

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

}

--------------------------------------
Former Expert Elite Member (not enough participation in all their webinars and other "stuff", even though I beta test and regularly contribute to the betterment of the software and the PowerMill community as a whole)

the numbers never lie
Message 3 of 19
Beta_Librae
in reply to: TK.421

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
Message 4 of 19
TK.421
in reply to: Beta_Librae

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
}

 

 

--------------------------------------
Former Expert Elite Member (not enough participation in all their webinars and other "stuff", even though I beta test and regularly contribute to the betterment of the software and the PowerMill community as a whole)

the numbers never lie
Message 5 of 19
Beta_Librae
in reply to: TK.421

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
Message 6 of 19
TK.421
in reply to: Beta_Librae

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

--------------------------------------
Former Expert Elite Member (not enough participation in all their webinars and other "stuff", even though I beta test and regularly contribute to the betterment of the software and the PowerMill community as a whole)

the numbers never lie
Message 7 of 19
Beta_Librae
in reply to: TK.421

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
Message 8 of 19
TK.421
in reply to: Beta_Librae

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
--------------------------------------
Former Expert Elite Member (not enough participation in all their webinars and other "stuff", even though I beta test and regularly contribute to the betterment of the software and the PowerMill community as a whole)

the numbers never lie
Message 9 of 19
Beta_Librae
in reply to: TK.421

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

 

May the Force be with you!


Kind Regards,
Not cnc, you can call me Peabrain
Message 10 of 19
TK.421
in reply to: Beta_Librae

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

--------------------------------------
Former Expert Elite Member (not enough participation in all their webinars and other "stuff", even though I beta test and regularly contribute to the betterment of the software and the PowerMill community as a whole)

the numbers never lie
Message 11 of 19
Beta_Librae
in reply to: TK.421

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
Message 12 of 19
TK.421
in reply to: Beta_Librae

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

 

--------------------------------------
Former Expert Elite Member (not enough participation in all their webinars and other "stuff", even though I beta test and regularly contribute to the betterment of the software and the PowerMill community as a whole)

the numbers never lie
Message 13 of 19
Beta_Librae
in reply to: TK.421

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
in reply to: Beta_Librae

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

Message 15 of 19
TK.421
in reply to: urizenYHS3W

It does? I didn’t know that. Has it always accepted variables?
--------------------------------------
Former Expert Elite Member (not enough participation in all their webinars and other "stuff", even though I beta test and regularly contribute to the betterment of the software and the PowerMill community as a whole)

the numbers never lie
Message 16 of 19
urizenYHS3W
in reply to: TK.421

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]

 

Message 17 of 19
TK.421
in reply to: urizenYHS3W

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 !
--------------------------------------
Former Expert Elite Member (not enough participation in all their webinars and other "stuff", even though I beta test and regularly contribute to the betterment of the software and the PowerMill community as a whole)

the numbers never lie
Message 18 of 19
Beta_Librae
in reply to: TK.421

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
in reply to: Beta_Librae

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

--------------------------------------
Former Expert Elite Member (not enough participation in all their webinars and other "stuff", even though I beta test and regularly contribute to the betterment of the software and the PowerMill community as a whole)

the numbers never lie

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

Post to forums  

Autodesk Design & Make Report