How to handle new features in post engine
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
As new features are being added in our CAM products Inventor HSM or HSMWorks and Fusion 360 we also need to extend the API of the post processor engine accordingly. However, this causes a problem since we want to ensure that we only have a single version of a particular post configuration that everybody can use even when using an older version of the products.
The recommended way to keep supporting the old releases is to add a bit more code that would otherwise be required.
Let says we add a new function called 'myNewFunction' for the Section class.
currentSection.myNewFunction(); // will fail for old releases since myNewFunction doesnt exist in Section.
To avoid failure for old release we instead first check if the feature is available:
// if statement will be skipped if myNewFunction isn't defined
if (currentSection.myNewFunction) { // note this is not a function call - here we ask if myNewFunction exists
currentSection.myNewFunction(); // now we can call the function
}
Note that this approach works the best for function calls.
If you try the same for say properties than you can get in trouble since you cannot differentiate between non-existing property and a property that casts to false without asking JavaScript to do this explicitly.
if (currentSection.myProperty) { // bad since myProperty may not exist or could be false
currentSection.myProperty; // use property
}
Instead we check if the property is undefined like this:
if (currentSection.myProperty !== undefined) { // test if property is defined - the !== operator will check both value and type - do not confuse with the != operator which doesnt check the type
currentSection.myProperty; // use property - even if it is set to 0 or false or empty string
}
If the code gets too complicated, then the alternative is to tell the post processor that the configuration requires a newer version of the engine by setting the "minimumRevision" property. That way the user will get an explicit error message stating that the product needs to be updated to use the processor. However, I really never had a good reason to make use of this approach so far. So you should be reluctant to use this feature also.
If you want you can get the version of the post engine using the "revision" property and skip specific features in the post depending on the version the user uses.
if (revision >= 12345) { // if post engine is later than this then do something
myNewFunction();
}
The posts in our library https://cam.autodesk.com/posts/ commonly make use of the above. Here is a common example for checking if the force tool change feature is available:
var insertToolCall = isFirstSection() ||
currentSection.getForceToolChange && currentSection.getForceToolChange() ||
(tool.number != getPreviousSection().getTool().number);
If you need to check if a global function is available then the code gets a little more complicated since we now have to use the typeof operator:
if ((typeof getHeaderVersion != "function") && getHeaderVersion()) {
writeComment(localize("post version") + ": " + getHeaderVersion());
}

René Fonseca
Software Architect