Spreadsheet and sketch parameters: incompatible units for + operator

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
Kunda1
Posts: 7345
Joined: Thu Jan 05, 2017 9:03 pm

Re: Spreadsheet and sketch parameters: incompatible units for + operator

Postby Kunda1 » Thu Jan 19, 2017 2:30 pm

eivindkvedalen wrote:
Syranolic wrote:Yes, I see that if the object property is normally displayed as "0,00 mm", for example, then it works.
But for the value of an offset, it doesn't. I don't many features, this is the only case I found...
Ok, the offset value should then have units attached to it (at least) in the GUI. Could you please register this in the bug tracker?

Eivind
Just linking the ticket number for issue #2671 to this forum thread.
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features
mario.silva.costa
Posts: 19
Joined: Wed May 10, 2017 8:12 pm

Re: Spreadsheet and sketch parameters: incompatible units for + operator

Postby mario.silva.costa » Wed Jul 19, 2017 8:40 am

Hi, not sure, but I think I found this same/similar problem.

1- I've created a spreadsheet, added some value with alias (val1_mm). The value has no unit, but the display unit is mm.

2- Added a Contraints.contraint1 (in mm).

3- Added a second constraint using the expression "Contraints.contraint1 + Spreadsheet.var1_mm", got the error "Incompatible unit for + operator".
freecad_invalid_units_op.png
freecad_invalid_units_op.png (34.42 KiB) Viewed 681 times
4- Added units to the value, in the spreadsheet and the no error.

5- If using operator "*", the inverse happens. No error when there is no unit, and there is an error "Incompatible unit for * operator" when there is a unit in the spreadsheet value.
freecad_valid_units_operator.png
freecad_valid_units_operator.png (33.27 KiB) Viewed 681 times
Note: Plese check attached example file, from which the images were taken.

multiplying by (1 mm) like stated below did solved the problem, its documented in:
1- https://www.freecadweb.org/wiki/Spreadsheet_Workbench; and
2- https://www.freecadweb.org/wiki/Manual: ... readsheets.

If using values from the spreasheet it works, they are unit compatible in the example I've used, which makes sense, thought might become difficult to understand in complex expressions. Note none of them has units in this example, the var1_mm has no units neither var2.
freecad_valid_units_spreadsheet.png
freecad_valid_units_spreadsheet.png (35.17 KiB) Viewed 681 times

I would suggest documentation improvement, stating these examples an solution.

OS: Ubuntu 16.04.2 LTS
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.17.11580 (Git)
Build type: None
Branch: master
Hash: aa07c777453258edf9fed304cf82bcfeb8bdea95
Python version: 2.7.12
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.1.0
Attachments
error_expression_incompatible_units_expr_sketch.fcstd
(3.95 KiB) Downloaded 8 times
eivindkvedalen
Posts: 602
Joined: Tue Jan 29, 2013 10:35 pm

Re: Spreadsheet and sketch parameters: incompatible units for + operator

Postby eivindkvedalen » Thu Jul 20, 2017 9:18 am

mario.silva.costa wrote:
Wed Jul 19, 2017 8:40 am
Hi, not sure, but I think I found this same/similar problem.
It's not the same problem; you are mixing calculations with and without units, that's why you get these results; see below.
mario.silva.costa wrote:
Wed Jul 19, 2017 8:40 am
1- I've created a spreadsheet, added some value with alias (val1_mm). The value has no unit, but the display unit is mm.
This means that the value entered does not have a unit attached to it; the display unit is only for presentation (and possibly do visual unit conversion), but does not affect the underlying representation.
mario.silva.costa wrote:
Wed Jul 19, 2017 8:40 am
2- Added a Contraints.contraint1 (in mm).
This value gets a unit attached (length in mm).
mario.silva.costa wrote:
Wed Jul 19, 2017 8:40 am
3- Added a second constraint using the expression "Contraints.contraint1 + Spreadsheet.var1_mm", got the error "Incompatible unit for + operator".
Here you try to add one number with a unit and another one without. That is not allowed; the units have to match. It's maybe easier to understand if you had two numbers with units, like mm and kg. Adding a length and a mass doesn't make much sense, right?
mario.silva.costa wrote:
Wed Jul 19, 2017 8:40 am
4- Added units to the value, in the spreadsheet and the no error.
Here the two numbers have the same units, and are thus compatible.
mario.silva.costa wrote:
Wed Jul 19, 2017 8:40 am
5- If using operator "*", the inverse happens. No error when there is no unit, and there is an error "Incompatible unit for * operator" when there is a unit in the spreadsheet value.
When you multiply, you also multiply the unit. If you have a number with unit, say 20mm, and one without, like 3, then 3 * 20mm = 60mm. If you have two numbers with unit, say 20mm and 3mm, then 20mm*3mm= 60mm^2. This is an area (mm^2), and thus cannot be used as a length constraint. However, on my not-so-recent 0.16 version I'm testing on, I don't get these expected results, but I'm not able to recreate your error message either.

To conclude, units works mostly as expected in FreeCAD, but because this has been added lately not all parts of FreeCAD handle them good enough at the moment. This is why I suggested the thread starter to register it in the tracker, so it can be fixed when time allows.

Eivind
mario.silva.costa
Posts: 19
Joined: Wed May 10, 2017 8:12 pm

Re: Spreadsheet and sketch parameters: incompatible units for + operator

Postby mario.silva.costa » Sun Jul 23, 2017 4:03 pm

Hi Eivind,

First, thanks for your reply. After researching, and reading the post properly I've came to understand it. So, the only thing I might "complain" would be some documentation improvement or some application hint in the case of error.

Let me know if I can help with documentation ...

Anyway for me it is now clear, and I'll know how to deal with it in the future.

Cheers,
mc
User avatar
Kunda1
Posts: 7345
Joined: Thu Jan 05, 2017 9:03 pm

Re: Spreadsheet and sketch parameters: incompatible units for + operator

Postby Kunda1 » Sun Jul 23, 2017 4:04 pm

@eivindkvedalen submitted PR#894 as a fix for issue #2671.
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features
User avatar
Kunda1
Posts: 7345
Joined: Thu Jan 05, 2017 9:03 pm

Re: Spreadsheet and sketch parameters: incompatible units for + operator

Postby Kunda1 » Sun Jul 23, 2017 9:11 pm

Syranolic wrote:ping
@Syranolic please change forum thread title to: "[Solved] Ticket #2671 - Spreadsheet and sketch parameters: incompatible units for + operator" Thanks!
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features