Expression dissappears from spinbox when file saved/reloaded
Forum rules
and Helpful information
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!
Also, be nice to others! Read the FreeCAD code of conduct!
-
- Posts: 27
- Joined: Mon Oct 03, 2022 6:31 am
Expression dissappears from spinbox when file saved/reloaded
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: 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. 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!
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.
(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: 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. 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!
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.
Re: Expression dissappears from spinbox when file saved/reloaded
Soooooooooo you're saying you did something wrong and it didn't work?
-
- Posts: 27
- Joined: Mon Oct 03, 2022 6:31 am
Re: Expression dissappears from spinbox when file saved/reloaded
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
- adrianinsaval
- Veteran
- Posts: 5541
- Joined: Thu Apr 05, 2018 5:15 pm
Re: Expression dissappears from spinbox when file saved/reloaded
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
-
- Posts: 27
- Joined: Mon Oct 03, 2022 6:31 am
Re: Expression dissappears from spinbox when file saved/reloaded
Wow, thank you!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
I'll give that a try as soon as I can and let you know how it works.
Jody
-
- Posts: 27
- Joined: Mon Oct 03, 2022 6:31 am
Re: Expression dissappears from spinbox when file saved/reloaded
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.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
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
- adrianinsaval
- Veteran
- Posts: 5541
- Joined: Thu Apr 05, 2018 5:15 pm
Re: Expression dissappears from spinbox when file saved/reloaded
For me it works even if input is not a reference constraint (see attached), perhaps there's something else going on in your caseMrGadget49 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.
- Attachments
-
- hiddenref_ex.FCStd
- (9.85 KiB) Downloaded 7 times
-
- Posts: 27
- Joined: Mon Oct 03, 2022 6:31 am
Re: Expression dissappears from spinbox when file saved/reloaded
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.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
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