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.
How do you bring numbers in as a precondition
ron_moreland
Member Posts: 90 ✭✭
I want to bring a simple unitless number in as a multiplier. I also want to restrict the range and assign a default value.
annotation { "Name" : "Scale" } isLength(definition.scale, { (inch) : [1, 1.059463, 1.07463] } as LengthBoundSpec);this works, but I think I want this:
annotation { "Name" : "Scale" } isLength(definition.scale, { (unitless) : [1, 1.059463, 1.07463] } as LengthBoundSpec);which doesn't. Should I bring it in as an "inch" then divide by"inch" later?
Tagged:
0
Best Answer
-
ilya_baran Onshape Employees, Developers, HDM Posts: 1,206annotation { "Name" : "My Number" }isReal(definition.myCount, { (unitless) : [0, 1, 6] } as RealBoundSpec);Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc5
Answers
Thanks
EXAMPLE
Everything is queries. Not an array in sight, except "sides[0]", and what the heck is it doing there? For someone with my background, it's very hard to get my head around. It's difficult to know if I'm passing the correct parameters and hard to decipher what came back.
Here's another example. I want to use "canBePlane()". Here's the documentation:
canBePlane (value) predicate
Typecheck for
Plane
What is "value"? I think I've passed it a plane, or a planar face, but it always fails. Should it be a query? a map? either?
I know featurescript is incredibly powerful, but where I am, I spend most of my time trying to determine if what I'm asking for and getting are correct. Very little time is spent on data manipulation.
I saw your discussions in this thread and the other thread, and thought it may be useful to clear up some stuff about types in FeatureScript.
For every type <X> in FeatureScript there is a canBe<X>() method, which is the typecheck for that type. You should never need to actually call the canBe<X>() method, its just a construction for declaring types.
Some examples of types in FeatureScript:
- Query
- Vector
- Matrix
- Transform
- Line
- Plane
- BoundingBox
- ValueWithUnits (length, angle, volume, etc)
Here's an example:If you look in the documentation, you'll see that evPlane returns a 'Plane':
https://cad.onshape.com/FsDoc/library.html#evPlane-Context-map
And that a 'Plane' is just a special map that contains the mathematical information about a plane in 3D space:
https://cad.onshape.com/FsDoc/library.html#Plane
You can use these 'is <X>' predicates to check whether a variable that you have is of the type that you expect, but you can't use 'is Line' to check if a 'Query' references a linear edge (because 'Query is Query').
You could use 'evLine()' to both check if the edge is linear, and find out the mathematical information about the line:
https://cad.onshape.com/FsDoc/library.html#evLine-Context-map
https://cad.onshape.com/FsDoc/library.html#Line
Or, you could just make sure the user passes linear edges into your feature:
Hope this isn't just adding confusion. Let us know if you still have questions.
Thanks.
"this is a string" as Plane
If you monitor a part studio that uses that feature, you'll be warned about a typecheck failure.
I may be misunderstanding your question, but 'varX is typeX' cannot be used to check geometry types of queries, it can only be used to check what type a FeatureScript variable is.
To answer the second part of your question in detail, you can't have 'evX() is X' without declaring 'canBeX()'.
Here's an example:
You fundamentally can't have 'Vehicle's without 'canBeVehicle()'. You can now check if a variable is a Vehicle with 'someVariable is Vehicle', but only because you wrote out its definition using the 'canBe' predicate.
'canBeVehicle()' is a construction of FeatureScript, and is used internally by the system to make sure that things declared 'as Vehicle' actually qualify for this role.
Another example:
In short: you should never need to call 'canBeX()' yourself. It's used by the system to declare variable types.
Coming full circle: It's not really useful to check whether something 'is Plane' or 'is Line' or 'canBePlane' or 'canBeLine'. If you end up with something of these variable types, you'll already know that you have them (because you would have had to call 'evPlane()' or 'evLine()' or similar to get those). To check if some piece of geometry is a plane, you can do: