Expressions... again...
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Re: Expressions... again...
Your first post, welcome to FreeCAD.
You can define values in a spreadsheet in spreadsheet wb and then reference the spreadsheet cell in your expression .
You can define values in a spreadsheet in spreadsheet wb and then reference the spreadsheet cell in your expression .
Re: Expressions... again...
Thanks: yeah, I saw that, but spreadsheets are included in the fcstd file. I was wondering about macros precisely so to share values between different fcstd files...
Re: Expressions... again...
It's possible that you have a spreadsheet in one document and reference values from there in other documents.
Important note: You use a document's name to reference it from other documents. Now, when saving the document the first time you choose a certain file name and this is usually different to "Unnamed1" (or its translated version) and then the links are lost after reopening it. So, it's recommended to create first the master document, create a spreadsheet, save and close it. After reopening the name is set to the above file name. Afterwards you can still make changes and save the file but you shouldn't rename it.
Then create the further documents where you want to add expressions to. Assuming you named the master document "master" you can access an alias like this: master#Spreadsheet.Length
Unfortunately, the integrated word completion is more confusing than helping because it always gives parser errors or claims that this or that doesn't exist. So, just continue on typing. When you are finished and the content is correct the OK suddenly becomes active.
Of course, it's up to you to load the corresponding documents later when you want to change anything.
So, it's not based on macros but it's already very close to what you may want.
Edit: Add missing word
Important note: You use a document's name to reference it from other documents. Now, when saving the document the first time you choose a certain file name and this is usually different to "Unnamed1" (or its translated version) and then the links are lost after reopening it. So, it's recommended to create first the master document, create a spreadsheet, save and close it. After reopening the name is set to the above file name. Afterwards you can still make changes and save the file but you shouldn't rename it.
Then create the further documents where you want to add expressions to. Assuming you named the master document "master" you can access an alias like this: master#Spreadsheet.Length
Unfortunately, the integrated word completion is more confusing than helping because it always gives parser errors or claims that this or that doesn't exist. So, just continue on typing. When you are finished and the content is correct the OK suddenly becomes active.
Of course, it's up to you to load the corresponding documents later when you want to change anything.
So, it's not based on macros but it's already very close to what you may want.
Edit: Add missing word
- DeepSOIC
- Veteran
- Posts: 7896
- Joined: Fri Aug 29, 2014 12:45 am
- Location: used to be Saint-Petersburg, Russia
Re: Expressions... again...
I copied this to Expressions wiki page. Almost as-is.wmayer wrote:It's possible that you have a spreadsheet in one document and reference values from there in other documents.
Important note: You use a document's name to reference it from other documents. Now, when saving the document the first time you choose a certain file name and this is usually different to "Unnamed1" (or its translated version) and then the links are lost after reopening it. So, it's recommended to create first the master document, create a spreadsheet, save and close it. After reopening the name is set to the above file name. Afterwards you can still make changes and save the file but you shouldn't rename it.
Then create the further documents where you want to add expressions to. Assuming you named the master document "master" you can access an alias like this: master#Spreadsheet.Length
Unfortunately, the integrated is more confusing than helping because it always gives parser errors or claims that this or that doesn't exist. So, just continue on typing. When you are finished and the content is correct the OK suddenly becomes active.
Of course, it's up to you to load the corresponding documents later when you want to change anything.
Re: Expressions... again...
@wmayer : ah, it'd be kind of cool, indeed. Unfortunately, changes to the "main" spreadsheet are not applied automagically to all the expressions that call for it.
It will only apply if I enter the dimension definition (eg, the thickness of an extrusion) and validate it. Funny thing is it seems to then check over all the main spreadsheet values (eg, if I extrude an expressed rectangle and I've also modified the sides dimensions in the spreadsheet, manually validating the thickness value will also apply the modifications to the other dimensions). Not too practical once dimensions start being used everywhere...
Also, I noticed the autocompletion starts working if I replace the # by a dot (the latter which is replaced back by a # when I validate the expression definition). Well, that one is not a biggie anyway.
It will only apply if I enter the dimension definition (eg, the thickness of an extrusion) and validate it. Funny thing is it seems to then check over all the main spreadsheet values (eg, if I extrude an expressed rectangle and I've also modified the sides dimensions in the spreadsheet, manually validating the thickness value will also apply the modifications to the other dimensions). Not too practical once dimensions start being used everywhere...
Also, I noticed the autocompletion starts working if I replace the # by a dot (the latter which is replaced back by a # when I validate the expression definition). Well, that one is not a biggie anyway.
- DeepSOIC
- Veteran
- Posts: 7896
- Joined: Fri Aug 29, 2014 12:45 am
- Location: used to be Saint-Petersburg, Russia
Re: Expressions... again...
Did you try Macro ForceRecompute?noraef wrote: Unfortunately, changes to the "main" spreadsheet are not applied automagically to all the expressions that call for it.
Re: Expressions... again...
Thanks! It works great with that macro. I did realize the recompute icon was greyed out, but didn't search about macros to solve that.DeepSOIC wrote:Macro ForceRecompute?
Added it to the global toolbar, and it'll more than do. Thanks again!
Re: Expressions... again...
Hi Eivind.eivindkvedalen wrote: ↑Sun Aug 09, 2015 10:39 pm If you quote them with << and >>, then it works in both cases. You can't use "normal" quote characters like " or ', because that is interpreted as units.
I noticed one issue when helping an user to get a value out of dictionary into a spreadsheet cell:
https://forum.freecadweb.org/viewtopic. ... 76#p214826
If <<>> is used at the end it will get removed from the expression. Consequently after save and open operation resulting in #ERR.
Code: Select all
<<Cube>>.Length
Cube.<<Length>>
Thanks.
-
- Posts: 602
- Joined: Tue Jan 29, 2013 10:35 pm
Re: Expressions... again...
You've actually found a way to inject python code; not good, but not sure if this is a security issue or not. Anyway, this should be fixed. Dictionaries and arrays were planned, but not fully implemented. If (when) time allows, I will finish them. The syntax will then be dictionary[key] or array[index], e.g Panel014.Material.Material[Density] in the example from your thread.triplus wrote: ↑Tue Feb 13, 2018 3:39 pmHi Eivind.eivindkvedalen wrote: ↑Sun Aug 09, 2015 10:39 pm If you quote them with << and >>, then it works in both cases. You can't use "normal" quote characters like " or ', because that is interpreted as units.
I noticed one issue when helping an user to get a value out of dictionary into a spreadsheet cell:
https://forum.freecadweb.org/viewtopic. ... 76#p214826
If <<>> is used at the end it will get removed from the expression. Consequently after save and open operation resulting in #ERR.
Note the difference in persistence of <<>>. Any chance this could get fixed? Is there something else that is recommended to be done in such use case? Or are we just pushing the expressions limits to much?Code: Select all
<<Cube>>.Length Cube.<<Length>>
Thanks.
Eivind
Re: Expressions... again...
Thanks for the explanation.