Programmatically determine whether a cell was calculated or an input

483 viewsScripting
0

This is a topic that seems to have history back to 2011 (ben g posted August 29, 2011 asking about it under \”Addressing cells programmatically\”), which asked if an \”isCalculated\” property for cells is desirable.  Digging through the scripting, I can\’t find anything akin to a isCalculated property.  Is this doable now?

The use case here is grabbing all inputs for (a) error checking and (b) rolling into different versions of a model.  Don\’t want to grab every value, just every user input-able item.

I\’ve found a work around using try-catch blocks, but a more elegant solution would be preferred.  The workaround basically \”saves\” the current value of a target cell then tries to write a different value to the item.  If it\’s calculated, it will throw an error, which will be caught if wrapped in a try-catch block.  If it\’s an input, no error, and then I write the original value back.

tgt = |Matrix3::Product4:New Time|
try{
    temp = tgt.value
    tgt.value = temp.toString() + \"a\"
    print(\"isInput\")
    tgt.value = temp
}
catch (Exception e) {
    print(\"isCalculated\")
}

Thanks!

Product Management Answered question November 3, 2023
0

Hello, there is currently no test for isCalculated to use with scripting. Kudos for your clever approach, you probably know that there are other reasons one might get an error on writing a cell so consider that in your approach. We do have some thoughts to not only make isCalculated and isMandatory, isFilled, isChanged available to scripts but to build into the product some common “app building” type of requests such as designating some cells as requiring an input, and checking if required inputs are filled or not. Stay tuned.

ksinclair Posted new comment November 6, 2023

Thank you for the reply, and especially for mentioning potential pitfalls in the workaround. I’ll stay tuned for updates!

Latest Questions