Example #1
0
def cmdPopulate_shapes_nonFromTo(refmode):
    sel = FreeCADGui.Selection.getSelectionEx()
    (lattices, shapes) = lattice2BaseFeature.splitSelection(sel)
    if activeBody() and len(shapes)>0:
        throwBody()
    if len(shapes) > 0 and len(lattices) == 1:
        FreeCAD.ActiveDocument.openTransaction("Populate with Children")
        lattice = lattices[0]
        for shape in shapes:
            CreateLatticePopulateChildren("Populate",u"Populate "+lattice.Object.Label+u" with "+shape.Object.Label,shape.Object,None,lattice.Object,refmode)
        deselect(sel)
        FreeCAD.ActiveDocument.commitTransaction()
    elif len(shapes) == 1 and len(lattices) > 1:
        shape = shapes[0]
        FreeCAD.ActiveDocument.openTransaction("Populate with Children")
        for lattice in lattices:
            CreateLatticePopulateChildren("Populate",u"Populate "+lattice.Object.Label+u" with "+shape.Object.Label,shape.Object,None,lattice.Object,refmode)
        deselect(sel)
        FreeCAD.ActiveDocument.commitTransaction()
    elif len(shapes) == 0 and len(lattices) == 2:
        shape = lattices[0]
        lattice = lattices[1]
        FreeCAD.ActiveDocument.openTransaction("Populate with Children")
        CreateLatticePopulateChildren("Populate",u"Populate "+lattice.Object.Label+u" with "+shape.Object.Label,shape.Object,None,lattice.Object,refmode)
        deselect(sel)
        FreeCAD.ActiveDocument.commitTransaction()        
    else:
        raise SelectionError("Bad selection","Please select some shapes and some arrays, first. You can select multiple shapes and one array, or multiple arrays and one shape.")
Example #2
0
def cmdPDPattern():
    sel = FreeCADGui.Selection.getSelectionEx()
    (lattices, shapes) = lattice2BaseFeature.splitSelection(sel)
    if len(shapes) > 0 and len(lattices) == 2:
        FreeCAD.ActiveDocument.openTransaction("Lattice Pattern")
        latticeFrom = lattices[0]
        latticeTo = lattices[1]
        CreateLatticePDPattern([so.Object for so in shapes],
                               latticeFrom.Object, latticeTo.Object,
                               'Use PlacementsFrom')
        deselect(sel)
        FreeCAD.ActiveDocument.commitTransaction()
    elif len(shapes) > 0 and len(lattices) == 1:
        FreeCAD.ActiveDocument.openTransaction("Lattice Pattern")
        latticeTo = lattices[0]
        CreateLatticePDPattern([so.Object for so in shapes], None,
                               latticeTo.Object, 'First item')
        deselect(sel)
        FreeCAD.ActiveDocument.commitTransaction()
    else:
        raise SelectionError(
            "Bad selection", "Please select either:\n"
            " one or more PartDesign features, and one or two placements/arrays \n"
            "or\n"
            " a template body and two placements/arrays, one from selected body and one from active body."
        )
def cmdPopulate_shapes_nonFromTo(refmode):
    sel = FreeCADGui.Selection.getSelectionEx()
    (lattices, shapes) = lattice2BaseFeature.splitSelection(sel)
    if len(shapes) > 0 and len(lattices) == 1:
        FreeCAD.ActiveDocument.openTransaction("Populate with copies")
        lattice = lattices[0]
        for shape in shapes:
            CreateLatticePopulateCopies("Populate",u"Populate "+lattice.Object.Label+u" with "+shape.Object.Label,shape.Object,None,lattice.Object,refmode)
        deselect(sel)
        FreeCAD.ActiveDocument.commitTransaction()
    elif len(shapes) == 1 and len(lattices) > 1:
        shape = shapes[0]
        FreeCAD.ActiveDocument.openTransaction("Populate with copies")
        for lattice in lattices:
            CreateLatticePopulateCopies("Populate",u"Populate "+lattice.Object.Label+u" with "+shape.Object.Label,shape.Object,None,lattice.Object,refmode)
        deselect(sel)
        FreeCAD.ActiveDocument.commitTransaction()
    elif len(shapes) == 0 and len(lattices) == 2:
        shape = lattices[0]
        lattice = lattices[1]
        FreeCAD.ActiveDocument.openTransaction("Populate with copies")
        CreateLatticePopulateCopies("Populate",u"Populate "+lattice.Object.Label+u" with "+shape.Object.Label,shape.Object,None,lattice.Object,refmode)
        deselect(sel)
        FreeCAD.ActiveDocument.commitTransaction()        
    else:
        raise SelectionError("Bad selection","Please select some shapes and some arrays, first. You can select multiple shapes and one array, or multiple arrays and one shape.")
