How to use position values in expressions?

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!
BassMati
Posts: 82
Joined: Sat Oct 06, 2018 11:39 am

How to use position values in expressions?

Postby BassMati » Mon Aug 19, 2019 9:21 pm

Hi folks,

I would like to define the position of Body2.Placement.Position.z in an expression, such as

Body1.Placement.Position.z + 123

but I cannot figure out (documentation, forum, google) the correct syntax. Interestingly, something like Pad1.Length does work in the formula… I could use a named spreadsheet cell to define the Body1 z position, and use that variable in both Body1 and Body2.Placement.Position.z, but I would rather use the z variable directly. Can someone give a hint?

Thanks in advance
Bass Mati
chrisb
Posts: 28029
Joined: Tue Mar 17, 2015 9:14 am

Re: How to use position values in expressions?

Postby chrisb » Mon Aug 19, 2019 11:55 pm

BassMati wrote:
Mon Aug 19, 2019 9:21 pm
it is Body.Placement.Base.x+123mm.
If you type "Body.Pla" in an expression aware field you see this in the autocompletion list.

Edits in blue.
kisolre
Posts: 2269
Joined: Wed Nov 21, 2018 1:13 pm

Re: How to use position values in expressions?

Postby kisolre » Tue Aug 20, 2019 7:36 am

chrisb wrote:
Mon Aug 19, 2019 11:55 pm
it is Body.Placement.Base.x+123.
Correction: Body.Placement.Base.x+123mm.
It will not accept unitless 123.
chrisb
Posts: 28029
Joined: Tue Mar 17, 2015 9:14 am

Re: How to use position values in expressions?

Postby chrisb » Tue Aug 20, 2019 12:46 pm

You are right and I have edited my post above - thanks.
BassMati
Posts: 82
Joined: Sat Oct 06, 2018 11:39 am

Re: How to use position values in expressions?

Postby BassMati » Tue Aug 20, 2019 1:26 pm

Thanks! Base was the missing member that carries the coordinates, so Body1.Placement.Base.z returns the desired value.

Autocompletion does not suggest the "base" member bevor the final letter e (on a Windows machine with realthunder's Assembly3 build), that's the reason I was stuck. Unit input was not the problem, I am aware of that.
Thanks a lot!
openBrain
Posts: 4623
Joined: Fri Nov 09, 2018 5:38 pm

Re: How to use position values in expressions?

Postby openBrain » Tue Aug 20, 2019 2:52 pm

My advice is to explore this in the Python console.
You can use "App.ActiveDocument." then continue with the usual expression. Auto completion is far better in the console. ;)
chrisb
Posts: 28029
Joined: Tue Mar 17, 2015 9:14 am

Re: How to use position values in expressions?

Postby chrisb » Tue Aug 20, 2019 4:36 pm

BassMati wrote:
Tue Aug 20, 2019 1:26 pm
Autocompletion does not suggest the "base" member bevor the final letter e (on a Windows machine with realthunder's Assembly3 build), that's the reason I was stuck. Unit input was not the problem, I am aware of that.
Thanks a lot!
Could you please retest this with a current 0.19? Here it is never an issue with autocompletion.

OS: macOS High Sierra (10.13)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.17681 (Git)
Build type: Release
Branch: master
Hash: e94af7ff5e873f263cac51d7d47df68eca183250
Python version: 3.7.3
Qt version: 5.9.7
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/Germany (en_DE)
BassMati
Posts: 82
Joined: Sat Oct 06, 2018 11:39 am

Re: How to use position values in expressions?

Postby BassMati » Mon Sep 09, 2019 12:49 pm

openBrain wrote:
Tue Aug 20, 2019 2:52 pm
Auto completion is far better in the console. ;)
I'll try that. Seems to be a good idea.
BassMati
Posts: 82
Joined: Sat Oct 06, 2018 11:39 am

Re: How to use position values in expressions?

Postby BassMati » Mon Sep 09, 2019 12:57 pm

chrisb wrote:
Tue Aug 20, 2019 4:36 pm
Could you please retest this with a current 0.19? Here it is never an issue with autocompletion.
I'll try to verify that. May take some time, I have to reorganize my model because recompute duration is exploding somewhat.

Currently I'm evaluating Realthunder's Assembly3 build. It's experimental and has a few problems here and there, so I guess/hope autocompletion problems appear only there.
BassMati
Posts: 82
Joined: Sat Oct 06, 2018 11:39 am

Re: How to use position values in expressions?

Postby BassMati » Mon Sep 09, 2019 2:07 pm

@chrisb: Autocomplete works in mainstream 0.19, so it is an Assembly3-related issue. Only "complaint" is, in a formula editor dialog box, I am used to get a complete list of members when I enter an object name, followed by a dot (like "Body001."). In freecad, I need to know at least the first letter of the member name to get a pick list… But I can live with that.