Default units for expressions

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
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!
User avatar
Joel_graff
Veteran
Posts: 1949
Joined: Fri Apr 28, 2017 4:23 pm
Contact:

Default units for expressions

Post by Joel_graff »

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...
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
GeneFC
Veteran
Posts: 5373
Joined: Sat Mar 19, 2016 3:36 pm
Location: Punta Gorda, FL

Re: Default units for expressions

Post by GeneFC »

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
User avatar
papyblaise
Veteran
Posts: 8026
Joined: Thu Jun 13, 2019 4:28 pm
Location: France

Re: Default units for expressions

Post by papyblaise »

Try to type the formula (17/32)*1in
Attachments
inch.PNG
inch.PNG (12.5 KiB) Viewed 1481 times
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Default units for expressions

Post by openBrain »

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...
Knowing you can read some code, in the short version you can find the unit change threshold in this function.
User avatar
Joel_graff
Veteran
Posts: 1949
Joined: Fri Apr 28, 2017 4:23 pm
Contact:

Re: Default units for expressions

Post by Joel_graff »

GeneFC wrote: Wed Jul 08, 2020 11:42 pm US Customary is a completely ancient and virtually unused system of units. It is still "official" in the US, but really outdated.
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
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Default units for expressions

Post by openBrain »

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?
I just pointed out. ;)
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;
        }
User avatar
Joel_graff
Veteran
Posts: 1949
Joined: Fri Apr 28, 2017 4:23 pm
Contact:

Re: Default units for expressions

Post by Joel_graff »

openBrain wrote: Thu Jul 09, 2020 9:51 am I just pointed out.
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
User avatar
papyblaise
Veteran
Posts: 8026
Joined: Thu Jun 13, 2019 4:28 pm
Location: France

Re: Default units for expressions

Post by papyblaise »

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
Bance
Veteran
Posts: 4275
Joined: Wed Feb 11, 2015 3:00 pm
Location: London

Re: Default units for expressions

Post by Bance »

17/32 mm = 0.020 in
LXC
Posts: 19
Joined: Mon Sep 07, 2020 3:05 pm

Re: Default units for expressions

Post by LXC »

This is just brutal. The "thou" is not helpful. If I want a cylinder that is

Code: Select all

5/16"
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',

Code: Select all

1/2
, it shows

Code: Select all

Result: 0.5000
for a field that shows "in" as the unit. I hit enter, and presto, my

Code: Select all

.5
is now

Code: Select all

0.0197 in ( 1 / 2 )
. 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:

Code: Select all

1in/2 
to get a half inch. Nobody thinks like that. Nobody.
Post Reply