Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:
  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. 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 to strip the units from a length?

jackson_kingjackson_king OS Professional Posts: 80 PRO
Hi All,
Is there a way to strip a length of it's units so the decimal number can be used in a "ceil(#/#)" equation?

I am trying to use configs to create an expanded metal/grating generation part studio and have it working well except for getting the desired sheet size to auto size.  I am using measure distance FS to get the lengths and widths for the distance of the pattern and am trying to use that measure distance number in the ceil function to drive the instance count. In this case, ceil(#Desired_Length/#Length) or ceil(#Desired_Width/#Width).

Here's the document:
https://cad.onshape.com/documents/07f282dcddf2935fa6750b71/w/2c0dd72f79a3f141eac8e0ae/e/de6fa0c8db0a64009288fb77

Thanks in advance!
Jackson

Best Answers

Answers

  • jackson_kingjackson_king OS Professional Posts: 80 PRO
    Thanks @Jake_Rosenfeld!  I was testing things before submitting the question and never had it as a #variable/#variable, just a number/#variable.  What you said makes perfect sense and it works!
  • jackson_kingjackson_king OS Professional Posts: 80 PRO
    @Jake_Rosenfeld, is there a way to remove the units if I needed too? 
    Jackson
  • konstantin_shiriazdanovkonstantin_shiriazdanov Member Posts: 1,221 ✭✭✭✭✭
    value with units has internal structure of map type, so #length.value should give a unitless number
  • jackson_kingjackson_king OS Professional Posts: 80 PRO
    Thanks guys! It all works well now. I think my next attempt should be turning this thing into featurescript. Which should be interesting as featurescript and I don’t see eye to eye on things sometimes. 
    Jackson
  • Evan_ReeseEvan_Reese Member Posts: 2,060 PRO
    A better way of doing this is dividing by the unit.  If you want the number of inches in #length, use #length / in
    Getting the value like @konstantin_shiriazdanov proposed will always give you the length in whatever internal units we're using, which may not be what you want.
    How might I approach this in Featurescript if I don't control which units the user selects? 
    Evan Reese / Principal and Industrial Designer with Ovyl
    Website: ovyl.io
  • alnisalnis Member, Developers Posts: 447 EDU
    @Evan_Reese not sure if this is quite what you'd want, but for user inputs, could you have a length parameter and dropdown for units?
    Student at University of Washington | Get in touch: contact@alnis.dev | My personal site: https://alnis.dev | Currently an Onshape intern: asmidchens@onshape.com
  • Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646
    @Evan_Reese

    It might be easier to answer if we had additional detail about what your user inputs are and what you are trying to do with them
    Jake Rosenfeld - Modeling Team
  • Evan_ReeseEvan_Reese Member Posts: 2,060 PRO
    @Evan_Reese not sure if this is quite what you'd want, but for user inputs, could you have a length parameter and dropdown for units?
    That's a good suggestion. That would get the job done, but my intuition is instant that there's a less kludgey way... or at least one where the user doesn't have to be aware of the kludgeyness. On the other hand, the fact that there doesn't seem to be an obvious answer probably indicates a deeper issue with my whole approach.

    As a learning exercise, I'm trying to plot points to a sine wave like this:
    y = amplitude*(e^(-decay/100*x))*cos(x*frequency*degree)+amplitude;
    Amplitude, frequency, and x are all valueWithUnits (lengths), and I think that's what I want, but cos() wants an angle, not the unit mashup I have. Should I change all of them to just values? if so, how do I get the right units without the user having to think about it?
    Evan Reese / Principal and Industrial Designer with Ovyl
    Website: ovyl.io
  • Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646
    @Evan_Reese

    Issues with units usually indicate an issue with the equation itself; if you were solving this equation on paper for a given x value, you would expect all the units to cancel appropriately to give you the right answer.  So to tackle it in parts:

    (e^(-decay/100*x)): this is a scale factor, and should be unitless.  Since `x` is a distance, I would expect `decay` to be in distance units, describing how far along the x-axis you want this scale factor to be (e^(-1/100))

    cos(x*frequency*degree): As this is right now, I would expect "frequency" to be in inverse distance units (i.e. "1 / distance"), and that (frequency * degree) forms a statement of "for every (1 / frequency), the cos wave changes by one degree".  I do not think this is the intention, it seems that you are having the user supply "frequency" meaning "how frequently does the cos wave pass through a full cycle".  In which case the correct equation would be: cos(x*(360*degree/frequency)); and you will see here that that the units just fall out correctly, without having to strip anything of its units.
    Jake Rosenfeld - Modeling Team
  • Evan_ReeseEvan_Reese Member Posts: 2,060 PRO
    @Evan_Reese

    Issues with units usually indicate an issue with the equation itself; if you were solving this equation on paper for a given x value, you would expect all the units to cancel appropriately to give you the right answer.  So to tackle it in parts:

    (e^(-decay/100*x)): this is a scale factor, and should be unitless.  Since `x` is a distance, I would expect `decay` to be in distance units, describing how far along the x-axis you want this scale factor to be (e^(-1/100))

    cos(x*frequency*degree): As this is right now, I would expect "frequency" to be in inverse distance units (i.e. "1 / distance"), and that (frequency * degree) forms a statement of "for every (1 / frequency), the cos wave changes by one degree".  I do not think this is the intention, it seems that you are having the user supply "frequency" meaning "how frequently does the cos wave pass through a full cycle".  In which case the correct equation would be: cos(x*(360*degree/frequency)); and you will see here that that the units just fall out correctly, without having to strip anything of its units.
    At least I was right about being wrong :D. my algebra has never been the best. Thanks for the rundown, I'll self-educate more.
    Evan Reese / Principal and Industrial Designer with Ovyl
    Website: ovyl.io
Sign In or Register to comment.