group objects with shapes?

Need help, or want to share a macro? Post here!
Post Reply
Posts: 23
Joined: Wed May 18, 2022 9:00 pm

group objects with shapes?

Post by Vasten »

is it possible to make a group object with a shape?

i can make custom python group

i can make custom feature python objects

but i cant find a way to make a container that has its own shape

for example, the part boolean ops like fusion, create an object that had sub objects like a group

is it possible to do this with a feature python object?


my group doesn't have a placement... can this be added, or do groups just not have a placement

right now im guessing that.. there is a way to assign objects to a feature python object like a group, and thus achieve both things at once
Posts: 49
Joined: Mon May 16, 2022 10:35 am

Re: group objects with shapes?

Post by thyssentishman »

As explained here you should use App::PropertyLink instead of groups to link between objects. The claimChildren() function in the ViewProvider class creates the parent-child structure in the TreeView.
Vasten wrote: Thu Jun 30, 2022 1:50 pm my group doesn't have a placement... can this be added, or do groups just not have a placement
If you create your parent using Part::FeaturePython it will have a Placement property.

Here is an example adapted from here and here:

Code: Select all

import FreeCADGui

class ViewProvider:
    def __init__(self, obj):
        '''Set this object to the proxy object of the actual view provider'''
        self.Object = obj.Object
        obj.Proxy = self

    def claimChildren(self):
        return self.Object.InList

    def __getstate__(self):
        '''When saving the document this object gets stored using Python's json module.\
                Since we have some un-serializable parts here -- the Coin stuff -- we must define this method\
                to return a tuple of all serializable objects or None.'''
        return None

    def __setstate__(self,state):
        '''When restoring the serialized object from document we have the chance to set some internals here.\
                Since no data were serialized nothing needs to be done here.'''
        return None


parent.Label = parent.Label # this is needed to trigger an update
Hope it helps.

Kind regards,

EDIT: Included response to question about group placement.
Post Reply