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.
If statement for parameter entry?
RyanAvery
Member Posts: 93 EDU
I'm using the parametric curve feature script with a Cartesian parameter input. For my Y value input I have this:
#t^(#tExponent) * #startingConst
where tExponent is a number and startingConst is a length (mm)
and my X and Z values are just trig functions so it gives me a helix that winds close at the begging and then gets more stretched out at the end.
this is working great.
What I now want is at some y value yd, that this function then changes to start using a different function, so it switches back to a normal helix at that yd point (not expanding anymore).
I tried this for the y input box:
(#t^(#tExponent) * #startingConst) < 150 ? (#t^(#tExponent) * #startingConst) : (#t^(#tExponent) * 2mm)Also, my t is going from 0 to 50
I have got this to work as valid input for the Y field:
#startingConst < 0.5mm ? 1mm * #t : 2mm * #t
And i've also got this to work for the Y field:
But I cant get any of these to work.
(#t^(#tExponent) * #startingConst) < 10mm ? (#t^(#tExponent) * #startingConst) : 2mm * #t
(#t^(#tExponent) * #startingConst) > 10mm ? (#t^(#tExponent) * #startingConst) : 2mm * #t
(#t^(#tExponent) * #startingConst) < 10mm ? (#t^(#tExponent) * #startingConst) : 2mm
Can I reference the current value of Y in the place that I'm inputting Y?
Any ideas?
0
Comments
I've taken a look at the code. I think that all @mahir would have to do to enable this would be to overload the `operator<` function in the same way that he has overloaded the rest of the operators to enable them to be used in that expression field.
For now, could I suggest doing two separate parametric curve features, and switching them at the boundary of your parameterization, then joining them as a composite curve? That will only work if you don't care about having a tangent discontinuity in your result. If you do care we can see if Mahir answers, or just copy the feature and try the enhancement.
Generally all of the other operators should just be abstractions of <.
> is just < called in the opposite order (assuming the two parameters have the same types). If you have two different parameter types you may need to define < for both parameter orderings.
a == b is !(a < b) && !(b < a)
a != b is a < b || b < a
a <= b is a < b && !(b < a)
a >= b is !(a < b)
We might implement them slightly differently but the point is that all you need is < for both parameter orderings and the other operators just come along.
It is mentioned in the operator overloads section of the documentation: https://cad.onshape.com/FsDoc/top-level.html
@ilya_baran may be able to shed more specific light on whether I have totally misunderstood the implementation
== and != are not overloadable -- if two things compare == in FeatureScript, they're interchangeable.
Once you overload a < b,
a <= b is !(b < a)
a > b is b < a
a >= b is !(a < b)
Unfortunately, I don't think overloading < will be enough here, because the ?: ternary operator itself is not overloadable. I would suggest doing it by writing function that depending on the value of the first argument evaluates either the second or the third.
But if I make the conditional on #t it fails, for instance this fails:
fails:
So I think the problem is referencing #t as an input to the conditional. Also, would it be possible to reference the value of Y in the input of Y's conditional? i.e.
https://cad.onshape.com/documents/578ff8b3e4b0e65410fcfda3/w/d33395f174e5b38f4abd6097/e/0c17de6a800d4aed83de417f
operator< is forced to return a boolean, which will fail since it needs to return an expression. The solution is to instead implement a function called less (it's uglier syntax but that's what it is).
The other issue is that the feature can't call these functions directly (because features are imported through namespaces). The solution I came up with is:
In the defineParameter feature. Then I could get it to work...
Didn't know you weren't a dev @mahir, you built some really nice features.