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: 

Project Save Macro

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
Anonymous
2085 Views, 9 Replies

Project Save Macro

Hello Im working on a macro to Save my project into a designated directory on my PC based on the Model Name in PMill, The following macro gets me 99% of the way there I just have an extra "}" Character at the end of the save path that I cannot figure out why it is even there in the first place. Maybe its just something simple I have overlooked.

 

If my Model Name was 6H680 the location comes out a

'C:/Users/jroth/Desktop/Powermill Projects/7XXXX/72XXX/72028/72028 HSG PLT}}}'

 

 

STRING LIST models = {}
FOREACH md IN FOLDER('model') {
IF position($md.name, "Planes") == -1 {
INT k = add_last($models, $md.name)
}
}
STRING ModelName = ''
IF size($models) == 1 {
$ModelName = $models[0]
} ELSE {
$ModelName = INPUT ENTITY MODEL "Choose model"
}

//Disect Model Name
STRING PATH1 = Substring("$ModelName", 0, 1)
STRING PATH2 = Substring("$ModelName", 1, 1)
STRING PATH3 = Substring("$ModelName", 0, 5)
STRING X4 = "XXXX"
STRING X3 = "XXX"

//Output path
STRING PATH0 = "C:\Users\jroth\Desktop\Powermill Projects\$PATH1+$X4\$PATH1+$PATH2+$X3\$PATH3\$ModelName"
STRING SaveAs = $PATH0

//if project already exist, just save it.
IF dir_exists($saveas) {
PROJECT SAVE


//if project doesn't exist, save it as modelname in model location
} ELSE {
BOOL NameCheck = FALSE
STRING $Question = "Is this path and modelname correct?" +CRLF+ $saveas
$NameCheck = QUERY $Question
IF $NameCheck {
PROJECT SAVE AS $saveas
STRING $Message = "Project has been saved in" +CRLF+ $saveas
MESSAGE INFO $Message
}
}

 

9 REPLIES 9
Message 2 of 10
rafael.sansao
in reply to: Anonymous

Replace line:

STRING PATH0 = "C:\Users\jroth\Desktop\Powermill Projects\$PATH1+$X4\$PATH1+$PATH2+$X3\$PATH3\$ModelName"

By:

STRING PATH0 = "C:\Users\jroth\Desktop\Powermill Projects\" + $PATH1 + $X4 + "\" + $PATH1 + $PATH2 + $X3 + "\" + $PATH3 + "\" + $ModelName

Rafael Sansão

EESignature

Message 3 of 10
Anonymous
in reply to: rafael.sansao

Thanks It works, just sort of curious to why it works. I'm pretty new to writing macros like this, and if no one already can tell I do work with zakary aka EDM on this forum, both of us are trying to learn to write / understand powemill macros

Message 4 of 10
Scoobyvroom
in reply to: Anonymous

One thing that helped me immensely was being able to see what was going on in the background. If you right mouse click on the macro in the explorer, you can select the debug option. This pops open anther window, and allows you to step through the macro line by line. It also gives you another Window that will show you the value of all variables and strings that are in use.

Message 5 of 10
TK.421
in reply to: Scoobyvroom

i learned the same way that @Scoobyvroom mentioned, as well as just posting stuff here and getting help from some of the expert users and the old Delcam staffers who used to frequent the old forum often

--------------------------------------
the numbers never lie
Message 6 of 10
Anonymous
in reply to: TK.421

This Macro works great but I want to create a few If Else statements in here. I am trying to get the macro to decide which folder to place the file in. For example I have folders for each specific job. 6XXXX, 6AXXX, 6BXXX and so on. Right now if my model name is 6H809 this macro below will create only a 6XXXX folder and even if the part number is 6HXXX. It creates a directory like: 

C:\Users\zwalker\Desktop\PROGRAMMED ELECTRODES\6XXXX\6H809\B Electrodes.  

 

And I want it to create a directory like this:

C:\Users\zwalker\Desktop\PROGRAMMED ELECTRODES\6HXXX\6H809\B Electrodes. 

 

In the past I have just simply replaced STRING X4 = "XXXX" with STRING X4 = "AXXX"  or STRING X4 = "BXXX" but I would rather not have a bunch of the same macro buttons on my ribbon when I could have one macro that does the deciding for me.

 

I want to be able to have PMILL Create a folder or if it exists already just get into the correct folder to create the correct save path.  I will post pictures below to hopefully better describe the scenario. I am not sure what terms I need to use to make this macro look at the line 16 (below) and have the macro determine whether this is an A, B, C, D or just another number. 

 

STRING PATH2 = Substring("$ModelName", 1, 1)

 

Hopefully this makes sense to you as to what I am trying to accomplish. Thank you!

 MacroHelp1.JPG 

 

