Logical operators AND and OR

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!
joe.belladonna
Posts: 18
Joined: Sat Nov 09, 2019 9:18 pm

Re: Logical operators AND and OR

Post by joe.belladonna »

openBrain wrote: Tue Jan 14, 2020 12:46 pm Maybe you can try the weird tuple-based ternary:

Code: Select all

(20, 100)[1<2 and 2<3]
Same error.

Maybe it is not possible to use logical operators within FreeCADs Expression, like Willem said. :(
fmluizao
Posts: 78
Joined: Tue Nov 19, 2019 7:16 pm

Re: Logical operators AND and OR

Post by fmluizao »

openBrain wrote: Tue Jan 14, 2020 9:37 am If I'm correct, since the Big Merge it is possible to use any Python command so I would say it depends on which FreeCAD version you're running. ;)
Maybe its not possible to use python in expressions? I did a quick search in the source and find nothing about this :roll:
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Logical operators AND and OR

Post by openBrain »

joe.belladonna wrote: Tue Jan 14, 2020 12:54 pm Maybe it is not possible to use logical operators within FreeCADs Expression, like Willem said. :(
fmluizao wrote: Tue Jan 14, 2020 1:04 pm Maybe its not possible to use python in expressions? I did a quick search in the source and find nothing about this :roll:
Yep guys. Probably I mistook. Analyzing the parser file, it looks like boolean operators aren't defined....
Same file at @realthunder fork is more complete and defines said operators. Let's ask :
realthunder wrote: Sat Jun 30, 2018 12:34 pm Ping

@realthunder : is there some merge soon foreseen regarding the expression extension?
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: Logical operators AND and OR

Post by vocx »

openBrain wrote: Tue Jan 14, 2020 9:37 am If I'm correct, since the Big Merge it is possible to use any Python command...
This is not correct.

Realthunder improved the Expression Engine with the LinkMerge branch, but he did not allow arbitrary Python commands to be used.

See Core-Changes: Expression and Spreadsheet, and PR #2475: Expression syntax extension.

What you are talking about was in fact implemented, but in his own Assembly3 branch. This branch contains many changes and prototype code, but not all of that was included with the LinkMerge. See Expression and Spreadsheet.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
User avatar
Roy_043
Veteran
Posts: 8552
Joined: Thu Dec 27, 2018 12:28 pm

Re: Logical operators AND and OR

Post by Roy_043 »

Workarounds:

AND:
(1 < 2 ? 1 : 0) * (2 < 3 ? 1 : 0) == 1 ? 100 : 20

OR:
(1 < 2 ? 1 : 0) + (2 < 3 ? 1 : 0) >= 1 ? 100 : 20
realthunder
Veteran
Posts: 2190
Joined: Tue Jan 03, 2017 10:55 am

Re: Logical operators AND and OR

Post by realthunder »

openBrain wrote: Tue Jan 14, 2020 1:43 pm @realthunder : is there some merge soon foreseen regarding the expression extension?
No, not in 0.19. Maybe the next version.
Roy_043 wrote: Tue Jan 14, 2020 9:41 pm Workarounds:

AND:
(1 < 2 ? 1 : 0) * (2 < 3 ? 1 : 0) == 1 ? 100 : 20

OR:
(1 < 2 ? 1 : 0) + (2 < 3 ? 1 : 0) >= 1 ? 100 : 20
I think these are good enough workarounds.
Try Assembly3 with my custom build of FreeCAD at here.
And if you'd like to show your support, you can donate through patreon, liberapay, or paypal
joe.belladonna
Posts: 18
Joined: Sat Nov 09, 2019 9:18 pm

Re: Logical operators AND and OR

Post by joe.belladonna »

Roy_043 wrote: Tue Jan 14, 2020 9:41 pm Workarounds:
AND:
(1 < 2 ? 1 : 0) * (2 < 3 ? 1 : 0) == 1 ? 100 : 20
OR:
(1 < 2 ? 1 : 0) + (2 < 3 ? 1 : 0) >= 1 ? 100 : 20
Thanks a lot. This works perfect. :)
app4soft
Posts: 78
Joined: Sat Feb 25, 2023 6:23 pm
Location: Ukraine
Contact:

Re: Logical operators AND and OR

Post by app4soft »

Issue on adding logical operators is open on GitHub: https://github.com/FreeCAD/FreeCAD/issues/8008
joe.belladonna wrote: Wed Jan 15, 2020 9:23 am
Roy_043 wrote: Tue Jan 14, 2020 9:41 pm Workarounds:
AND:
(1 < 2 ? 1 : 0) * (2 < 3 ? 1 : 0) == 1 ? 100 : 20
OR:
(1 < 2 ? 1 : 0) + (2 < 3 ? 1 : 0) >= 1 ? 100 : 20
Thanks a lot. This works perfect. :)
As for this, there is a way to simplify calculatilon:
  • AND:
    = A < B ? (B < C ? 1:0):0
  • OR:
    = A > B ? 1:( B < C ? 1:0)
  • IF NOT THEN ELSE:
    = A != B ? 1:0(works for both numeric and text string; text should be braketed with << and >>)
  • Compare two items size:
    = A != B ? ( A > B ? 1:2):3 (1 - first bigger, 2 - second bigger, 3 - both equal)
:idea: Making 2D/3D CAD with FreeCAD, LibreCAD
Patreon: https://patreon.com/app4soft (all FREE)
Post Reply