Sketcher constraint save error?

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
Post Reply
fsoro
Posts: 3
Joined: Fri Apr 19, 2019 2:19 pm

Sketcher constraint save error?

Post by fsoro »

Hi everybody,

I'm new to this forum, so please apologize if I should transgress one or the other rule concerning new posts. I have the feeling I found a bug in FreeCAD, so I would like to discuss it on the forum to make sure it is really worth reporting it in the tracker. After searching the forum and the tracker I could not find this subject (I hope I did not miss anything), that's why I'm starting this new discussion.

First this is my FreeCAD version (it should be the most recent one):

OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.17.13541 (Git)
Build type: Release
Branch: releases/FreeCAD-0-17
Hash: 9948ee4f1570df9216862a79705afb367b2c6ffb
Python version: 2.7.14
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.2.0
Locale: French/Switzerland (fr_CH)

Summary: I'm having trouble defining constraints with formula in "Sketcher". It is possible to define constraints based on formula containing named values defined in a spreadsheet, but these formula are not saved, and hence when re-opening the file, the formula will have disappeared (replaced by their last value), and hence any change in the spreadsheet values will not have any effect on the 3D geometry.

Details: Those are the steps to reproduce the problem from scratch (sorry for the rather lenghty description, but you should be able to go through it in a few minutes only). Maybe one or two keywords are not exactly as in the english version of FreeCAD (I translated them from the french version), but it should be about correct:

  1. Start FreeCAD and create a new empty document.
  2. Select the "Spreadsheet" workbench, write 3 values in 3 different cells (e.g. 500, 120 and 22). Name each of these 3 cells by richt-clicking on it --> Properties --> (tab) Alias and give them the names "Board_length", "Board_width" and "Board_thickness" respectively.
  3. Select the "Part Design" workbench, click "Create body", then "Create sketch", choose "XY_Plane", draw a new "Rectangle".
  4. Select one of the horizontal sides of the rectangle, click the "Horizontal Distance" constraint, click on the blue round icon "f(x)" and enter "Spreadsheet.Board_length" in the "Length" field.
  5. Select one of the vertical sides of the rectangle, click the "Vertical Distance" constraint, click on the blue round icon "f(x)" and enter "Spreadsheet.Board_width" in the "Length" field.
  6. Look at the constraint list (left) and double-click on the horizontal constraint that was just defined. You can see that the value of the expression that was entered is correct, but the expression itself is not there any more (this is the 1st part of the bug). So click on the blue round icon "f(x)" again and re-enter "Spreadsheet.Board_length" in the "Length" field. After closing the input dialog, a message "Failed to parse expression" is shown. Click "OK" to close the message and then "Update" (left). Now the blue round icon "f(x)" is visible in the constraint list besides the horizontal constraint, and if you re-open the constraint value window, the formula is still there.
  7. Double-click on the vertical constraint (in the list on the left) that was just defined. Here also you can see that the value of the expression that was entered is correct, but the expression itself is not there any more. So click on the blue round icon "f(x)" again and re-enter "Spreadsheet.Board_width" in the "Length" field. After closing the input dialog, the message "Failed to parse expression" is shown. Click "OK" to close the message and then "Update" (left). Now the blue round icon "f(x)" is visible in the constraint list besides the vertical constraint, and if you re-open the constraint value window, the formula is still there.
  8. Leave the "Sketcher" drawing page (click on the "Close" button up left) to go back to the "Part Design" workbench and click "Pad". In the "Length" field, click on the blue round icon "f(x)" and enter "Spreadsheet.Board_thickness". Now the board you have just drawn is visible on the 3D view.
  9. Go to the Spreadsheet and change one of the dimensions (e.g. the width from 120 to 500) and look at the result in the 3D view: it was updated correctly. You can do the same with any of the dimensions in the Spreadsheet and it will work like a charm.
  10. Save your file and exit FreeCAD.
  11. Reopen the file you just saved, double-click on "Spreadsheet" in the tree (left) and try again changing one of the dimensions in the Spreadsheet. You will notice that the 3D view is only updated correctly when you change the board thickness, but nothing happens if you change the length or the width.
  12. Double-click on the "Sketch" in the tree (left) and have a look in the constraint list (left). You will see that the value of the expression that was entered originally is still correct, but the expression itself is not there any more, hence any change in the Spreadsheet does not have any effect. So it looks like FreeCAD does not save the expressions entered in Sketcher constraints, on the other hand it does it correctly for the "Part Design" dimensions (like the thickness of the board in this example).
The attached FreeCAD file is what you should get after step 10) if you do not want to go through all steps, but then you should re-enter the formula in the constraints (see steps 6. and 7.) before going to step 9.

Thank you for any input on that matter...
Attachments
Sketcher constraint save error.FCStd
(9.57 KiB) Downloaded 51 times
jmaustpc
Veteran
Posts: 11207
Joined: Tue Jul 26, 2011 6:28 am
Location: Australia

Re: Sketcher constraint save error?

Post by jmaustpc »

