Can I have FreeCAD python object as a sub-object(?) of another.

Need help, or want to share a macro? Post here!
keithsloan52
Posts: 1065
Joined: Mon Feb 27, 2012 5:31 pm

Can I have FreeCAD python object as a sub-object(?) of another.

Postby keithsloan52 » Thu Jan 16, 2020 2:29 pm

Trying to get my head round if it is possible to have a python object as a sub-object ( my term ). Is this possible?

i.e. I wish to create a object lets call it container-obj with various parameters that gets created with the normal placement/position/rotation
but can contain one of another set of objects again with various parameters but without the normal placement et al.

Where the various parameters of the container-obj and the object it contains can be edited in the normal way.

Thoughts - Thanks
reox
Posts: 684
Joined: Sat Aug 13, 2016 10:06 am
Contact:

Re: Can I have FreeCAD python object as a sub-object(?) of another.

Postby reox » Thu Jan 16, 2020 4:22 pm

I dont know if I understood you correctly, but you basically want something like this:

Code: Select all

class SomeObject:
    """
    This object does stuff...
    """
    def __init__(self, a, b, c, d):
    	pass

class MyFancyObject(SomeObject):
    def __init__(self, a, b, c, d, x, y, z):
        super().__init__(a + x, b + y, c + z, d * x * y * z)

:?:
vocx
Posts: 2452
Joined: Thu Oct 18, 2018 9:18 pm

Re: Can I have FreeCAD python object as a sub-object(?) of another.

Postby vocx » Thu Jan 16, 2020 4:48 pm

keithsloan52 wrote:
Thu Jan 16, 2020 2:29 pm
...
Where the various parameters of the container-obj and the object it contains can be edited in the normal way.
Can you make a concrete example with some objects that you've seen in FreeCAD? For instance, the Std_Group and Std_Part objects basically do what you describe. They are objects that contain other objects. In the case of Std_Group, it is very basic, it doesn't control the position of the objects inside; it just groups them in the tree view. In the case of Std_Part, it has the Origin extension which allows it to control the placement of the objects relatively to its Origin object.

You can subclass the Std_Group object (App_DocumentObjectGroup), which is what other workbenches do. Or you can subclass App_GeoFeature, which is how Std_Part is implemented.

Both Std_Group and Std_Part have a "Group" property, which is an "App::PropertyLinkList" to refer to other objects. So, you could also create a regular object and use this property to link other objects to it.
To support the documentation effort, and code development, your donation is appreciated: paypal.