STRING LIST models = {}
FOREACH md IN FOLDER('model') {
     IF position($md.name, "Planes") == -1 {
          INT k = add_last($models, $md.name)
     }
}
STRING ModelName = ''
IF size($models) == 1 {
     $ModelName = $models[0]
} ELSE {
     $ModelName = INPUT ENTITY MODEL "Choose model"
}

//Disect Model Name
STRING PATH1 = Substring("$ModelName", 0, 1)
STRING PATH2 = Substring("$ModelName", 1, 1)
STRING PATH3 = Substring("$ModelName", 0, 5)
STRING PATH4 = Substring("$ModelName", 6, 1)
STRING X4 = "XXXX"
STRING X3 = "XXX"
STRING ELECTRODE = $PATH4 + " Electrodes"

//Output path
STRING PATH0 = "C:\Users\zwalker\Desktop\Programmed Electrodes\" + $PATH1 + $X4 + "\" + $PATH3 + "\" + $ELECTRODE + "\" + $ModelName
STRING SaveAs = $PATH0

//if project already exist, just save it.
IF dir_exists($saveas) { 
PROJECT SAVE


//if project doesn't exist, save it as modelname in model location
} ELSE { 
		BOOL NameCheck = FALSE
		STRING $Question = "Is this path and modelname correct?" +CRLF+ $saveas
		$NameCheck = QUERY $Question
		IF $NameCheck {
		PROJECT SAVE AS $saveas 
		STRING $Message = "Project has been saved in" +CRLF+ $saveas
		MESSAGE INFO $Message
		}
	}

 

Tags (2)
Message 7 of 10
Anonymous
in reply to: Anonymous

It seems as if I have solved my own problem, all I had to do was:

 

ADD 

STRING PATH5 = Substring("$ModelName", 0, 1)

Then Replace

 

STRING PATH1 = Substring("$ModelName", 0, 1)

With

STRING PATH1 = Substring("$ModelName", 0, 2)

and then just take out one X on:

STRING X4 = "XXX"

 Lastly add in STRING X5

STRING X5 = "XXXX"

now my new output path Looks like this.

//Output path
STRING PATH0 = "C:\Users\zwalker\Desktop\Programmed Electrodes\" + $PATH5 + $X5 + "\" + $PATH1 + $X4 + "\" + $PATH3 + "\" + $ELECTRODE + "\" + $ModelName
STRING SaveAs = $PATH0

 

 

Sometimes the further in depth you think about things the harder it may seem when in reality the solution is very simple. This has happened to me a few times now. although I am still pretty new to the macro language. Hopefully this will help someone else with the same file save directory in the future! I will post the entire code below to show the full macro. Refer to my post above to note changes. And thanks again everyone else for the help.

 

STRING LIST models = {}
FOREACH md IN FOLDER('model') {
     IF position($md.name, "Planes") == -1 {
          INT k = add_last($models, $md.name)
     }
}
STRING ModelName = ''
IF size($models) == 1 {
     $ModelName = $models[0]
} ELSE {
     $ModelName = INPUT ENTITY MODEL "Choose model"
}

//Disect Model Name
STRING PATH5 = Substring("$ModelName", 0, 1)
STRING PATH1 = Substring("$ModelName", 0, 2)
STRING PATH2 = Substring("$ModelName", 1, 1)
STRING PATH3 = Substring("$ModelName", 0, 5)
STRING PATH4 = Substring("$ModelName", 6, 1)
STRING X5 = "XXXX"
STRING X4 = "XXX"
STRING X3 = "XXX"
STRING ELECTRODE = $PATH4 + " Electrodes"

//Output path
STRING PATH0 = "C:\Users\mcormier\Desktop\Programmed Electrodes\" + $PATH5 + $X5 + "\" + $PATH1 + $X4 + "\" + $PATH3 + "\" + $ELECTRODE + "\" + $ModelName
STRING SaveAs = $PATH0

//if project already exist, just save it.
IF dir_exists($saveas) { 
PROJECT SAVE


//if project doesn't exist, save it as modelname in model location
} ELSE { 
		BOOL NameCheck = FALSE
		STRING $Question = "Is this path and modelname correct?" +CRLF+ $saveas
		$NameCheck = QUERY $Question
		IF $NameCheck {
		PROJECT SAVE AS $saveas 
		STRING $Message = "Project has been saved in" +CRLF+ $saveas
		MESSAGE INFO $Message
		}
	}

 

 

Message 8 of 10
mayankpatel5523
in reply to: Anonymous

Which language you use for this code

Message 9 of 10
mayankpatel5523
in reply to: Anonymous

I want to create a macro for copy or move file in system dictionary 

Message 10 of 10
nguyenthinhvt95
in reply to: Anonymous

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report