Hi, your first post, welcome to FreeCAD. :)
fsoro wrote: Fri Apr 19, 2019 4:18 pm I have the feeling I found a bug in FreeCAD, so I would like to discuss it on the forum to make sure it is really worth reporting it in the tracker.
Thank you for doing so. And seriously thank you for the file, version data, and step by step instructions. :) The only thing you did not do was check in a current FreeCAD development version. We offer regular snapshots to make testing easier. We have released the next FreeCAD, 0.18 in terms of source code, we are still resolving packaging issues on some of the many platforms we support, so the web site still says 0.17 is the latest release version.

I don't remember having that bug in FreeCAD 0.17 on Linux at least, but unless you can repeat it in 0.18, it no longer matters. There is no bug in current FreeCAD at least not for me on Kubuntu Linux, I just tried all you said to confirm. But please test it on 0.18 and see if you can still repeat it and let us know if it is still there on Windows.

We have a bug submissions guidelines topic at the top of the Help forum, I have changed it now so that it is above all forums which might make it a bit easier for new comers to find. These things all seem easy when you have been here for a decade or so, but not always for new comers.


By the way, in FreeCAD 0.18, there are many sketcher updates, one of which is now the constraints change colour from default red to default orange when they are defined by an expression as in your example above.

Again, welcome here, i hope you hang around and help test 0.18. :)

Jim

OS: Ubuntu 18.04.2 LTS
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.1.
Build type: Release
Python version: 3.6.7
Qt version: 5.9.5
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/Australia (en_AU)
chrisb
Veteran
Posts: 54197
Joined: Tue Mar 17, 2015 9:14 am

Re: Sketcher constraint save error?

Post by chrisb »

Hi fsoro, welcome to the forum, and thank you for a great first post. It is best to check any error in the most recent development version, although I'm afraid it will not help much in this case.

The issue you found is due to the names you gave to the constraints. If you use expressions you are at the edge of python programming and in python these things must not have blanks in them and you should omit other fancy characters like accents etc. as well.

You cannot rename the constraints by double clicking in the 3D window, you have do so in the list to the left. There are already issues concerning the names in the tracker, please check for them.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
fsoro
Posts: 3
Joined: Fri Apr 19, 2019 2:19 pm

Re: Sketcher constraint save error?

Post by fsoro »

Thanks a lot jmaustpc and chrisb for your very detailed and useful answers.

As you can see below, I installed the latest development version (the same as jmaustpc, but under Windows 10 instead of Ubuntu). Repeating the same steps as described in my first post I get exactly the same result, but I noticed by doing so that I omitted a "small" detail in steps 4. and 5. of my description: after entering "Spreadsheet.Board_length" in the "Length" field, I actually entered a "Name (optional)" on the line below by calling it "Board length" (this time leaving an empty space between the two words). This was visible in the file attached to the first post. As chrisb correctly pointed out, this is the reason for the failure. Leaving this name field empty or entering a string with no blank does solve the problem. I naively assumed that this name field was just an information for the user (unlike the named cell "Board_length") and that it would not matter what I wrote into it. Si I'll have to be more careful in the future...

Thanks again for your help.


New version information:

OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.16110 (Git)
Build type: Release
Branch: (HEAD detached at upstream/releases/FreeCAD-0-18)
Hash: f7dccfaa909e5b9da26bf50c4a22ccca9bb10c40
Python version: 3.6.6
Qt version: 5.6.2
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: French/Switzerland (fr_CH)
chrisb
Veteran
Posts: 54197
Joined: Tue Mar 17, 2015 9:14 am

Re: Sketcher constraint save error?

Post by chrisb »

I have added this to the known issues in the wiki's Expressions.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
chrisb
Veteran
Posts: 54197
Joined: Tue Mar 17, 2015 9:14 am

Re: Sketcher constraint save error?

Post by chrisb »

Could you please check the bugtracker, if a ticket exists? I'm short of time now.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
jmaustpc
Veteran
Posts: 11207
Joined: Tue Jul 26, 2011 6:28 am
Location: Australia

Re: Sketcher constraint save error?

Post by jmaustpc »

fsoro wrote: Sat Apr 20, 2019 9:27 am entering "Spreadsheet.Board_length"
By the way, it is also possible to just directly reference a spreadsheet cell in an expression without naming it, for example "Spreadsheet.D2" will take the value from cell D2. The letter comes first and is capitalised, then the number.

Jim
chrisb
Veteran
Posts: 54197
Joined: Tue Mar 17, 2015 9:14 am

Re: Sketcher constraint save error?

Post by chrisb »

There is already an entry in the bugtracker: issue #3696, and a corresponding forum discussion.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
fsoro
Posts: 3
Joined: Fri Apr 19, 2019 2:19 pm

Re: Sketcher constraint save error?

Post by fsoro »

Thanks a lot chrisb for finding these forum and bugtracker entries. Obviously I did not search for the appropriate keywords when looking for this issue...
chrisb
Veteran
Posts: 54197
Joined: Tue Mar 17, 2015 9:14 am

Re: Sketcher constraint save error?

Post by chrisb »

This one was not too difficult after having found that it was an Expression issue. I searched all tracker's Expression issues.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
Post Reply