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.
In Feature Script: Zero need ValueWithUnits when sketching somethings?
yvan_bourassa
Member Posts: 2 ✭✭
Hello Everyone,
I try to sketch circle like this:
I try to sketch circle like this:
precondition
{
annotation { "Name" : "Ring Diameter" }
annotation { "Name" : "Ring Diameter" }
isLength(definition.myRingDiameter, { (millimeter) : [0, 120, 500] } as LengthBoundSpec);
}
var D = definition.myRingDiameter;
var D = definition.myRingDiameter;
skCircle(sketchPINS, "circle1", {
"center" : vector(0 , D/2),
"radius" : definition.myPinDiameter/2
});
this code fail! Precondition of skCircle failed (value.center is undefined || is2dPoint(value.center))
var D = definition.myRingDiameter;
Someone have an explanation, why Zero need units?
this code fail! Precondition of skCircle failed (value.center is undefined || is2dPoint(value.center))
var D = definition.myRingDiameter;
skCircle(sketchPINS, "circle1", {
"center" : vector(0 * millimeter, D/2),
"radius" : definition.myPinDiameter/2
});
this code pass!Someone have an explanation, why Zero need units?
Tagged:
0
Best Answers
-
mahir Member, Developers Posts: 1,309 ✭✭✭✭✭It needs units because it's a coordinate. X, Y, and Z coordinates are generally nonzero, i.e. the nonzero numerical space is a lot larger than the zero space. So it's more straightforward to just expect them to have units. Otherwise you'd have to program an extra "If" into every function just to check if a value is zero and apply a default unit.
Bottom line is featurescript won't let you be lazy. Variables that generally need units (distance, coordinates, angles, mass, etc) should be explicitly declared with units. It'll keep you out of trouble in the long run. It's no different than declaring a double or integer variable type. Zero is zero right? No, not really. An integer zero doesn't function like a double zero.3
Answers
Bottom line is featurescript won't let you be lazy. Variables that generally need units (distance, coordinates, angles, mass, etc) should be explicitly declared with units. It'll keep you out of trouble in the long run. It's no different than declaring a double or integer variable type. Zero is zero right? No, not really. An integer zero doesn't function like a double zero.
This is essentially a data correctness check: even though zero of anything seems like it should be just zero, units are meant to signify *what physical quantity* your datum is. I'd expect that passing 0 degrees to something that expects length would fail, because that input can change. Being too smart about converting one type of zero to another might lead to your feature silently succeeding with a zero input of the wrong type but then mysteriously failing when that changes.
Edit: Mahir beat me to it.