Python Part.makeBox() Examples

The following are 11 code examples of Part.makeBox(). 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: helper.py    From LCInterlocking with GNU Lesser General Public License v2.1 7 votes vote down vote up
def check_limit_y_on_for_tab(tab_face, height, pos_y, width, thickness, material_face):
    box_x_size = thickness / 2.0 # OK
    box_y_size = 0.1
    box_z_size = height / 2.0

    box_y_minus = Part.makeBox(box_x_size, box_y_size, box_z_size)
    box_y_minus.translate(FreeCAD.Vector(-0.005 - box_x_size, pos_y - width/2.0 - box_y_size, -box_z_size / 2.0))

    box_y_plus = Part.makeBox(box_x_size, box_y_size, box_z_size)
    box_y_plus.translate(FreeCAD.Vector(-0.005 - box_x_size, pos_y + width/2.0, -box_z_size / 2.0))

    y_plus_inside, toto1 = check_intersect(box_y_plus, tab_face, material_face)
    y_minus_inside, toto2 = check_intersect(box_y_minus, tab_face, material_face)

    #shapeobj = FreeCAD.ActiveDocument.addObject("Part::Feature","y_plus_inside")
    #shapeobj.Shape = toto1
    #FreeCAD.ActiveDocument.recompute()

    #shapeobj = FreeCAD.ActiveDocument.addObject("Part::Feature","y_minus_inside")
    #shapeobj.Shape = toto2
    #FreeCAD.ActiveDocument.recompute()
    #print("y plus %r, minus %r" % (y_plus_inside, y_minus_inside))

    return y_plus_inside, y_minus_inside 
Example #3
Source File: freecad.py    From OpenModes with GNU General Public License v3.0 6 votes vote down vote up
def box(x, y, z, rounding=None):
    """Create a box, optionally rounding the edges

    Parameters
    ----------
    x, y, z: float
        Size of the box in 3 dimensions
    rounding: float, optional
        If specified, the edges will be rounded with this radius
    """
    box = Part.makeBox(x, y, z)

    centre = FreeCAD.Vector(-0.5*x, -0.5*y, -0.5*z)
    box.Placement.Base = centre

    if rounding is not None:
        box = box.makeFillet(rounding, box.Edges)
    return box


#bar = box(500, 150, 200, 10)
#mesh = freecad_mesh(bar)

#MeshPart.meshFromShape(box,GrowthRate=0.3,SegPerEdge=1,SegPerRadius=2,SecondOrder=0,Optimize=1,AllowQuad=0) 
Example #4
Source File: helper.py    From LCInterlocking with GNU Lesser General Public License v2.1 6 votes vote down vote up
def check_limit_z(tab_face, width, pos_y, material_face, material_plane):
    box_x_size = material_plane.thickness / 2.0 # OK
    box_y_size = width / 2.0
    box_z_size = 0.1

    box_z_plus = Part.makeBox(box_x_size, box_y_size, box_z_size)
    box_z_plus.translate(FreeCAD.Vector(0.005, pos_y - box_y_size/2.0, material_face.thickness / 2.0))

    box_z_minus = Part.makeBox(box_x_size, box_y_size, box_z_size)
    box_z_minus.translate(FreeCAD.Vector(0.005, pos_y - box_y_size/2.0, -box_z_size - material_face.thickness / 2.0))

    z_plus_inside, toto1 = check_intersect(box_z_plus, tab_face, material_plane)
    z_minus_inside, toto2 = check_intersect(box_z_minus, tab_face, material_plane)

    #shapeobj = FreeCAD.ActiveDocument.addObject("Part::Feature","tstupdds_plus")
    #shapeobj.Shape = toto1
    #FreeCAD.ActiveDocument.recompute()

    #shapeobj = FreeCAD.ActiveDocument.addObject("Part::Feature","tstupddsd_minus")
    #shapeobj.Shape = toto2
    #FreeCAD.ActiveDocument.recompute()
    #print("z plus %r, minus %r" % (z_plus_inside, z_minus_inside))

    return z_plus_inside, z_minus_inside 
