Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- Be respectful, on topic and if you see a problem, Flag it.
If you would like to contact our Community Manager personally, feel free to send a private message or an email.
FeatureScript: opFunction with boolean for optional parameters
Hi,
I'm working on a featurescript using opFitSpline functionality.
I always use the endDerivative and startDerivative, but have added a boolean option to check/uncheck in the UI for the intermediary derivatives.
my code now looks like this:
// create a spline using the arrays if (definition.derivativeEndOnly) { opFitSpline(context, id + "fitSpline1", { "points" : pathPoints, "startDerivative" : startDerivative, "endDerivative" : endDerivative, "derivatives" : derivatives }); } else { opFitSpline(context, id + "fitSpline1", { "points" : pathPoints, "startDerivative" : startDerivative, "endDerivative" : endDerivative, }); }
is there a cleaner way to disable the "derivatives" in one opFitSpline without having two different opFitSpline functions?
leaving the derivatives map empty hasn't worked so far.
Best Answer
-
MichaelPascoe Member Posts: 1,979 PRO
See how the definition of the opFitSpline is a map { }. You can create that map beforehand then add only what you need to it, then feed it into the opFitSpline:
var splineDef = {}; splineDef.points = pathPoints; splineDef.startDerivative = startDerivative; splineDef.endDerivative = endDerivative; if (definition.derivativeEndOnly) splineDef.derivatives = derivatives; opFitSpline(context, id + "fitSpline1", splineDef);
Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! Learn How to FeatureScript Here 🔴0
Answers
See how the definition of the opFitSpline is a map { }. You can create that map beforehand then add only what you need to it, then feed it into the opFitSpline:
Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! Learn How to FeatureScript Here 🔴
Got it!
thanks Micheal!
var fitSplineMap = {
ah yes,
is cleaner than mergeMaps, but the idea is the same indeed