Expression dissappears from spinbox when file saved/reloaded

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!
Post Reply
MrGadget49
Posts: 27
Joined: Mon Oct 03, 2022 6:31 am

Expression dissappears from spinbox when file saved/reloaded

Post by MrGadget49 »

Problem: Expression dissappears from spinbox when file saved/reloaded
(Actually, more just for information than a problem)

I created an expression inside the spin box of a constraint. This expression used the value of another constraint as input. This other constraint was a vertical dimension defined to be a reference. The idea was to be able to drag the end of the line up or down to change the value of the constraint.

When I created my expression, I observed the following:
Screenshot from 2022-11-27 16-42-27.png
Screenshot from 2022-11-27 16-42-27.png (14.98 KiB) Viewed 495 times
I thought it was a bummer that it wasn't going to work as I wanted, but I toggled the 'Reference' property off and pressed on. This time it worked.
Screenshot from 2022-11-27 16-50-14.png
Screenshot from 2022-11-27 16-50-14.png (10.75 KiB) Viewed 495 times
At some point along the way, I decided to try toggling the 'Reference' property back on. I did and it worked, just as I had expected it to, I could drag the end of the 'Input' line up and down and the 'Output' line would be set in real time to the nearest integer below the value of 'Input'. I was very pleased.... I had cheated the system! 8-)

Unfortunately, I put this project away for a few weeks while I worked on setting up a FreeCAD system that was built from source.

When I finally got back to it, Where were all my expressions that I had so painstakingly set up? The examples above are just simple examples that I set up while trying to figure out what went wrong. It wasn't long before they also vanished.

Naturally, the first thing I suspected was my new home built version of FreeCAD... To test this I tried the old versions, all the way back to 9.1 but the expressions disappeared from them all.

I finally figured out that it was just saving and reloading the file that caused the disappearance. I also got another clue when I created another Constraint with an expression that didn't used any other Constraints. That one didn't disappear when the other ones did.

That's when it hit me.... I remembered the error message. Reference constraint from this sketch cannot be used in this expression. That was it. I toggled off the Reference property on the Input Constraint and the problem was solved.

It's kind of a shame though.... :( It was working exactly as I wanted it too.
Bance
Veteran
Posts: 4186
Joined: Wed Feb 11, 2015 3:00 pm
Location: London

Re: Expression dissappears from spinbox when file saved/reloaded

Post by Bance »

Soooooooooo you're saying you did something wrong and it didn't work? :lol: :lol: :lol:
MrGadget49
Posts: 27
Joined: Mon Oct 03, 2022 6:31 am

Re: Expression dissappears from spinbox when file saved/reloaded

Post by MrGadget49 »

Bance wrote: Sun Nov 27, 2022 11:13 pm Soooooooooo you're saying you did something wrong and it didn't work? :lol: :lol: :lol:
Ahhh YUP, that pretty much sums it up. But it worked sooo good until I I tried to save and reload it. :)

Another lesson I learned here is to have the 'Report View' on when I'm debugging things. When I did turn it on, there were some messages there about the 'Expression engine and the reference mode'

I still haven't given up on it... I have some things in mind I want that I want to use it for, and it pretty much depends on my input constraint being 'Reference'.

Jody
User avatar
adrianinsaval
Veteran
Posts: 5541
Joined: Thu Apr 05, 2018 5:15 pm

Re: Expression dissappears from spinbox when file saved/reloaded

Post by adrianinsaval »

If the constraints are truly independent and there's really no risk of a dependency loop use the hiddenref function to access that constraint in your expression:

Code: Select all

trunc(hiddenref(.Constraints.input)/1in)*1in
MrGadget49
Posts: 27
Joined: Mon Oct 03, 2022 6:31 am

Re: Expression dissappears from spinbox when file saved/reloaded

Post by MrGadget49 »

adrianinsaval wrote: Mon Nov 28, 2022 2:14 pm If the constraints are truly independent and there's really no risk of a dependency loop use the hiddenref function to access that constraint in your expression:

Code: Select all

trunc(hiddenref(.Constraints.input)/1in)*1in
Wow, thank you!

I'll give that a try as soon as I can and let you know how it works.

Jody
MrGadget49
Posts: 27
Joined: Mon Oct 03, 2022 6:31 am

Re: Expression dissappears from spinbox when file saved/reloaded

Post by MrGadget49 »

adrianinsaval wrote: Mon Nov 28, 2022 2:14 pm If the constraints are truly independent and there's really no risk of a dependency loop use the hiddenref function to access that constraint in your expression:

Code: Select all

trunc(hiddenref(.Constraints.input)/1in)*1in
Thank you! This solution works great as long as the 'input' is a reference. The first time I tried it, I forgot to toggle input back to a reference and got a "Failed to parse expression" error. When I saved and reloaded the expression disappeared as before.

When I set it up the second time I made sure input was a reference and got no errors and save/restore worked also.

Thank you again!

Jody
User avatar
adrianinsaval
Veteran
Posts: 5541
Joined: Thu Apr 05, 2018 5:15 pm

Re: Expression dissappears from spinbox when file saved/reloaded

Post by adrianinsaval »

MrGadget49 wrote: Mon Nov 28, 2022 7:15 pm Thank you! This solution works great as long as the 'input' is a reference. The first time I tried it, I forgot to toggle input back to a reference and got a "Failed to parse expression" error. When I saved and reloaded the expression disappeared as before.
For me it works even if input is not a reference constraint (see attached), perhaps there's something else going on in your case
Attachments
hiddenref_ex.FCStd
(9.85 KiB) Downloaded 7 times
MrGadget49
Posts: 27
Joined: Mon Oct 03, 2022 6:31 am

Re: Expression dissappears from spinbox when file saved/reloaded

Post by MrGadget49 »

adrianinsaval wrote: Mon Nov 28, 2022 7:33 pm For me it works even if input is not a reference constraint (see attached), perhaps there's something else going on in your case
Well, I can't explain it, but now it's working for me too. I know I didn't imagine it because I took some screenshots. I'll play with it a bit and if I can recreate it I'll post about it here.

I like your example with the circles. I was just using straight lines. The circles make a much clearer presentation.

Thanks again for your help! I hope someday I can return the favor!

Jody
Post Reply