Default units for expressions
Forum rules
and Helpful information
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help
Also, be nice to others! Read the FreeCAD code of conduct!
Also, be nice to others! Read the FreeCAD code of conduct!
- Joel_graff
- Veteran
- Posts: 1949
- Joined: Fri Apr 28, 2017 4:23 pm
- Contact:
Default units for expressions
So it seems to me that if I were to enter a formula in the expression editor for a constraint, it ought to compute the result in the default length unit specified in the document preferences...
But when I type "17/32" as an expression for a length constraint, it converts to "20.92 thou" rather than 0.53 inches, even though my document units are "US Customary" and the default length unit is inches...
But when I type "17/32" as an expression for a length constraint, it converts to "20.92 thou" rather than 0.53 inches, even though my document units are "US Customary" and the default length unit is inches...
FreeCAD Trails workbench for transportation engineering: https://www.github.com/joelgraff/freecad.trails
pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
Re: Default units for expressions
This has been discussed a few times recently, mostly by me.
US Customary is a completely ancient and virtually unused system of units. It is still "official" in the US, but really outdated.
The inperial decimal units system in FreeCAD works very well, but of course it is "decimal". You can enter fractions, but it will always output decimal.
I do not have any experience with the building unit system.
Gene
US Customary is a completely ancient and virtually unused system of units. It is still "official" in the US, but really outdated.
The inperial decimal units system in FreeCAD works very well, but of course it is "decimal". You can enter fractions, but it will always output decimal.
I do not have any experience with the building unit system.
Gene
- papyblaise
- Veteran
- Posts: 8026
- Joined: Thu Jun 13, 2019 4:28 pm
- Location: France
Re: Default units for expressions
Try to type the formula (17/32)*1in
- Attachments
-
- inch.PNG (12.5 KiB) Viewed 1481 times
Re: Default units for expressions
Knowing you can read some code, in the short version you can find the unit change threshold in this function.Joel_graff wrote: ↑Wed Jul 08, 2020 8:24 pm So it seems to me that if I were to enter a formula in the expression editor for a constraint, it ought to compute the result in the default length unit specified in the document preferences...
But when I type "17/32" as an expression for a length constraint, it converts to "20.92 thou" rather than 0.53 inches, even though my document units are "US Customary" and the default length unit is inches...
- Joel_graff
- Veteran
- Posts: 1949
- Joined: Fri Apr 28, 2017 4:23 pm
- Contact:
Re: Default units for expressions
The exact system I'm using is entirely irrelevant, here. My question is, when calculating a value in the expression engine, why doesn't it default to the system of units specified for the document?
FreeCAD Trails workbench for transportation engineering: https://www.github.com/joelgraff/freecad.trails
pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
Re: Default units for expressions
I just pointed out.Joel_graff wrote: ↑Thu Jul 09, 2020 9:31 am The exact system I'm using is entirely irrelevant, here. My question is, when calculating a value in the expression engine, why doesn't it default to the system of units specified for the document?
More specifically in your sample case :
Code: Select all
else if(UnitValue < 2.54) { // smaller then 0.1 inch -> Thou (mil)
unitString = QString::fromLatin1("thou");
factor = 0.0254;
}
- Joel_graff
- Veteran
- Posts: 1949
- Joined: Fri Apr 28, 2017 4:23 pm
- Contact:
Re: Default units for expressions
Right. I was trying to sort out what appears to have been a bug in my original posting... hadn't gotten around to replying to you yet.
What had me scratching my head was why it rendered 17/32" as 20.92 thou, which is 1/34.25 inches. Oddly, I can't reproduce that behavior now. Of course, it's possible I wasn't entering something correctly, but it was something that had happened several times, so I doubt it was incorrect data entry on my part. I ended up using the gnome default calculator because I just couldn't get the expression editor to do correct math, whether it was thousandths or inches.
On a side note, it would be nice to not have to fight the thousands conversion - no fun when I enter something in inches and FC insists that it should be thousandths... for some reason, unit notations aren't always easy to change.
Anyway, I'll keep an eye open for the issue I saw. I don't see it happening now.
FreeCAD Trails workbench for transportation engineering: https://www.github.com/joelgraff/freecad.trails
pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
- papyblaise
- Veteran
- Posts: 8026
- Joined: Thu Jun 13, 2019 4:28 pm
- Location: France
Re: Default units for expressions
You don't say us what config you use inches or mm
if you use inches I can't answher because I never use it
if you use mm , use mi formula it's run
if you use inches I can't answher because I never use it
if you use mm , use mi formula it's run
Re: Default units for expressions
17/32 mm = 0.020 in
Re: Default units for expressions
This is just brutal. The "thou" is not helpful. If I want a cylinder that is diameter, having to enter the radius takes me one step away from the dimension in its meaningful value. Then, FreeCAD converts the radius to "thou" making in meaningless. I switch my preference to Imperial to get rid of "thou". Now, when I enter, in the formula editor', , it shows for a field that shows "in" as the unit. I hit enter, and presto, my is now . There is no "under-the-hood" explanation that makes that make sense.
Units are so fundamental to modeling that they need work correctly. Forcing users to do unit-conversion gymnastics is just not acceptable.
The hackaround is to enter:to get a half inch. Nobody thinks like that. Nobody.
Code: Select all
5/16"
Code: Select all
1/2
Code: Select all
Result: 0.5000
Code: Select all
.5
Code: Select all
0.0197 in ( 1 / 2 )
Units are so fundamental to modeling that they need work correctly. Forcing users to do unit-conversion gymnastics is just not acceptable.
The hackaround is to enter:
Code: Select all
1in/2