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 do i create a new unit of measure?

dave_cowdendave_cowden Member, Developers Posts: 475 ✭✭✭
I would like to create a new unit that represents a threadpitch: threads per unit length.

Question 1: How do i do that?
Question 2: If i support threads/inch and threads/meter, how do i ensure these are converted property?
Question 3: how do i link my unit of measure so that when the document defaults are inches, my new threads/inch measure is the default, while if the document units are mm, threads/mm are the default?
Question 4: ( somewhat tangential): having values with units are cool, but why are the units always converted to meter before they are passed into the body of a feature. Is there some reason for this? it would be nice in some cases to know what the unit of measure the user initially supplied ( because for example you could accept dimensionless values connected with another length dimension )
Question 5: ( also somewhat tangential): how do you properly convert units? seems like the conversion is always done for me -- but always from what the user supplied to meter. I can't see where that code is, and/or how to do other types of conversations myself.

Best Answer

Answers

  • dave_cowdendave_cowden Member, Developers Posts: 475 ✭✭✭
    Ok thanks. The main reason I was needing to ask "was the cylinder length defined in inches" was because its the best workaround for the missing ability to define the UOM that i want. In short, in this case, using the dimension the user already supplied is a way i can interpret the dimensionless threads per input, without resorting to making them type the whole unit, or without hard-coding the unit of measure, which are both inadequate.

    Just consider this a "+1" for ability to add a proper, custom UOM.  Basically, both of the solutions you suggest in #2 are not nice for the user.
  • darren_13darren_13 Member, Developers Posts: 119 PRO
    On the back of this, I really wanted to create a unit for time. This was so that I could calculate twist based upon rotational and directional velocity, without the restriction of working in just a set unit (i.e. interchangeable between seconds, minutes etc...) Without this, I have to ensure the input is in m/s and rad/s only (excluding common definitions in RPM and knots etc).

    Cheers, Darren.
  • darren_13darren_13 Member, Developers Posts: 119 PRO
    actually in documentation we have:

    Values can be multiplied and divided. The preceding values are 1 * kilogram90 * degree, and 9.81 * meter / second / second.

    Is 'second' built in? auto complete doesn't find it?

    Cheers,
    Darren
  • darren_13darren_13 Member, Developers Posts: 119 PRO
    added these lines in my script:

    /** A constant equal to 1 second. */
    annotation { "Name" : "Second", "Abbreviation" : "s" }
    export const second = { "value" : 1, "unit" : TIME_UNITS } as ValueWithUnits;

    seems to be fine, can we get this in the units.fs?

    Cheers,
    Darren
Sign In or Register to comment.