App::FeaturePython equivalent toPart:: Multi Union/Fuse

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
keithsloan52
Veteran
Posts: 2764
Joined: Mon Feb 27, 2012 5:31 pm

App::FeaturePython equivalent toPart:: Multi Union/Fuse

Post by keithsloan52 »

Part has the option of creating a Multi Union/Fusion of sub Parts.

Is an equivalent available with a user defined App::FeaturePython object? Or could such a equivalent be implemented

I would like to create a hierarchi of user defined objects which do not have graphics parts but do allow users to set a lot of
parameters that related to the FreeCAD drawing / 3D Object being created.

Thanks
keithsloan52
Veteran
Posts: 2764
Joined: Mon Feb 27, 2012 5:31 pm

Re: App::FeaturePython equivalent toPart:: Multi Union/Fuse

Post by keithsloan52 »

Okay I tried to use Groups, but seems you cannot add a sub group i.e. Add a group to a group as I get the following error

Code: Select all

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/freecad/Mod/GDML/importGDML.py", line 79, in open
    processGDML(filename)
  File "/usr/lib/freecad/Mod/GDML/importGDML.py", line 557, in processGDML
    processElements()
  File "/usr/lib/freecad/Mod/GDML/importGDML.py", line 518, in processElements
    elementObjGrp = elementsGrp.newObject("App:DocumentObjectGroup",name)
<class 'Base.FreeCADError'>: Cannot create object of type 'App:DocumentObjectGroup'
Code is

Code: Select all

def processElements() :
    elementsGrp  = doc.addObject("App::DocumentObjectGroup","Elements")
    for element in materials.findall('element') :
        name = element.get('name')
        elementObjGrp = elementsGrp.newObject("App:DocumentObjectGroup",name)
        for fraction in element.findall('fraction') :
            n = fraction.get('n')
            ref = fraction.get('ref')
            fractObj = elementObjGrp.newObject("App::FeaturePython",ref)
            GGMLfraction(fractObj,ref,n)
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: App::FeaturePython equivalent toPart:: Multi Union/Fuse

Post by DeepSOIC »

BooleanFragments tool is essentially the same as Part Union, except it does a different operation. And it's implemented in python. You can use it as a starting point.
https://github.com/FreeCAD/FreeCAD/blob ... res.py#L69
Post Reply