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.
Sorry for the beginner's question, but I need to mix length units and I do not know how...
jacques_blain
Member Posts: 2 ✭✭
i.e. I would like to say
const VNSpindleBearingOD is string = "SpindleBearingOD";
const SpindleBearingOD is number = 3.15; // this value is in inch
const VNSpindleBearingOD is string = "SpindleBearingID";
const SpindleBearingID is number = 80; // This value is in mm
verifyVariableName (VNSpindleBearingOD);
setVariable(context, VNBearingSpindleOD, SpindleBearingOD); // By default my project is in inch so this will be OK
verifyVariableName (VNSpindleBearingID);
setVariable(context, VNBearingSpindleID, SpindleBearingID); // !!!>>> But this will be interpreted as inch, instead of mm
Any help will be greatly appreciated
const VNSpindleBearingOD is string = "SpindleBearingOD";
const SpindleBearingOD is number = 3.15; // this value is in inch
const VNSpindleBearingOD is string = "SpindleBearingID";
const SpindleBearingID is number = 80; // This value is in mm
verifyVariableName (VNSpindleBearingOD);
setVariable(context, VNBearingSpindleOD, SpindleBearingOD); // By default my project is in inch so this will be OK
verifyVariableName (VNSpindleBearingID);
setVariable(context, VNBearingSpindleID, SpindleBearingID); // !!!>>> But this will be interpreted as inch, instead of mm
Any help will be greatly appreciated
Tagged:
0
Best Answer
-
ilya_baran Onshape Employees, Developers, HDM Posts: 1,211The way to mix units in FS is to use *lengths* (and other quantities with units, collectively called ValueWithUnits) instead of numbers (which are unitless).
So if you write
const SpindleBearingOD is ValueWithUnits = 3.15 * inch;
const SpindleBearingID is ValueWithUnits = 80 * millimeter;
they will be interpreted as the correct lengths. You can also add them, subtract them, etc. Keep in mind that a length remembers that it's a length but not what units it was originally defined with (so you get *exactly* same value from 2.54 * centimeter as from inch).Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc5
Answers
So if you write
const SpindleBearingOD is ValueWithUnits = 3.15 * inch;
const SpindleBearingID is ValueWithUnits = 80 * millimeter;
they will be interpreted as the correct lengths. You can also add them, subtract them, etc. Keep in mind that a length remembers that it's a length but not what units it was originally defined with (so you get *exactly* same value from 2.54 * centimeter as from inch).