Spreadsheet: set true/false property in model data

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!
drmacro
Veteran
Posts: 8982
Joined: Sun Mar 02, 2014 4:35 pm

Spreadsheet: set true/false property in model data

Post by drmacro »

In the properties data tab the little blue fx icon allows you to get the value from the spreadsheet.

But, some properties are true/false and give a control that allows the user to select true or false.

Is there a way to set this property from a spread sheet?
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Spreadsheet: set true/false property in model data

Post by openBrain »

AFAIK boolean properties aren't expression aware, thus can't be directly bound to a spreadsheet value.
You can do that with a macro, but it will be neither saved in the document nor working on another installation.
drmacro
Veteran
Posts: 8982
Joined: Sun Mar 02, 2014 4:35 pm

Re: Spreadsheet: set true/false property in model data

Post by drmacro »

openBrain wrote: Fri Aug 07, 2020 5:13 pm AFAIK boolean properties aren't expression aware, thus can't be directly bound to a spreadsheet value.
You can do that with a macro, but it will be neither saved in the document nor working on another installation.
I suspected as much.
:(
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
User avatar
Roy_043
Veteran
Posts: 8550
Joined: Thu Dec 27, 2018 12:28 pm

Re: Spreadsheet: set true/false property in model data

Post by Roy_043 »

Something like this works:

Code: Select all

App.ActiveDocument.Box.setExpression('MapReversed', u'Spreadsheet.MyBool')
drmacro
Veteran
Posts: 8982
Joined: Sun Mar 02, 2014 4:35 pm

Re: Spreadsheet: set true/false property in model data

Post by drmacro »

Roy_043 wrote: Fri Aug 07, 2020 7:01 pm Something like this works:

Code: Select all

App.ActiveDocument.Box.setExpression('MapReversed', u'Spreadsheet.MyBool')
Just to be sure I understand...which can always be questionable. :D

That code would need to be run each time the spreadsheet cell was changed, correct?
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
User avatar
Roy_043
Veteran
Posts: 8550
Joined: Thu Dec 27, 2018 12:28 pm

Re: Spreadsheet: set true/false property in model data

Post by Roy_043 »

Try it!
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Spreadsheet: set true/false property in model data

Post by openBrain »

drmacro wrote: Fri Aug 07, 2020 7:06 pm That code would need to be run each time the spreadsheet cell was changed, correct?
Nope. 'setExpression' sets an expression binding inside the expression engine, which will be updated on recompute automatically. ;)

I hadn't expected this to be possible. Thx Roy, will try it also. :+1:
drmacro
Veteran
Posts: 8982
Joined: Sun Mar 02, 2014 4:35 pm

Re: Spreadsheet: set true/false property in model data

Post by drmacro »

Roy_043 wrote: Fri Aug 07, 2020 7:08 pmTry it!
Finally getting back around to this...

I tried it and it works great.

The 'u' in

Code: Select all

...u'Spreadsheet.MyBool'...
, from Python searches, appears to be unicode operator? Is that right? And any non zero value is true?

How does one do that for, say, Pad > Type which is probably an enumerated value?

I tried:

Code: Select all

App.ActiveDocument.Pad.setExpression('Type', u'Spreadsheet.PadType')
with different values 0, 1, 2, 3, 4 but that errors out when it evaluates the cell.

I also tried other than 'u' to no avail.

(I couldn't really find a good reference for the construct in Python docs (probably don't know what to search for...) and I still get cross eyed when I attempt to read the API docs for FreeCAD. :? :roll: )
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
User avatar
Roy_043
Veteran
Posts: 8550
Joined: Thu Dec 27, 2018 12:28 pm

Re: Spreadsheet: set true/false property in model data

Post by Roy_043 »

drmacro wrote: Tue Aug 11, 2020 5:40 pm appears to be unicode operator?
I think so too. But I am not sure.

Pad Type is a string value. You can easily check this:

Code: Select all

App.ActiveDocument.Pad.Type
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Spreadsheet: set true/false property in model data

Post by DeepSOIC »

BTW, it doesn't have to be done with a macro/py console. In 0.19, realthunder has added a gui method, too.
1. Right-click in property editor, "Show all"
2. Right-click on the property you want to drive with an expression, click "Expression", type the expression, done!
With this method, it is also possible to assign vectors and placements in one go.
Post Reply