Referencing X,Y, Z coordinate of another object in formula editor.

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!
User avatar
joeldebruijn
Posts: 3
Joined: Thu Apr 01, 2021 5:26 am
Contact:

Referencing X,Y, Z coordinate of another object in formula editor.

Post by joeldebruijn »

Context:

- I'm designing a cabinet with different 'heights' for each shelf.
- Because I'm using certain storage boxes the heigth is calculated in a spreadsheet, so eacht shelf fits them nicely.
- Each shelf is supported by 4 beams.
- First design, so maybe n00b question.

What I try to accomplish:

- After I copy/paste a shelf and its beams I change the z coordinate of the first horizontal beam.
- I want the other beams to change their z coordinate as well automaticcaly.

What I expected:

To be able to enter the following in the formula editor at the Z property of Beam II "<<Beam I>>.Placement.Base.Z"

So I'm having trouble using a property/value of one object in another by using the formula editor.

I studied the Placement page in the wiki and the aeroplane example, but I still dont get it.

I'm on FreeCad 0.19
Last edited by joeldebruijn on Wed May 05, 2021 6:14 pm, edited 1 time in total.
chrisb
Veteran
Posts: 53953
Joined: Tue Mar 17, 2015 9:14 am

Re: Referencing X,Y, Z coordinate of another object in formula editor.

Post by chrisb »

Hard to say anything without the file.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
joeldebruijn
Posts: 3
Joined: Thu Apr 01, 2021 5:26 am
Contact:

Re: Referencing X,Y, Z coordinate of another object in formula editor.

Post by joeldebruijn »

Thanks in advance, see attachement.

20210503 - WasRuimte - KastGroot.FCStd
(48.83 KiB) Downloaded 20 times

Made a screenshot also:
I'm trying to make the Z for beam II, III and IV depending on Z of beam I.
20210505-201955-.png
20210505-201955-.png (156.77 KiB) Viewed 744 times
tigrincs
Posts: 8
Joined: Wed May 05, 2021 6:45 pm

Re: Referencing X,Y, Z coordinate of another object in formula editor.

Post by tigrincs »

Hi Joel
I'm into woodworking and I came accross your problem, although I haven't managed to find the solution, but I do understand what you mean. The problem, as I understand is that the Placement attribute of the referenced object is actually a vector and I haven't the foggiest idea, if the formula editor has any functions to manipulate vectors, like to access the Y coordinate of a vector. But I keep digging, and hoping that somebody will be able to give us an answer.
edwilliams16
Veteran
Posts: 3117
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Referencing X,Y, Z coordinate of another object in formula editor.

Post by edwilliams16 »

Code: Select all

<<BladBRaamwerkLigger I>>.Placement.Base.z
and

Code: Select all

Box010.Placement.Base.z
both work for me in the formula editor

Note it is lower-case z.
tigrincs
Posts: 8
Joined: Wed May 05, 2021 6:45 pm

Re: Referencing X,Y, Z coordinate of another object in formula editor.

Post by tigrincs »

edwilliams16 wrote: Wed May 05, 2021 7:49 pm

Code: Select all

<<BladBRaamwerkLigger I>>.Placement.Base.z
and

Code: Select all

Box010.Placement.Base.z
both work for me in the formula editor

Note it is lower-case z.
Well done, thanks! There's no code completion for .Placement.Base.x|y|z :(
BTW, is there an object reference library, or a wiki on the properties somewhere here? Would be great to have especially because without the completion I'm clueless sometimes.
User avatar
joeldebruijn
Posts: 3
Joined: Thu Apr 01, 2021 5:26 am
Contact:

Re: Referencing X,Y, Z coordinate of another object in formula editor.

Post by joeldebruijn »

Ahhhhhh! Thanks, so often the smallest things take the longest time ...

At first I thought "Base" wasnt possible because it isnt in the listed suggestions:
20210505-224814-.png
20210505-224814-.png (5.43 KiB) Viewed 694 times
But typing it anyway works.

Then (I dont know why) I used uppercase the whole time.
20210505-224833-Window.png
20210505-224833-Window.png (4.27 KiB) Viewed 694 times
Anyway, thanks for helping me out!
edwilliams16
Veteran
Posts: 3117
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Referencing X,Y, Z coordinate of another object in formula editor.

Post by edwilliams16 »

Code completion is partly broken in the formula editor. It does work in the Python console, so
you can look for completions of App.ActiveDocument.Box010.Placement there.
Screen Shot 2021-05-05 at 11.41.27 AM.png
Screen Shot 2021-05-05 at 11.41.27 AM.png (28.36 KiB) Viewed 666 times
The property naming hierarchy, I think always follows how it shows in the property editor, so, for instance

Code: Select all

Placement.Axis.z
is just what you might expect.
tigrincs
Posts: 8
Joined: Wed May 05, 2021 6:45 pm

Re: Referencing X,Y, Z coordinate of another object in formula editor.

Post by tigrincs »

edwilliams16 wrote: Wed May 05, 2021 9:33 pm Code completion is partly broken in the formula editor. It does work in the Python console, so
you can look for completions of App.ActiveDocument.Box010.Placement there.
Screen Shot 2021-05-05 at 11.41.27 AM.png

The property naming hierarchy, I think always follows how it shows in the property editor, so, for instance

Code: Select all

Placement.Axis.z
is just what you might expect.
Ed, you're a true gem, thanks! I don't know Python, but I know other languages, so I guess, I can take it from here.
One more silly question. I have named bodies in the tree, say there's a body named, say 'fence'. It would be obvious to me to refer to it as App.ActiveDocument.fence.Placement yadayadayada… But for me it does not work in the console, it refers to PartXXX, BodyYYY, PadZZZ. I did change the name, the ID, the label. Drives me nuts. Can you give me a last hint?
edwilliams16
Veteran
Posts: 3117
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Referencing X,Y, Z coordinate of another object in formula editor.

Post by edwilliams16 »

The internal name is unique. The label you assign need not be - though it would be a good idea if you are going to script with it.

If you hover over an object in the 3D or tree view, you'll see its internal name at the left bottom edge of the screen.

Or you might find selection view useful: https://wiki.freecadweb.org/Selection_view

Using the python console with the label is a bit more cumbersome.

Code: Select all

obj = App.ActiveDocument.getObjectsByLabel("myLabel")[0]
obj.   # will give possible completions - properties and methods
The getObjectsByLabel() method returns a list (not necessarily unique, remember) - the [0] picks off the first item

Typing App.ActiveDocument all the time is also tedious.

Code: Select all

DOC = App.ActiveDocument
will allow you to refer to it as DOC
Post Reply