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?
...also...
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
group objects with shapes?
-
- Posts: 49
- Joined: Mon May 16, 2022 10:35 am
Re: group objects with shapes?
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.
Here is an example adapted from here and here:
Hope it helps.
Kind regards,
Johannes
EDIT: Included response to question about group 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
doc=FreeCAD.ActiveDocument
parent=doc.addObject("Part::FeaturePython","Parent")
child=doc.addObject("Part::FeaturePython","Child")
child.addProperty("App::PropertyLink","LinkToParent")
child.LinkToParent=parent
obj=ViewProvider(parent.ViewObject)
parent.Label = parent.Label # this is needed to trigger an update
Kind regards,
Johannes
EDIT: Included response to question about group placement.