Heavy Logic macro, please simplify.

Heavy Logic macro, please simplify.

Eskondedo
Advocate Advocate
988 Views
2 Replies
Message 1 of 3

Heavy Logic macro, please simplify.

Eskondedo
Advocate
Advocate

Hello all,

   I have a macro that I have been developing for some time now to automate the posting process based on machine type.  We have many different machine types which require multiple different post processing requirements.  This macro was originally designed to recognize if the conditions are met then set the post processor and Setup sheets accordingly.  This thing has grown into quite the monster and I would like someone to take a look at and see if it can be simplified any.  This thing works 95% of the time but we have had some scenarios over the last few days that do not fit the conditions of the macro and when I make one change to it I get lost and mess up all the other steps, theres just so many IFs and {} I get lost with it after looking at it for hours.  This macro bounces between many other macros as well so I have attached them all, I think, if someones brave enough to tackle this beast.  Thank you in advance.

0 Likes
Accepted solutions (1)
989 Views
2 Replies
Replies (2)
Message 2 of 3

MitchPflederer
Advocate
Advocate

Hopefully this doesn't come as a shock , no one SHOULD  do this for free.

 

BUT! I will say if you download ATOM or NP++ you can indent and color and leave notes leading with "//" it will make things so much easier for you. Also if you are able to tidy things up on the post end that will help out. for example you got a post for graphite and steel, just make one post with a script that can be activated with a user defined parameter. you got multiple posts for 5 and 3 axis, make a script to detect if that's the case. From the looks of it you could probably cut your posts in half. Which i just did for  myself and I can already tell you its saving time when i need to add something new to all the posts. If you need help with that specifically let me know but this is a ton of work and like i said it shouldn't be done for free.

 

One thing I've found on this forum, people will gladly help if you ask questions for specific steps in a large macro, or ask for staring points or pointers. I hope i don't come off as a gatekeeper, i just think you'll have better luck contacting someone on here with payment in mind, or show that YOU are willing to grunt through on your own but with help. IF this helps you start your journey here's one of my macros for adding a user defined parameter to the ncprogram

 

//This macro will allow you to translate a machine work offset to a post as a user defined parameter
//in this instance "MOFFSET" and its value is what is sent to the post processor.
//To access this parameter in Autodesk manufacturing utility:
//create a user parameter called udp_MOFFSET, the prefix "udp_" is case sensitive
//drag the new userparameter "udp_yourparametername" to a desired location in the post editor where you wish your
//work offset number to be called in the case of this macro you will set the value type of the block to "String"

IF NOT entity_exists ('ncprogram','') {
MESSAGE INFO "No NC Programs Active, Activate a Program"
MACRO ABORT
}


ENTITY nc = entity('ncprogram','')
IF MEMBER($nc.UserParameters._keys, 'MOFFSET') {

STRING EDITPAR1 = "EDIT PAR " + '"' + "entity('ncprogram';" + "'$nc.Name" + "').UserParameters.MOFFSET" + '"' + "0"
DoCommand $EDITPAR1
} ELSE {
EDIT USERPAR ncprogram $nc.Name TYPE "String"
EDIT USERPAR ncprogram $nc.Name NAME "MOFFSET"
CREATE USERPAR ncprogram $nc.Name
STRING EDITPAR1 = "EDIT PAR " + '"' + "entity('ncprogram';" + "'$nc.Name" + "').UserParameters.MOFFSET" + '"' + "0"
DoCommand $EDITPAR1
}

STRING stringmsg = "Work offset is now set to Option 1"
MESSAGE INFO $stringmsg

Message 3 of 3

Anonymous
Not applicable
Accepted solution

I have to agree with Mitch, this looks like a bunch of work and it will be hard to find someone to do this for free. Anyway, i have taken a quick look at the macro and here are some tipps for you:

 

1) Use Functions

It looks like there are a few code parts that are repetitive. Take this Code an put it into an function. Look which parameters are different and pass this parameter to the function. (e.g. the "Machine Select" part)

 

2) IF … ELSE vs SWITCH

If you need more than three decicions, than use "SWITCH" instead of "IF … ELSE". It's way better to read than nested "IF … ELSE" calls. (e.g. again the "Machine Select" part)

 

3) The Right Editor

As Mitch allready mentioned, use an proper editor. I can suggest Notepad++ since there is even an Code highlighting addon for the PowerMill macro language somewhere here in the Forum. Additional this Editor can show you which "}" belongs to which "IF" and so on.

Also use Tabs to format your Code proberly to increase the readability.

 

4) Use variables for Paths

Is see there are many paths in this macro. It's better to write the path into an variable and use this instead of write the path everytime you need it. So if the path changes, you only have to chance it once in the variable.

STRING MacroPath = "C:\PowerMill\Macros\"

//Call a Macro
MACRO $MacroPath & "Run.mac"

 

I hope these tipps helps you to complete your task.