Well I must say, what you did there was actually really interesting! Was really easy to follow too. You must have some coding experience I'd assume 🙂
Anyways, I could modify the post to do this, but I'd have to refactor the code so that instead of doing everything onOpen, it would be per section.
But this at least this example will give you a good overview. Essentially this will do what you want it to do. My example is pretty lame and simple, but you could easily expand it in so many ways.
So first off, the ManualNC operation is a parameter for the following operation. So by putting an NC operation in between operations you can disable and enable settings, or add gCode, anything really as long as you program the post processor to accept it. So for this example I used the Action Manual NC type, and used that to change the value of the global properties. In this way you could use a manual NC operation to turn on and off different user settings.

I just used a simple switch/case to interpret the results. Alternatively you could use a string like: toolSubs:true,coreProgram:true to turn it on, and toolSubs:false,coreProgram:false to turn it off.
your post would have to have something like this:
function onSection() {
if(hasParameter("action")) {
var params = getParameter("action").split(",");
for (var i=0; i<params.length; i++){
writeComment(params[i]);
param = params[i].split(":");
switch (param[0]) {
case 'toolSubs':
usingToolSubs = (param[1] == "true");
writeComment("usingToolSubs=true");
break;
case 'coreProgram':
isCoreProgram = (param[1] == "true");
writeComment("isCoreProgram=true");
break;
default:
writeComment("Error: unknown action!");
break;
}
}
}
//rest of code here
}
So it's a lot more logic on the post side, but it IS possible to do. If you would like, I can write a post that would do exactly that for you, but it would take me some time to sort all the logic out and test it fully. Though you do seem like you might know a fair bit about programming so you might even be interested in doing this yourself.
Also, if you put a manual NC operation as the last operation in your setup folder, then the parameter will apply to the onClose() function.
You also cannot put two of the same ManualNC operations before 1 operation. E.g. you cannot have 2 action NC operations, the first one will be overwritten by the second one.
Lastly, you cannot have a manual NC operation apply to the onOpen() function, which there is really no need to anyways because the user properties of the post dialogue should have any settings you want in the onOpen() function.
Though, if you wanted to get around this, you could run through the onOpen function, and in onSection, check if it's the first section, if it is the first section, you could run another function and pass it the desired parameter like this:
var firstSection = true;
onOpen() {
//code
}
onAfterOpen(params) {
//some code needing params
}
onSection () {
if (firstSection) {
if(hasParameter("action"))
onAfterOpen(getParameter("action"));
firstSection = false;
}
//rest of section
}
My only concern there is that Javascript is an asynchronous language, so you would need a callback after onAfterOpen() unless the post processor version has some voodoo magic to keep it synchronous. Honestly haven't explored that too much so don't know for sure.
Anyways, that ended up being really technical, but it should help. Let me know if you have questions!
note: I attached the edited post so you could see what changes I made - Starts on line 810.
Best,
Xander Luciano