Example #5
Source File: helper.py    From LCInterlocking with GNU Lesser General Public License v2.1 6 votes vote down vote up
def check_limit_y(tab_face, height, pos_y, width, material_plane):
    box_x_size = material_plane.thickness / 2.0 # OK
    box_y_size = 0.1
    box_z_size = height / 2.0

    box_y_minus = Part.makeBox(box_x_size, box_y_size, box_z_size)
    box_y_minus.translate(FreeCAD.Vector(0.005, pos_y - width/2.0 - box_y_size, -box_z_size / 2.0))

    box_y_plus = Part.makeBox(box_x_size, box_y_size, box_z_size)
    box_y_plus.translate(FreeCAD.Vector(0.005, pos_y + width/2.0, -box_z_size / 2.0))

    y_plus_inside, toto1 = check_intersect(box_y_plus, tab_face, material_plane)
    y_minus_inside, toto2 = check_intersect(box_y_minus, tab_face, material_plane)

    #shapeobj = FreeCAD.ActiveDocument.addObject("Part::Feature","y_plus_inside")
    #shapeobj.Shape = toto1
    #FreeCAD.ActiveDocument.recompute()

    #shapeobj = FreeCAD.ActiveDocument.addObject("Part::Feature","y_minus_inside")
    #shapeobj.Shape = toto2
    #FreeCAD.ActiveDocument.recompute()
    #print("y plus %r, minus %r" % (y_plus_inside, y_minus_inside))

    return y_plus_inside, y_minus_inside 
Example #6
Source File: CountersunkHoles.py    From FreeCAD_FastenersWB with GNU General Public License v2.0 5 votes vote down vote up
def execute(self, fp):
    '''"Print a short message when doing a recomputation, this method is mandatory" '''
    #fp.Shape = Part.makeBox(1,1,1 + len(fp.diameters))
    origshape = fp.baseObject[0].Shape
    shape = origshape
    for diam in fp.diameters:
      FreeCAD.Console.PrintLog("Generating hole tool for: " + diam + "\n")
      edge, m, f, o, type = cshSplitEdgeDiam(diam)
      cshole = cshMakeCSHole(m, type)
      FastenerBase.FSMoveToObject(cshole, origshape.getElement(edge), f == '1', float(o))
      shape = shape.cut(cshole)
    fp.Shape = shape 
Example #7
Source File: shapes.py    From cadquery-freecad-module with GNU Lesser General Public License v3.0 5 votes vote down vote up
def makeBox(cls, length, width, height, pnt=Vector(0, 0, 0), dir=Vector(0, 0, 1)):
        """
        makeBox(length,width,height,[pnt,dir]) -- Make a box located in pnt with the dimensions (length,width,height)
        By default pnt=Vector(0,0,0) and dir=Vector(0,0,1)'
        """
        return Shape.cast(FreeCADPart.makeBox(length, width, height, pnt.wrapped, dir.wrapped)) 
Example #8
Source File: makehinges.py    From LCInterlocking with GNU Lesser General Public License v2.1 5 votes vote down vote up
def create_flat_connection(hinge_properties, referentiel_face):
    box_x_size = hinge_properties.arc_length
    box_y_size = hinge_properties.extrustion_vector.Length
    box_z_size = hinge_properties.thickness
    box = Part.makeBox(box_x_size, box_y_size, box_z_size, FreeCAD.Vector(0., -box_y_size/2.0, -box_z_size/2.0))

    flat_connection = transform(box, referentiel_face)

    return flat_connection 
Example #9
Source File: makehinges.py    From LCInterlocking with GNU Lesser General Public License v2.1 5 votes vote down vote up
def create_hole_hinge(hinge_clearance, hinge_length, thickness, kerf_diameter):
    height = thickness * 2.0
    hinge_width = max(10e-3, hinge_clearance - kerf_diameter)
    if hinge_clearance < kerf_diameter:
        raise ValueError("Hinge clearance is less than kerf diameter")
    elif hinge_clearance < 2. * kerf_diameter:
        box_length = hinge_length - kerf_diameter
        hinge = Part.makeBox(hinge_width, box_length, height, FreeCAD.Vector(-hinge_width/2.0, -box_length/2.0, -height/2.0))
    else:
        box_length = hinge_length - hinge_width - kerf_diameter # hinge_width is for the two corner radius
        hinge = draw_rounded_hinge(hinge_width, box_length, height)

    return hinge 
