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: 98
Joined: Sat Oct 06, 2018 11:39 am
Location: Germany Bielefeld
Contact:

How to use position values in expressions?

Post by BassMati »

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
Veteran
Posts: 53930
Joined: Tue Mar 17, 2015 9:14 am

Re: How to use position values in expressions?

Post by chrisb »

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.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
kisolre
Veteran
Posts: 4164
Joined: Wed Nov 21, 2018 1:13 pm

Re: How to use position values in expressions?

Post by kisolre »

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
Veteran
Posts: 53930
Joined: Tue Mar 17, 2015 9:14 am

Re: How to use position values in expressions?

Post by chrisb »

You are right and I have edited my post above - thanks.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
BassMati
Posts: 98
Joined: Sat Oct 06, 2018 11:39 am
Location: Germany Bielefeld
Contact:

Re: How to use position values in expressions?

Post by BassMati »

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
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: How to use position values in expressions?

Post by openBrain »

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
Veteran
Posts: 53930
Joined: Tue Mar 17, 2015 9:14 am

Re: How to use position values in expressions?

Post by chrisb »

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)
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
BassMati
Posts: 98
Joined: Sat Oct 06, 2018 11:39 am
Location: Germany Bielefeld
Contact:

Re: How to use position values in expressions?

Post by BassMati »

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: 98
Joined: Sat Oct 06, 2018 11:39 am
Location: Germany Bielefeld
Contact:

Re: How to use position values in expressions?

Post by BassMati »

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: 98
Joined: Sat Oct 06, 2018 11:39 am
Location: Germany Bielefeld
Contact:

Re: How to use position values in expressions?

Post by BassMati »

@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.
Post Reply