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.

Postby joeldebruijn » Wed May 05, 2021 9:51 am

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

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

Postby chrisb » Wed May 05, 2021 3:24 pm

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.

Postby joeldebruijn » Wed May 05, 2021 6:26 pm

Thanks in advance, see attachement.

20210503 - WasRuimte - KastGroot.FCStd
(48.83 KiB) Downloaded 2 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 249 times
tigrincs
Posts: 7
Joined: Wed May 05, 2021 6:45 pm

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

Postby tigrincs » Wed May 05, 2021 7:25 pm

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
Posts: 436
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

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

Postby edwilliams16 » 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.
tigrincs
Posts: 7
Joined: Wed May 05, 2021 6:45 pm

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

Postby tigrincs » Wed May 05, 2021 8:51 pm

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.

Postby joeldebruijn » Wed May 05, 2021 8:55 pm

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 199 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 199 times
Anyway, thanks for helping me out!
edwilliams16
Posts: 436
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

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

Postby edwilliams16 » 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
Screen Shot 2021-05-05 at 11.41.27 AM.png (28.36 KiB) Viewed 171 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: 7
Joined: Wed May 05, 2021 6:45 pm

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

Postby tigrincs » Wed May 05, 2021 10:00 pm

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
Posts: 436
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

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

Postby edwilliams16 » Thu May 06, 2021 1:39 am

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