Example #10
Source File: join.py    From LCInterlocking with GNU Lesser General Public License v2.1 5 votes vote down vote up
def screw_way_on_face(material_face, material_plane, screw_nut_spec, pos_y, dog_bone=False):
    # horizontal hole
    vert_corrected_length = screw_nut_spec.screw_length - material_plane.thickness \
                            + material_plane.thickness_tolerance + screw_nut_spec.screw_length_tol
    corrected_width = screw_nut_spec.screw_diameter * 1.2 - material_face.laser_beam_diameter
    corrected_height = material_face.thickness  # + materialFace.tolerance
    screw_hole = Part.makeBox(vert_corrected_length, corrected_width, corrected_height,
                              FreeCAD.Vector(0.,
                                             -corrected_width / 2.0, -corrected_height / 2.0))
    if dog_bone:
        screw_hole = helper.make_dog_bone_on_limits_on_xy(screw_hole, corrected_height, True)
    x_pos = -vert_corrected_length
    screw_hole.translate(FreeCAD.Vector(x_pos, pos_y, 0))
    # Nut hole
    corrected_length = screw_nut_spec.nut_height - material_face.laser_beam_diameter + 0.1
    corrected_width = screw_nut_spec.nut_flat_flat - material_face.laser_beam_diameter + 0.1
    nut_hole = Part.makeBox(corrected_length, corrected_width, corrected_height,
                            FreeCAD.Vector(0,
                                           -corrected_width / 2.0, -corrected_height / 2.0))
    x_pos = -vert_corrected_length + screw_nut_spec.nut_height + screw_nut_spec.screw_length_tol
    nut_hole.translate(FreeCAD.Vector(x_pos, pos_y, 0))
    if dog_bone:
        nut_hole = helper.make_dog_bone_on_limits_on_xy(nut_hole, corrected_height)
    hole = screw_hole.fuse(nut_hole)
    return hole


#            X (Length)
#            |
#            |
#            |
#            |Z (Height)
#            ---------------------------> Y (Width)
# X est vers le haut
# Y est aligné sur la face
# Z est devant la camera 
Example #11
Source File: join.py    From LCInterlocking with GNU Lesser General Public License v2.1 4 votes vote down vote up
def tab_join_create_tab_on_face(material_face, material_plane, width, pos_y, tab_face, dog_bone=False):

    y_plus_inside, y_minus_inside = helper.check_limit_y_on_for_tab(tab_face, material_face.thickness, pos_y, width,
                                                                    material_plane.thickness, material_face)
    # X Rien pr l'instant, mais on peut prendre en compte l'epaiseur variante de la piece opposé => length
    # Y Ajout d'un Kerf => width
    # Z Rien => height
    corrected_length = material_plane.thickness
    # corrected_width = width + materialFace.laser_beam_diameter
    corrected_height = material_face.thickness

    corrected_width = width  # - materialPlane.laser_beam_diameter
    corrected_width_center = corrected_width / 2.0
    if y_minus_inside and y_plus_inside:
        corrected_width += material_face.laser_beam_diameter
        corrected_width_center = corrected_width / 2.0
    elif y_minus_inside:
        corrected_width += material_face.laser_beam_diameter / 2.0
        corrected_width_center = (corrected_width + material_face.laser_beam_diameter / 2.0) / 2.0
    elif y_plus_inside:
        corrected_width += material_face.laser_beam_diameter / 2.0
        corrected_width_center = (corrected_width - material_face.laser_beam_diameter / 2.0) / 2.0

    #origin = FreeCAD.Vector(-corrected_length / 2.0, -corrected_width_center, -corrected_height / 2.0)
    origin = FreeCAD.Vector(0., -corrected_width_center, -corrected_height / 2.0)
    tab = Part.makeBox(corrected_length, corrected_width, corrected_height, origin)
    tab.translate(FreeCAD.Vector(0, pos_y, 0))

    hole = None
    left_hole = None
    right_hole = None

    if dog_bone:
        radius = min(corrected_width, corrected_length) * 2 / 30.
        if y_minus_inside:
            left_hole = Part.makeCylinder(radius, corrected_height,
                                          FreeCAD.Vector(0, -corrected_width_center + pos_y, -corrected_height / 2.0),
                                          FreeCAD.Vector(0, 0, 1.))
        if y_plus_inside:
            right_hole = Part.makeCylinder(radius, corrected_height,
                                           FreeCAD.Vector(0, -corrected_width_center + corrected_width + pos_y,
                                           -corrected_height / 2.0),
                                           FreeCAD.Vector(0, 0, 1.))
        hole = left_hole
        if hole and right_hole:
            hole = hole.fuse(right_hole)
        elif right_hole:
            hole = right_hole

    return tab, hole