Add children to parent object

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
dubstar-04
Posts: 698
Joined: Mon Mar 04, 2013 8:41 pm
Location: Chester, UK
Contact:

Add children to parent object

Post by dubstar-04 »

I would like to create an object:

Code: Select all

obj_chassis = doc.addObject("App::FeaturePython","Chassis")
and then add child object to it.

I have had a quick look at the arch workbench to see how its done but i don't really understand it. Can anyone advise?

Thanks,

Dan
danielfalck
Posts: 395
Joined: Fri Oct 07, 2011 8:58 pm
Location: Beaverton,Oregon, USA
Contact:

Re: Add children to parent object

Post by danielfalck »

Hi Dan,

Here is an example of how we have been doing it in the Path workbench (a work in progress that isn't in master yet):

https://github.com/danielfalck/FreeCAD/ ... re.py#L138

We are inserting the new object into the parent object's 'group' . This example is a specialized case of adding a CNC fixture offset object into the CNC project object. The way I am doing it there - the for loop and all that - is just to find the parent object in the Document tree. You can insert something into a group directly, if you already know it's Name.
I hope that helps a bit.
User avatar
dubstar-04
Posts: 698
Joined: Mon Mar 04, 2013 8:41 pm
Location: Chester, UK
Contact:

Re: Add children to parent object

Post by dubstar-04 »

Thanks for the reply.

I have the following code working now.

Code: Select all


        doc = FreeCAD.activeDocument()
        obj_chassis_project = doc.addObject("App::DocumentObjectGroupPython","Chassis Project")
        obj_chassis_child = doc.addObject("App::FeaturePython","Chassis")         
        Chassis(obj_chassis_child)
        g = obj_chassis.Group
        g.append(obj_chassis_child)
        obj_chassis.Group = g

Thanks,

Dan
Post Reply