how add custom properties to any object?

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: how add custom properties to any object?

Post by openBrain »

ifohancroft wrote: Tue Sep 14, 2021 10:03 pm Can you access custom properties of a parent object?

Like if I have a Sketch, inside of a Body inside of a Part, can I add a custom property to the Part then access that as a dimension constraint in the Sketch? How?
Just set in an expression

Code: Select all

=PARTNAME.PROPERTYNAME
hmk
Posts: 159
Joined: Tue Sep 29, 2020 1:19 pm
Location: Berlin, Germany

Re: how add custom properties to any object?

Post by hmk »

openBrain wrote: Wed Sep 15, 2021 8:13 am Just set in an expression

Code: Select all

=PARTNAME.PROPERTYNAME
More details here: https://wiki.freecadweb.org/Expressions ... ng_objects
User avatar
Zolko
Veteran
Posts: 2213
Joined: Mon Dec 17, 2018 10:02 am

Re: how add custom properties to any object?

Post by Zolko »

ifohancroft wrote: Tue Sep 14, 2021 10:03 pm Can you access custom properties of a parent object? Like if I have a Sketch, inside of a Body inside of a Part, can I add a custom property to the Part then access that as a dimension constraint in the Sketch? How?
No, you can't, that would create a cyclic dependency. Unfortunately, because that would be extremely useful
try the Assembly4 workbench for FreCAD — tutorials here and here
User avatar
ifohancroft
Posts: 206
Joined: Fri May 31, 2019 11:25 pm
Location: Sofia, Bulgaria
Contact:

Re: how add custom properties to any object?

Post by ifohancroft »

Zolko wrote: Wed Sep 15, 2021 10:41 am
ifohancroft wrote: Tue Sep 14, 2021 10:03 pm Can you access custom properties of a parent object? Like if I have a Sketch, inside of a Body inside of a Part, can I add a custom property to the Part then access that as a dimension constraint in the Sketch? How?
No, you can't, that would create a cyclic dependency. Unfortunately, because that would be extremely useful
Thank you!

Also, yeah. It would help a lot if it was possible.
Last edited by ifohancroft on Wed Sep 15, 2021 12:41 pm, edited 2 times in total.
I like making, breaking and modding stuff, using a soldering iron, code or both. https://ifohancroft.com
User avatar
ifohancroft
Posts: 206
Joined: Fri May 31, 2019 11:25 pm
Location: Sofia, Bulgaria
Contact:

Re: how add custom properties to any object?

Post by ifohancroft »

openBrain wrote: Wed Sep 15, 2021 8:13 am
ifohancroft wrote: Tue Sep 14, 2021 10:03 pm Can you access custom properties of a parent object?

Like if I have a Sketch, inside of a Body inside of a Part, can I add a custom property to the Part then access that as a dimension constraint in the Sketch? How?
Just set in an expression

Code: Select all

=PARTNAME.PROPERTYNAME
hmk wrote: Wed Sep 15, 2021 8:26 am
openBrain wrote: Wed Sep 15, 2021 8:13 am Just set in an expression

Code: Select all

=PARTNAME.PROPERTYNAME
More details here: https://wiki.freecadweb.org/Expressions ... ng_objects
Attaching the file for reference, but it doesn't seem to work.

I have a Part called Keyboard, inside it I have a Body called Plate and inside it I have a Sketch that I haven't renamed.
I added a length property to the Keyboard part and called it switch. Trying to access it either as =Keyboard.switch or =<<Keyboard>>.switch I get:
Result: cyclic reference to Unnamed#Part

OS: Manjaro Linux (MATE/mate)
Word size of FreeCAD: 64-bit
Version: 0.20.25288 (Git) AppImage
Build type: Release
Branch: master
Hash: bbb557aab6129efd9486d6df19f06c2976fdb7e5
Python version: 3.9.6
Qt version: 5.12.9
Coin version: 4.0.0
OCC version: 7.5.2
Locale: English/United States (en_US)
Attachments
test.FCStd
(7 KiB) Downloaded 31 times
I like making, breaking and modding stuff, using a soldering iron, code or both. https://ifohancroft.com
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: how add custom properties to any object?

Post by openBrain »

ifohancroft wrote: Wed Sep 15, 2021 12:40 pm I have a Part called Keyboard, inside it I have a Body called Plate and inside it I have a Sketch that I haven't renamed.
I added a length property to the Keyboard part and called it switch. Trying to access it either as =Keyboard.switch or =<<Keyboard>>.switch I get:
Result: cyclic reference to Unnamed#Part
Yep, as @zolko explained it creates a cyclic dependency in the expression engine.
drmacro
Veteran
Posts: 9002
Joined: Sun Mar 02, 2014 4:35 pm

Re: how add custom properties to any object?

Post by drmacro »

Hmm...it does work, but, doing that creates a cyclic reference because the sub object would be referencing something that is part of what defines the sub-object.

If you create a another Std_Part and add a property called macswitch as shown below, it's fine.
macswitch.png
macswitch.png (89.44 KiB) Viewed 2442 times
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
User avatar
ifohancroft
Posts: 206
Joined: Fri May 31, 2019 11:25 pm
Location: Sofia, Bulgaria
Contact:

Re: how add custom properties to any object?

Post by ifohancroft »

openBrain wrote: Wed Sep 15, 2021 1:07 pm
ifohancroft wrote: Wed Sep 15, 2021 12:40 pm I have a Part called Keyboard, inside it I have a Body called Plate and inside it I have a Sketch that I haven't renamed.
I added a length property to the Keyboard part and called it switch. Trying to access it either as =Keyboard.switch or =<<Keyboard>>.switch I get:
Result: cyclic reference to Unnamed#Part
Yep, as @zolko explained it creates a cyclic dependency in the expression engine.
drmacro wrote: Wed Sep 15, 2021 1:36 pm Hmm...it does work, but, doing that creates a cyclic reference because the sub object would be referencing something that is part of what defines the sub-object.

If you create a another Std_Part and add a property called macswitch as shown below, it's fine.

macswitch.png
Ah! Got it. Thank you!
I like making, breaking and modding stuff, using a soldering iron, code or both. https://ifohancroft.com
jtm2020hyo
Posts: 594
Joined: Wed Aug 12, 2020 1:24 am

Re: how add custom properties to any object?

Post by jtm2020hyo »

ifohancroft wrote: Tue Sep 14, 2021 10:03 pm
yes, sounds possible and until I know there exist different methods.
hmk
Posts: 159
Joined: Tue Sep 29, 2020 1:19 pm
Location: Berlin, Germany

Re: how add custom properties to any object?

Post by hmk »

For what it's worth, it seem to work for a special case:

1) Define the custom properties in a Body:
Screenshot from 2021-11-17 17-31-59.png
Screenshot from 2021-11-17 17-31-59.png (47.25 KiB) Viewed 1946 times
2) Create a PartDesign shape (e.g., a Cylinder) and in an expression use the shape's _Body property to "reach up" to its parent Body:
Screenshot from 2021-11-17 17-33-36.png
Screenshot from 2021-11-17 17-33-36.png (80.14 KiB) Viewed 1946 times
3) Sometimes a wild expression can get you up to the parent Body, for example an expression inside a Sketch :)
Screenshot from 2021-11-17 17-44-25.png
Screenshot from 2021-11-17 17-44-25.png (89.56 KiB) Viewed 1946 times
Post Reply