Spreadsheet unit bug

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
spontarelliam
Posts: 27
Joined: Mon Aug 26, 2019 4:54 pm

Spreadsheet unit bug

Post by spontarelliam »

When using the spreadsheet workbench to apply referenced dimensions, the values pulled from the spreadsheet are assumed to be millimeters, regardless of unit selection.

For example, create a spreadsheet with a single value of 12, set it's alias to 'width'. Sketch a rectangle and set height to 12 inches, set width to Spreadsheet.width. This will create a very narrow rectangle rather than the expected square because the 12 is interpreted as 12 millimeters or .472 inches.

Any suggestions on how we can fix this?

freecad_spreadsheet_unit_bug_5-fast_optimized.GIF
freecad_spreadsheet_unit_bug_5-fast_optimized.GIF (631.77 KiB) Viewed 3453 times

FreeCAD version 0.20 build 25176.
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Spreadsheet unit bug

Post by openBrain »

Enter correctly the quantity in the spreadsheet : '12 in'
spontarelliam
Posts: 27
Joined: Mon Aug 26, 2019 4:54 pm

Re: Spreadsheet unit bug

Post by spontarelliam »

Ah how embarrassing, that fixed it. I guess I'm not used to putting text and numbers in the same spreadsheet cell.

This seems less important now, but I still wonder if it's worth chasing down the reason that the Dimension Reference field renders "in" (see the gif) but applies mm. Clearly it confused me, but I wonder if I'm not alone.
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Spreadsheet unit bug

Post by openBrain »

spontarelliam wrote: Thu Nov 25, 2021 5:43 pm Ah how embarrassing, that fixed it. I guess I'm not used to putting text and numbers in the same spreadsheet cell.
It's called 'quantity' here (number + unit). It's pretty powerful but indeed user has to learn dealing with this. ;)
This seems less important now, but I still wonder if it's worth chasing down the reason that the Dimension Reference field renders "in" (see the gif) but applies mm. Clearly it confused me, but I wonder if I'm not alone.
I don't see what you're talking about in your GIF. :?
spontarelliam
Posts: 27
Joined: Mon Aug 26, 2019 4:54 pm

Re: Spreadsheet unit bug

Post by spontarelliam »

When I click the Name field, "in" appears after the 12, as though it understands those are my default units.

freecad_spreadsheet_unit_bug-short_compressed-optimized.GIF
freecad_spreadsheet_unit_bug-short_compressed-optimized.GIF (757.03 KiB) Viewed 3341 times
User avatar
adrianinsaval
Veteran
Posts: 5541
Joined: Thu Apr 05, 2018 5:15 pm

Re: Spreadsheet unit bug

Post by adrianinsaval »

oh yeah that seems like a bug it should either display mm or convert the value to in . This is before adding the unit in the spreadsheet cell right?
spontarelliam
Posts: 27
Joined: Mon Aug 26, 2019 4:54 pm

Re: Spreadsheet unit bug

Post by spontarelliam »

That's correct, this is what it looks like when units are not specified in the spreadsheet.
User avatar
onekk
Veteran
Posts: 6146
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Spreadsheet unit bug

Post by onekk »

If you didn't specify units, maybe it is assumed they are default FreeCAD units.

FreeCAD is a metric CAD, imperial are only translations of the internal mm unit used by the "3d modeling engine".

Using "old fashioned measures" is not too scientific, (fortunately imperial people have standardized thing from the times when on every king change foot mesure was also changed). :D

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Spreadsheet unit bug

Post by openBrain »

I had a look at the bug above, and that's actually not so easy :
* This is a nice intention overall that when user set no unit in the "Value", FreeCAD adds the unit automatically (especially when it's a direct value, not an expression)
* This is a very cool thing that a unitless value in spreadsheet is always considered in mm, whatever is your unit setting.If it wasn't the case, just imagine the mess it would be if you're in millimeters and open a file created by someone using inches...

ATM I think the ideal solution would be to trigger an expression computation when leaving the expression dialog, but I have not much time right now to look at this.
I someone want to try, you're very welcome. :)
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Spreadsheet unit bug

Post by openBrain »

ATM I implemented the simple solution of always adding "mm" after a unitless expression : https://github.com/FreeCAD/FreeCAD/pull/5221

Will continue searching for immediate expression computation later when more time available.
Post Reply