Python Part.makeCompound() Examples

The following are 12 code examples of Part.makeCompound(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module Part , or try the search function .
Example #1
Source File: pipeFeatures.py    From flamingo with GNU Lesser General Public License v3.0 8 votes vote down vote up
def execute(self, fp):
    O=FreeCAD.Vector(0,0,0)
    vectL=FreeCAD.Vector(fp.L,0,0)
    vectW=FreeCAD.Vector(0,fp.W,0)
    vectH=FreeCAD.Vector(0,0,fp.H)
    base=[vectL,vectW,vectH]
    outline=[]
    for i in range(3):
      f1=Part.Face(Part.makePolygon([O,base[0],base[0]+base[1],base[1],O]))
      outline.append(f1)
      f2=f1.copy()
      f2.translate(base[2])
      outline.append(f2)
      base.append(base.pop(0))
    box=Part.Solid(Part.Shell(outline))
    tank=box.makeThickness([box.Faces[0],box.Faces[2]],-fp.thk1,1.e-3)
    top=Part.makeBox(fp.L-2*fp.thk1,fp.W-2*fp.thk1,fp.thk2,FreeCAD.Vector(fp.thk1,fp.thk1,fp.H-2*fp.thk2))
    fp.Shape=Part.makeCompound([tank,top]) 
Example #2
Source File: kicad.py    From fcad_pcb with MIT License 6 votes vote down vote up
def _makeCompound(self,obj,name,label=None,fit_arcs=False,
            fuse=False,add_feature=False,force=False):

        obj = unpack(obj)
        if not isinstance(obj,(list,tuple)):
            if not force and (
               not fuse or obj.TypeId=='Path::FeatureArea'):
                return obj
            obj = [obj]

        if fuse:
            return self._makeArea(obj,name,label=label,fit_arcs=fit_arcs)

        if add_feature or self.add_feature:
            return self._makeObject('Part::Compound',
                    '{}_combo'.format(name),label,'Links',obj)

        return Part.makeCompound(obj) 
Example #3
Source File: kicad.py    From fcad_pcb with MIT License 6 votes vote down vote up
def _makeCustomPad(self, params):
        wires = []
        for key in params.primitives:
            wire,width = makePrimitve(key, getattr(params.primitives, key))
            if not width:
                if isinstance(wire, Part.Edge):
                    wire = Part.Wire(wire)
                wires.append(wire)
            else:
                wire = Path.Area(Accuracy=self.arc_fit_accuracy,Thicken=wire.isClosed(),
                            Offset=width*0.5).add(wire).getShape()
                wires += wire.Wires
        if not wires:
            return
        if len(wires) == 1:
            return wires[0]
        return Part.makeCompound(wires) 
Example #4
Source File: NiCrPath.py    From NiCr with GNU General Public License v2.0 6 votes vote down vote up
def PathToShape(point_list):
    # creates a compound of faces from a NiCr point list to representate the wire
    # trajectory
    comp = []
    for i in range(len(point_list[0])-1):
        pa_0 = FreeCAD.Vector(tuple(point_list[0][i]))
        pa_1 = FreeCAD.Vector(tuple(point_list[0][i+1]))
        pb_0 = FreeCAD.Vector(tuple(point_list[1][i]))
        pb_1 = FreeCAD.Vector(tuple(point_list[1][i+1]))
        l0 = Part.Line(pa_0, pa_1).toShape()
        l1 = Part.Line(pb_0, pb_1).toShape()
        f = Part.makeLoft([l0, l1])
        comp.append(f)

    return Part.makeCompound(comp)




# routing between WirePaths (wirepath path link) 
Example #5
Source File: ExplodedAssembly.py    From ExplodedAssembly with GNU General Public License v2.0 5 votes vote down vote up
def updateTrajectoryLines():
    EAFolder = FreeCAD.ActiveDocument.ExplodedAssembly.Group
    # remove all the previous trajectory lines
    for traj in EAFolder:
        for lines in traj.Group:
            FreeCAD.ActiveDocument.removeObject(lines.Name)

    # re-draw all trajectories
    for traj in EAFolder:
        lines_compound = []
        objects = []
        for name in traj.names:
            objects.append(FreeCAD.ActiveDocument.getObject(name))

        inc_D = traj.Distance
        dir_vectors = []
        rot_centers = []
        for s in range(len(objects)):
            dir_vectors.append(FreeCAD.Vector(tuple(traj.dir_vectors[s])))
            rot_centers.append(FreeCAD.Vector(tuple(traj.rot_centers[s])))

        for n in range(len(objects)):
            pa = rot_centers[n]# objects[n].Placement.Base
            pb = rot_centers[n] + dir_vectors[n]*inc_D
            lines_compound.append(Part.makeLine(pa, pb))

        l_obj = FreeCAD.ActiveDocument.addObject('Part::Feature','trajectory_line')
        l_obj.Shape = Part.makeCompound(lines_compound)
        l_obj.ViewObject.DrawStyle = "Dashed"
        l_obj.ViewObject.LineWidth = 1.0
        traj.addObject(l_obj)

    FreeCAD.Gui.updateGui() 
Example #6
Source File: assembly.py    From FreeCAD_assembly3 with GNU General Public License v3.0 5 votes vote down vote up
def updatePlacement(self,pla=None,shape=None):
        obj = self.Object
        if not shape:
            # If the shape is not given, we simply obtain the shape inside our
            # own "Shape" property
            shape = obj.Shape
            if not shape or shape.isNull():
                return
            # De-compound to obtain the original shape in our coordinate system
            shape = shape.SubShapes[0]

            # Call getElementInfo() to obtain part's placement only. We don't
            # need the shape here, in order to handle missing down-stream
            # element
            info = self.getInfo()
            pla = info.Placement

        if obj.Offset.isIdentity():
            objPla = FreeCAD.Placement()
        else:
            if hasProperty(obj,'Radius'):
                s = shape.SubShapes[0]
            else:
                s = shape
            # obj.Offset is in the element shape's coordinate system, we need to
            # transform it to the assembly coordinate system
            mat = pla.multiply(utils.getElementPlacement(s)).toMatrix()
            objPla = FreeCAD.Placement(mat*obj.Offset.toMatrix()*mat.inverse())

        # Update the shape with its owner Part's current placement
        shape.Placement = pla

        # Make a compound to contain the part's placement. There may be
        # additional placement for this element which is updated below
        shape = Part.makeCompound(shape)
        obj.Shape = shape
        obj.Placement = objPla

        # unfortunately, we can't easily check two shapes are the same
        self.version.value += 1 
Example #7
Source File: kicad.py    From fcad_pcb with MIT License 5 votes vote down vote up
def make_gr_circle(params, width=0):
    center = makeVect(params.center)
    end = makeVect(params.end)
    r = center.distanceToPoint(end)
    if not width or r <= width*0.5:
        return Part.makeCircle(r+width*0.5, center)
    return Part.makeCompound([Part.Wire(Part.makeCircle(r+width*0.5,center)),
                              Part.Wire(Part.makeCircle(r-width*0.5,center,Vector(0,0,-1)))]) 
Example #8
Source File: kicad.py    From fcad_pcb with MIT License 5 votes vote down vote up
def getFaceCompound(shape,wire=False):
    objs = []
    for f in shape.Faces:
        selected = True
        for v in f.Vertexes:
            if not isZero(v.Z):
                selected = False
                break
        if not selected:
            continue

        ################################################################
        ## TODO: FreeCAD curve.normalAt is not implemented
        ################################################################
        # for e in f.Edges:
            # if isinstance(e.Curve,(Part.LineSegment,Part.Line)): continue
            # if not isZero(e.normalAt(Vector()).dot(Vector(0,0,1))):
                # selected = False
                # break
        # if not selected: continue

        if not wire:
            objs.append(f)
            continue
        for w in f.Wires:
            objs.append(w)
    if not objs:
        raise ValueError('null shape')
    return Part.makeCompound(objs) 
Example #9
Source File: kicad.py    From fcad_pcb with MIT License 5 votes vote down vote up
def _makeWires(self,obj,name,offset=0,fill=False,label=None,
            fit_arcs=False,workplane=False):

        if self.add_feature:
            if self.make_sketch:
                obj = self._makeSketch(obj,name,label)
            elif isinstance(obj,Part.Shape):
                obj = self._makeObject('Part::Feature', '{}_wire'.format(name),
                        label,'Shape',obj)
            elif isinstance(obj,(list,tuple)):
                objs = []
                comp = []
                for o in obj:
                    if isinstance(o,Part.Shape):
                        comp.append(o)
                    else:
                        objs.append(o)
                if comp:
                    comp = Part.makeCompound(comp)
                    objs.append(self._makeObject('Part::Feature',
                            '{}_wire'.format(name),label,'Shape',comp))
                obj = objs

        if fill or offset:
            return self._makeArea(obj,name,offset=offset,fill=fill,
                    fit_arcs=fit_arcs,label=label,workplane=workplane)
        else:
            return self._makeCompound(obj,name,label=label) 
Example #10
Source File: SheetMetalUnfolder.py    From FreeCAD_SheetMetal with GNU General Public License v3.0 5 votes vote down vote up
def generateSketch(self, edges, name, color):
        docG = FreeCADGui.ActiveDocument
        p = Part.makeCompound(edges)
        try:
            sk = Draft.makeSketch(p.Edges, autoconstraints = True,addTo=None,delete=False,name=name)
            sk.Label = name
        except:
            doc = FreeCAD.ActiveDocument
            skb = doc.ActiveObject
            doc.removeObject(skb.Name)
            SMWarning("discretizing Sketch")
            sk = SMmakeSketchfromEdges(p.Edges,name)
        docG.getObject(sk.Name).LineColor = color
        docG.getObject(sk.Name).PointColor = color 
Example #11
Source File: helper.py    From LCInterlocking with GNU Lesser General Public License v2.1 5 votes vote down vote up
def assemble_list_element_fast(el_list):
    if len(el_list) == 0:
        return None
    return Part.makeCompound(el_list) 
Example #12
Source File: assembly.py    From FreeCAD_assembly3 with GNU General Public License v3.0 4 votes vote down vote up
def execute(self,obj):
        if not obj.isDerivedFrom('Part::FeaturePython'):
            self.version.value += 1
            return False

        if obj.Detach:
            self.updatePlacement()
            return True

        info = None
        try:
            info = self.getInfo(False)
        except Exception:
            self.updatePlacement()

            if not gui.AsmCmdManager.AutoFixElement:
                raise

            self.fix()
            info = self.getInfo(False)

        if not getattr(obj,'Radius',None):
            shape = Part.Shape(info.Shape).copy()
        else:
            if isinstance(info.Part,tuple):
                parentShape = Part.getShape(info.Part[2], info.Subname,
                        transform=info.Part[3], needSubElement=False)
            else:
                parentShape = Part.getShape(info.Part, info.Subname,
                        transform=False, needSubElement=False)
            found = False
            shapes = [info.Shape]
            pla = info.Shape.Placement
            for edge in parentShape.Edges:
                if not info.Shape.isCoplanar(edge) or \
                    not utils.isSameValue(
                        utils.getElementCircular(edge,True),obj.Radius):
                    continue
                edge = edge.copy()
                if not found and utils.isSamePlacement(pla,edge.Placement):
                    found = True
                    # make sure the direct referenced edge is the first one
                    shapes[0] = edge
                else:
                    shapes.append(edge)
            shape = shapes

        # Make a compound to contain shape's part-local-placement. A second
        # level compound will be made inside updatePlacement() to contain the
        # part's placement.
        shape = Part.makeCompound(shape)
        try:
            shape.ElementMap = info.Shape.ElementMap
        except Exception:
            pass
        self.updatePlacement(info.Placement,shape)
        return True