def cmdPopulate_shapes_FromTo():
    sel = FreeCADGui.Selection.getSelectionEx()
    (lattices, shapes) = lattice2BaseFeature.splitSelection(sel)
    if len(shapes) == 0 and len(sel) >= 3:
        shapes = sel[:-2]
        lattices = sel[-2:]
    if len(shapes) > 0 and len(lattices) == 2:
        FreeCAD.ActiveDocument.openTransaction("Populate with copies")
        latticeFrom = lattices[0]
        latticeTo = lattices[1]
        for shape in shapes:
            CreateLatticePopulateCopies("Populate",u"Moved "+shape.Object.Label, shape.Object, latticeFrom.Object, latticeTo.Object,"Use PlacementsFrom")
        deselect(sel)
        FreeCAD.ActiveDocument.commitTransaction()
    else:
        raise SelectionError("Bad selection","Please select either:\n one or more shapes, and two placements/arrays \nor\nthree placements/arrays")
Example #5
0
def cmdPopulate_shapes_FromTo():
    sel = FreeCADGui.Selection.getSelectionEx()
    (lattices, shapes) = lattice2BaseFeature.splitSelection(sel)
    if activeBody() and len(shapes)>0:
        throwBody()
    if len(shapes) == 0 and len(sel) >= 3:
        shapes = sel[:-2]
        lattices = sel[-2:]
    if len(shapes) > 0 and len(lattices) == 2:
        FreeCAD.ActiveDocument.openTransaction("Populate with Children")
        latticeFrom = lattices[0]
        latticeTo = lattices[1]
        for shape in shapes:
            CreateLatticePopulateChildren("Populate",u"Moved "+shape.Object.Label, shape.Object, latticeFrom.Object, latticeTo.Object,"Use PlacementsFrom")
        deselect(sel)
        FreeCAD.ActiveDocument.commitTransaction()
    else:
        raise SelectionError("Bad selection","Please select either:\n one or more shapes, and two placements/arrays \nor\nthree placements/arrays")
Example #6
0
def cmdSingleBoundBox():
    sel = FreeCADGui.Selection.getSelectionEx()
    (lattices, shapes) = LBF.splitSelection(sel)
    if len(shapes) > 0 and len(lattices) == 0:
        FreeCAD.ActiveDocument.openTransaction("Make BoundBox")
        for shape in shapes:
            CreateBoundBox(shape.Object)
        FreeCAD.ActiveDocument.commitTransaction()
    elif len(shapes) == 1 and len(lattices) == 1:
        FreeCAD.ActiveDocument.openTransaction("Make BoundBox")
        CreateBoundBox(shapes[0].Object, OrientMode= "use OrientLink", OrientLink= lattices[0].Object)
        FreeCAD.ActiveDocument.commitTransaction()
    else:
        raise SelectionError("Bad selection", 
                             "Please select some shapes to make bounding boxes of, or a shape and a placement to make a rotated bounding box. You have selected {shapescount} objects and {latticescount} placements/arrays."
                                 .format(  shapescount= str(len(shapes)), 
                                           latticescount= str(len(lattices))  )
                            )
    deselect(sel)
Example #7
0
def cmdSingleBoundBox():
    sel = FreeCADGui.Selection.getSelectionEx()
    (lattices, shapes) = LBF.splitSelection(sel)
    if len(shapes) > 0 and len(lattices) == 0:
        FreeCAD.ActiveDocument.openTransaction("Make BoundBox")
        for shape in shapes:
            CreateBoundBox(shape.Object)
        FreeCAD.ActiveDocument.commitTransaction()
    elif len(shapes) == 1 and len(lattices) == 1:
        FreeCAD.ActiveDocument.openTransaction("Make BoundBox")
        CreateBoundBox(shapes[0].Object,
                       OrientMode="use OrientLink",
                       OrientLink=lattices[0].Object)
        FreeCAD.ActiveDocument.commitTransaction()
    else:
        raise SelectionError(
            "Bad selection",
            "Please select some shapes to make bounding boxes of, or a shape and a placement to make a rotated bounding box. You have selected {shapescount} objects and {latticescount} placements/arrays."
            .format(shapescount=str(len(shapes)),
                    latticescount=str(len(lattices))))
    deselect(sel)