OpenJSCAD.org
OpenJSCAD.org copied to clipboard
Params callback functions
Perhaps it's a good idea to allow callback functions or at least regexes to validate content passed through the parameters div input controls or for the ones passed by URL. This will prevent parse errors in many cases. Right now javascript errors are thrown, but it's better to allow people to define friendly messages, perhaps even things like "The wall thickness cannot be negative".
{
name: 'shape',
type: 'choice',
values: ["TRI", "SQU", "CIR"], // these are the values that will be supplied to your script
captions: ["Triangle", "Square", "Circle"], // optional, these values are shown in the listbox
// if omitted, the items in the 'values' array are used
caption: 'Shape:', // optional, displayed left of the input field
initial: "SQU", // optional, default selected value
// if omitted, the first item is selected by default
// NOTE: parameter "default" is deprecated
validate: shapeValidate
}
An example to clarify:
function validate(parameterDefinitions,paramName,paramValue){
if(paramValue == "circular") && parameterDefinitions['height'].value > 10)
status("The "+paramValue+" shape can only be used when the height is more than 10.");
}
This issue was opened in 2014, had some commits but no recent activity for past 2 years. And it's not a bug. I suggest we close it as stale.
Actually, there was also a request in discord for a way the script can produce some output aside from model. For example users are creating utility scripts where it is useful to show the user some calculation details. In current V2 throwing an error for invalid params would display the message on the screen in red.
Let’s let @ErikDeBruijn decide to close. There’s no solution yet.
I don't have a strong need for this anymore but if my request is useful to others we can keep it alive. Im fine with focus on other, more recent feature requests, though! Perhaps that is time better spent.