Пример #1
0
def shp_topbeltclamp (railaxis = 'x', bot_norm = '-z', pos = V0, extra=1):

    cyl_posx = Gt2BeltClamp.CB_L + Gt2BeltClamp.CS + Gt2BeltClamp.CCYL_R
    height =  Gt2BeltClamp.C_H + extra

    shpcyl = fcfun.shp_cyl(r= Gt2BeltClamp.CCYL_R,
                           h= height,
                           normal = VZ,
                           pos = FreeCAD.Vector(cyl_posx,0,-extra) )

    bl_posy0 = Gt2BeltClamp.CB_IW/2.
    bl_posy1 = Gt2BeltClamp.CB_IW/2. + Gt2BeltClamp.CB_W

    # block on top
    blt_p0 = FreeCAD.Vector(0, bl_posy0, -extra)
    blt_p1 = FreeCAD.Vector(Gt2BeltClamp.CB_L , bl_posy0, -extra)
    blt_p2 = FreeCAD.Vector(Gt2BeltClamp.CB_L , bl_posy1, -extra)
    blt_p3 = FreeCAD.Vector(0 , bl_posy1, -extra)
    shp_wire_blt = Part.makePolygon([blt_p0,blt_p1,blt_p2,blt_p3, blt_p0])
    shp_face_blt = Part.Face(shp_wire_blt)
    shpblt = shp_face_blt.extrude(FreeCAD.Vector(0,0,height))
    
    # block on bottom
    blb_p0 = FreeCAD.Vector(0 , -bl_posy1, -extra)
    blb_p1 = FreeCAD.Vector(Gt2BeltClamp.CB_L , -bl_posy1, -extra)
    blb_p2 = FreeCAD.Vector(Gt2BeltClamp.CB_L , -bl_posy0, -extra)
    blb_p3 = FreeCAD.Vector(0, -bl_posy0, -extra)
    shp_wire_blb = Part.makePolygon([blb_p0,blb_p1,blb_p2,blb_p3, blb_p0])
    shp_face_blb = Part.Face(shp_wire_blb)
    shpblb = shp_face_blb.extrude(FreeCAD.Vector(0,0,height))

    shp_clamp = shpcyl.multiFuse([shpblt, shpblb])

    vec_railaxis = fcfun.getvecofname(railaxis)
    vec_botnorm = fcfun.getvecofname(bot_norm)

    vrot = fcfun.calc_rot(vec_railaxis, vec_botnorm)

    shp_clamp.Placement.Rotation = vrot
    shp_clamp.Placement.Base = pos

    return shp_clamp
Пример #2
0
    def __init__(self,
                 fc_fro_ax,
                 fc_top_ax,
                 base_h = 2,
                 base_l = 0,
                 base_w = 0,
                 bolt_d = 3,
                 bolt_csunk = 0,
                 ref = 1,
                 pos = V0,
                 extra=1,
                 wfco = 1,
                 intol = 0,
                 name = 'belt_clamp' ):

        doc = FreeCAD.ActiveDocument
        self.name = name

        # if more tolerance is needed in the center
        cb_in_w = CB_IW + intol
        self.cb_in_w = cb_in_w
        cb_wall_w = CB_W - intol/2
        self.cb_wall_w = cb_wall_w

        # normalize and get the other base vector
        nfro_ax = DraftVecUtils.scaleTo(fc_fro_ax,1)
        nfro_ax_n = nfro_ax.negative()
        ntop_ax = DraftVecUtils.scaleTo(fc_top_ax,1)
        ntop_ax_n = ntop_ax.negative()
        nsid_ax = nfro_ax.cross(ntop_ax)

        clamponly_l = CB_L + CS + 2 * CCYL_R
        clamponly_w = max((cb_in_w+2*cb_wall_w), (2*CCYL_R))

        bolt2end = 0 # they will change in case they are used
        clamp2end = 0
        if base_h == 0 and bolt_d == 0:
            # No base
            base = 0
            base_l = 0
        else:
            base = 1
            if bolt_d > 0 :
                d_bolt = kcomp.D912[bolt_d]
                bolt_shank_r = d_bolt['shank_r_tol']
                bolt_head_r = d_bolt['head_r_tol']
                bolt_head_l = d_bolt['head_l']
                # there are bolt holes, calculate the extra length needed
                # from the end to the clamp / cylinder
                bolt2end = fcfun.get_bolt_end_sep(bolt_d,hasnut=0)
                # bolt space on one side
                clamp2end = 2 * bolt2end
                base_min_len = clamponly_l + 2 * clamp2end
                if base_l < base_min_len:
                    logger.debug("base_l too short, taking min len %s",
                                  base_min_len)
                    base_l = base_min_len
                else:
                    clamp2end = (base_l - clamponly_l) /2.
                    bolt2end = clamp2end / 2.
                if bolt_csunk > 0:
                    # there are countersunk holes for the bolts
                    if base_h == 0:
                        # minimum height:
                        base_h = bolt_csunk + bolt_head_l
                    else:
                        # check if there is enough base height
                        if base_h < bolt_csunk + bolt_head_l:
                            base_h = bolt_csunk + bolt_head_l
                            logger.debug("base_h too short,taking height %s",
                                  base_h)
                else:
                    if base_h < self.MIN_BASE_H:
                        base_h = self.MIN_BASE_H
                        logger.debug("taking base height %s",
                                  base_h)
            else: # No bolt
                bolt2end = 0
                if base_l < clamponly_l:
                    if base_l > 0:
                        logger.debug("base_l too short, Taking min len %s",
                                      clamponly_l) 
                    base_l = clamponly_l
                    clamp2end = 0
                else: #base larger than clamp
                    clamp2end = (base_l - clamponly_l) /2.
            if base_w == 0:
                base_w = clamponly_w
            elif base_w < clamponly_w:
                logger.debug("base_w too short, Taking min width %s",
                              clamponly_w)
                base_w = clamponly_w

        ###
        cencyl2froclamp = CB_L+CS+CCYL_R
        #vectors to references:
        # from the center of the cylinder to the front clamp
        vec_1to2 = DraftVecUtils.scale(nfro_ax,cencyl2froclamp)
        vec_2to1 = vec_1to2.negative()
        # from the front clamp to the front bolt
        vec_2to3 = DraftVecUtils.scale(nfro_ax, bolt2end)
        vec_3to2 = vec_2to3.negative()
        # Since not always there is a bolt, from the clamp
        vec_2to4 = DraftVecUtils.scale(nfro_ax, clamp2end)
        vec_4to2 = vec_2to4.negative()
        # from the center of the cylinder to the back bolt
        vec_5to1 = DraftVecUtils.scale(nfro_ax,CCYL_R) + vec_2to3
        vec_1to5 = vec_5to1.negative()
        # from the back bolt to the back end
        vec_6to1 = DraftVecUtils.scale(nfro_ax,CCYL_R) + vec_2to4
        vec_1to6 = vec_6to1.negative()

        # default values
        vec_tocencyl = V0
        vec_tofrontclamp = V0
        vec_tofrontbolt = V0
        vec_tofrontbase = V0
        vec_tobackbolt = V0
        vec_tobackbase = V0
        if ref==1: #ref on the center of the cylinder
            vec_tocencyl = V0
            vec_tofrontclamp = vec_1to2 
            vec_tofrontbolt = vec_1to2 + vec_2to3
            vec_tofrontbase = vec_1to2 + vec_2to4
            vec_tobackbolt = vec_1to5
            vec_tobackbase = vec_1to6
        elif ref==2: #ref on the front of the clamps
            vec_tocencyl = vec_2to1
            vec_tofrontclamp = V0
            vec_tofrontbolt = vec_2to3
            vec_tofrontbase = vec_2to4
            vec_tobackbolt = ve_2to1 + vec_1to5
            vec_tobackbase = ve_2to1 + vec_1to6
        elif ref == 3:
            if clamp2end == 0 or bolt2end == 0:
                logger.error('reference on the bolts, there are no bolts')
            else:
                vec_tocencyl = vec_3to2 + vec_2to1
                vec_tofrontclamp = vec_3to2
                vec_tofrontbolt = V0
                vec_tofrontbase = vec_2to3 #same as 3 to 4
                vec_tobackbolt = vec_3to2 + vec_2to1 + vec_1to5
                vec_tobackbase = vec_3to2 + vec_2to1 + vec_1to6
        elif ref == 4:
            if clamp2end == 0:
                logger.debug('reference at the end, same as the clamps')
            vec_tocencyl = vec_4to2 + vec_2to1
            vec_tofrontclamp = vec_4to2
            vec_tofrontbolt = vec_3to2 # same as 4 to 3
            vec_tofrontbase = V0
            vec_tobackbolt = vec_4to2 + vec_2to1 + vec_1to5
            vec_tobackbase = vec_4to2 + vec_2to1 + vec_1to6
        elif ref == 5:
            if clamp2end == 0 or bolt2end == 0:
                logger.error('reference on the bolts, there are no bolts')
            else:
                vec_tocencyl = vec_5to1
                vec_tofrontclamp = vec_5to1 + vec_1to2
                vec_tofrontbolt = vec_5to1 + vec_1to2 + vec_2to3
                vec_tofrontbase = vec_5to1 + vec_1to2 + vec_2to4
                vec_tobackbolt = V0
                vec_tobackbase = vec_3to2 #5to6: same as 3to2
        elif ref == 6:
            if clamp2end == 0:
                logger.debug('reference at the end, same as the clamps')
            vec_tocencyl = vec_6to1
            vec_tofrontclamp = vec_6to1 + vec_1to2
            vec_tofrontbolt = vec_6to1 + vec_1to2 + vec_2to3
            vec_tofrontbase = vec_6to1 + vec_1to2 + vec_2to4
            vec_tobackbolt = vec_2to3 # same as 6 to 5
            vec_tobackbase = V0
        else:
            logger.error('reference out of range')
          


        if extra == 0:
            extra_pos = V0
        else:
            extra_pos = DraftVecUtils.scale(ntop_ax, -extra)
        pos_extra = pos + extra_pos
        base_top_add = DraftVecUtils.scale(ntop_ax, base_h + extra)
        
        
        # total height of the clamp, including the base
        clamp_tot_h = C_H + base_h + extra
        # position of the clamp cylinder:
        clampcyl_pos = pos_extra + vec_tocencyl
        shp_cyl = fcfun.shp_cyl(CCYL_R, clamp_tot_h, ntop_ax, clampcyl_pos)
        # position of the clamp blocks, without going to the side axis
        clampblock_pos = pos_extra + vec_tofrontclamp
        clampblock_side_add = DraftVecUtils.scale(nsid_ax, 
                                                  (cb_in_w + cb_wall_w)/2.)
        clampblock_1_pos = clampblock_pos + clampblock_side_add
        clampblock_2_pos = clampblock_pos - clampblock_side_add
        shp_clampblock_1 = fcfun.shp_box_dir(box_w = cb_wall_w,
                                             box_d = CB_L,
                                             box_h = clamp_tot_h,
                                             fc_axis_h = ntop_ax,
                                             fc_axis_d = nfro_ax_n,
                                             cw=1, cd=0, ch=0,
                                             pos = clampblock_1_pos)
        shp_clampblock_2 = fcfun.shp_box_dir(box_w = cb_wall_w,
                                             box_d = CB_L,
                                             box_h = clamp_tot_h,
                                             fc_axis_h = ntop_ax,
                                             fc_axis_d = nfro_ax_n,
                                             cw=1, cd=0, ch=0,
                                             pos = clampblock_2_pos)

        shp_clamp = shp_cyl.multiFuse([shp_clampblock_1, shp_clampblock_2])


        #position of the base, we will take it on the point 4 and make it not 
        # centered
        if base == 1:
            base_pos = pos_extra + vec_tofrontbase 
            shp_base = fcfun.shp_box_dir(box_w = base_w,
                                         box_d = base_l,
                                         box_h = base_h + extra,
                                         fc_axis_h = ntop_ax,
                                         fc_axis_d = nfro_ax_n,
                                         cw=1, cd=0, ch=0,
                                         pos = base_pos)
            if base_l > clamponly_l: # chamfer
                shp_base = fcfun.shp_filletchamfer_dir (shp_base,
                                              fc_axis=ntop_ax,
                                              fillet=1, radius= 2)

            # shape of the bolt holes, if there are
            if bolt_d > 0:
                pos_bolt_front = pos_extra + vec_tofrontbolt + base_top_add
                pos_bolt_back = pos_extra + vec_tobackbolt + base_top_add
                if bolt_csunk > 0 :
                    shp_bolt_front = fcfun.shp_bolt_dir(
                                              r_shank = bolt_shank_r,
                                              l_bolt = base_h + extra,
                                              r_head = bolt_head_r,
                                              l_head = bolt_head_l,
                                              support=0,
                                              fc_normal = ntop_ax_n,
                                              pos=pos_bolt_front)
                    shp_bolt_back = fcfun.shp_bolt_dir(
                                              r_shank = bolt_shank_r,
                                              l_bolt = base_h + extra,
                                              r_head = bolt_head_r,
                                              l_head = bolt_head_l,
                                              support=0,
                                              fc_normal = ntop_ax_n,
                                              pos=pos_bolt_back)
                else: # no head, just a cylinder:
                    shp_bolt_front = fcfun.shp_cylcenxtr (
                                              r = bolt_shank_r,
                                              h = base_h + extra,
                                              normal = ntop_ax_n,
                                              ch = 0,
                                              xtr_top=1, xtr_bot=1,
                                              pos = pos_bolt_front)
                    shp_bolt_back = fcfun.shp_cylcenxtr (
                                              r = bolt_shank_r,
                                              h = base_h + extra,
                                              normal = ntop_ax_n,
                                              ch = 0,
                                              xtr_top=1, xtr_bot=1,
                                              pos = pos_bolt_back)


                # fuse the bolts:
                shp_bolts = shp_bolt_front.fuse(shp_bolt_back)
                shp_base = shp_base.cut(shp_bolts)
            shp_clamp = shp_base.fuse(shp_clamp)

              
 

        doc.recompute()
        shp_clamp = shp_clamp.removeSplitter()
        self.shp = shp_clamp

        self.wfco = wfco
        if wfco == 1:
            # a freeCAD object is created
            fco_clamp = doc.addObject("Part::Feature", name )
            fco_clamp.Shape = shp_clamp
            self.fco = fco_clamp
def nemamotor_holder():

    #  --------------- step 01 ---------------------------
    #  rectangular cuboid with basic dimensions
    #
    #                    Z
    #                    :
    #                    :
    #             :.....tot_w.......
    #             :______:__________:
    #             /                /|
    #            /                / |
    #           /                /  |
    #          /                /   |
    #       ../________________/    |
    #       : |                |    |
    #       : |                |    |...............Y
    #       : |                |   /     .
    #  tot_h: |                |  /     . tot_d
    #       : |                | /     .
    #       :.|________________|/......
    #                .
    #               .
    #              X
    #

    # creates the shape, you don't see it yet on FreeCAD Gui
    # centered along axis Y
    shp01 = fcfun.shp_boxcen(tot_d, tot_w, tot_h, cy=True)
    # creates a freecad object from the shape, to see it in FreeCAD Gui,
    # not necessary, but illustrative for this tutorial
    fcd01 = fcfun.add_fcobj(shp01, 'box01')

    #  --------------- step 02 ---------------------------
    #  chamfering the 4 vertical edges (marked with H)
    #
    #                    Z
    #                    :
    #                    :
    #             :.....tot_w.......
    #             :______:__________:
    #             /                /H chamfering
    #            /                / H
    #           /                /  H
    #          /                /   H
    #       ../________________/    H
    #       : H                H    H
    #       : H                H    H...............Y
    #       : H                H   /     .
    #  tot_h: H                H  /     . tot_d
    #       : H                H /     .
    #       :.H________________H/......
    #                .
    #               .
    #              X
    #

    fcd02 = fcfun.filletchamfer(
        fcd01,
        e_len=tot_h,
        name='step02',
        fillet=0,
        radius=chmf_r,
        axis='z'  # axis to fillet
    )

    #  --------------- step 03 ---------------------------
    #  Horizontal chamfering the top edge to make a 'triangular' reinforcement
    #
    #      Z
    #      :
    #      :___            . chmf_pos
    #      |    \
    #      |      \
    #      |        \
    #      |          \
    #      |            \
    #      |              \
    #      |________________.....X
    #
    #
    # the radius is the smaller part
    chmf_reinf_r = min(tot_d - wall_thick, tot_h - motor_thick)

    fcd03 = fcfun.filletchamfer(
        fcd02,
        e_len=0,
        name='step03',
        fillet=0,
        radius=chmf_reinf_r,
        axis='y',  # axis to fillet
        xpos_chk=1,
        zpos_chk=1,
        xpos=tot_d,  # position of the edge in x
        zpos=tot_h  # position of the edge in z
    )

    #  --------------- step 04 ---------------------------
    #  Hole for the motor
    #
    #                Z                      Z
    #                :                      :
    #        ________:_________             :__
    #       | |              | |            | :  \
    #       | |              | |            | :    \
    #       | |              | |            | :      \
    #       | |              | |            | :        \
    #       | |              | |            | :          \
    #       | |              | |            | :            \
    #       |_|______________|_|            | :..............\...motor_thick
    #       |_|______________|_|..Y         |_________________\..X
    #       : :                             : :
    #       : :                             : :
    #        reinf_thick                     wall_thick

    pos04 = FreeCAD.Vector(wall_thick, 0, motor_thick)
    shp04cut = fcfun.shp_boxcen(tot_d,
                                tot_w - 2 * reinf_thick,
                                tot_h,
                                cy=True,
                                pos=pos04)
    # creates a freecad object from the shape, to see it in FreeCAD Gui,
    # not necessary, but illustrative for this tutorial
    fcd04cut = fcfun.add_fcobj(shp04cut, 'motorhole')
    # difference (cut) of fcd01 and fcd02cut
    fcd04 = doc.addObject("Part::Cut", 'step04')
    fcd04.Base = fcd03
    fcd04.Tool = fcd04cut
    # the shape
    shp04 = fcd04.Shape

    doc.recompute()

    #  --------------- step 05 ---------------------------
    #  Holes for motor bolts, and the central hole
    #
    #    ____________________...............................>Y
    #   | ___________________|.. wall_thick
    #   | |                | |.. motor_xtr_space.....
    #   | | O     __     O | | --                   :motor_w/2
    #   | |    /      \    | |   .                  :
    #   | |   |   1    |   | |   .+ motor_bolt_sep ---
    #   | |    \      /    | |   .
    #   | | O     __     O | | --
    #   |_|________________|_| ..... wall_thick
    #             :        : :
    #             :         reinf_thick
    #       :     X      :
    #       :            :
    #       :            :
    #       motor_bolt_sep

    # position of the motor axis z=-1 to do the cut
    pos05 = FreeCAD.Vector(wall_thick + motor_xtr_space + motor_w / 2., 0, -1)
    shp05cenhole = fcfun.shp_cyl(
        r=motor_hole_r,
        h=motor_thick + 2,  # for the cut
        normal=fcfun.VZ,
        pos=pos05)
    # make a list of the bolt holes
    boltholes_shp_list = []
    # the four motor holes
    for x_side in [-1, 1]:
        for y_side in [-1, 1]:
            hole_pos = pos05 + FreeCAD.Vector(x_side * motor_bolt_sep / 2.,
                                              y_side * motor_bolt_sep / 2., 0)
            shp05bolthole = fcfun.shp_cyl(
                r=motor_bolt_r_tol,
                h=motor_thick + 2,  # for the cut
                normal=fcfun.VZ,
                pos=hole_pos)
            boltholes_shp_list.append(shp05bolthole)
    # fuse the 5 holes
    shp05cut = shp05cenhole.multiFuse(boltholes_shp_list)
    # not necessary to create a FreeCAD object, but illustrative for tutorial
    fcd05cut = fcfun.add_fcobj(shp05cut, 'boltholes')
    # difference (cut) of fcd04 and fcd05cut
    fcd05 = doc.addObject("Part::Cut", 'step05')
    fcd05.Base = fcd04
    fcd05.Tool = fcd05cut
    # the shape
    shp05 = fcd05.Shape

    doc.recompute()

    #  --------------- step 06 ---------------------------
    #  Rails to attach the holder
    #
    #            Z
    #            :
    #    ________:_________
    #   | |              | |
    #   | | ||        || | |-----------------------
    #   | | ||        || | |                       :
    #   | | ||        || | |                       +motor_max_h
    #   | | ||        || | |                       :
    #   | | ||        || | |-------                :
    #   |_|______________|_|.......:+ motor_min_h..:
    #   |_|______________|_|....:+motor_thick............Y
    #        :         :
    #        :.........:
    #             bolt_wall_sep

    shp06_cut_list = []
    for y_side in [-1, 1]:
        # the rails
        step06_bot_pos = FreeCAD.Vector(-1, y_side * bolt_wall_sep / 2.,
                                        motor_thick + motor_min_h)
        shp06_rail = fcfun.shp_boxcen(wall_thick + 2,
                                      2 * bolt_wall_r_tol,
                                      motor_max_h - motor_min_h,
                                      cy=True,
                                      pos=step06_bot_pos)
        shp06_cut_list.append(shp06_rail)
        # bottom end circle:
        shp06_hole = fcfun.shp_cyl(
            r=bolt_wall_r_tol,
            h=wall_thick + 2,  # for the cut
            normal=fcfun.VX,
            pos=step06_bot_pos)
        shp06_cut_list.append(shp06_hole)
        step06_top_pos = FreeCAD.Vector(-1, y_side * bolt_wall_sep / 2.,
                                        motor_thick + motor_max_h)
        # top end circle:
        shp06_hole = fcfun.shp_cyl(
            r=bolt_wall_r_tol,
            h=wall_thick + 2,  # for the cut
            normal=fcfun.VX,
            pos=step06_top_pos)

        shp06_cut_list.append(shp06_hole)

    # fuse the rails
    shp06cut = fcfun.fuseshplist(shp06_cut_list)
    # not necessary to create a FreeCAD object, but illustrative for tutorial
    fcd06cut = fcfun.add_fcobj(shp06cut, 'rails')
    # difference (cut) of fcd04 and fcd05cut
    fcd06 = doc.addObject("Part::Cut", 'step06')
    fcd06.Base = fcd05
    fcd06.Tool = fcd06cut
    # the shape
    shp06 = fcd06.Shape

    doc.recompute()

    return fcd06
Пример #4
0
    def __init__(self,
                 size,
                 length,
                 shaft_l,
                 circle_r,
                 circle_h,
                 name="nemamotor",
                 chmf=1,
                 rshaft_l=0,
                 bolt_depth=3,
                 bolt_out=2,
                 container=1,
                 normal=VZ,
                 pos=V0):

        doc = FreeCAD.ActiveDocument
        self.base_place = (0, 0, 0)
        self.size = size
        self.width = kcomp.NEMA_W[size]
        self.length = length
        self.shaft_l = shaft_l
        self.circle_r = circle_r
        self.circle_h = circle_h
        self.chmf = chmf
        self.rshaft_l = rshaft_l
        self.bolt_depth = bolt_depth
        self.bolt_out = bolt_out
        self.container = container
        nnormal = DraftVecUtils.scaleTo(normal, 1)
        self.normal = nnormal
        self.pos = pos
        nemabolt_d = kcomp.NEMA_BOLT_D[size]
        self.nemabolt_d = nemabolt_d
        mtol = kcomp.TOL - 0.1

        lnormal = DraftVecUtils.scaleTo(nnormal, length)
        neg_lnormal = DraftVecUtils.neg(lnormal)

        # motor shape
        v1 = FreeCAD.Vector(self.width / 2. - chmf, self.width / 2., 0)
        v2 = FreeCAD.Vector(self.width / 2., self.width / 2. - chmf, 0)
        motorwire = fcfun.wire_sim_xy([v1, v2])
        # motor wire normal is VZ
        # DraftVecUtils doesnt work as well
        # rot = DraftVecUtils.getRotation(VZ, nnormal)
        # the order matter VZ, nnormal. It seems it doent matter VZ or VZN
        # this is valid:
        #rot = DraftGeomUtils.getRotation(VZ,nnormal)
        #print rot
        rot = FreeCAD.Rotation(VZ, nnormal)
        print rot
        motorwire.Placement.Rotation = rot
        motorwire.Placement.Base = pos
        motorface = Part.Face(motorwire)
        shp_motorbox = motorface.extrude(neg_lnormal)
        # shaft shape
        if rshaft_l == 0:  # no rear shaft
            shp_shaft = fcfun.shp_cyl(r=kcomp.NEMA_SHAFT_D[size] / 2.,
                                      h=shaft_l,
                                      normal=nnormal,
                                      pos=pos)
        else:
            rshaft_posend = DraftVecUtils.scaleTo(neg_lnormal,
                                                  rshaft_l + length)
            shp_shaft = fcfun.shp_cyl(r=kcomp.NEMA_SHAFT_D[size] / 2.,
                                      h=shaft_l + rshaft_l + length,
                                      normal=nnormal,
                                      pos=pos + rshaft_posend)

        shp_motorshaft = shp_motorbox.fuse(shp_shaft)
        # Bolt holes
        # AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
        # There is something wrong with the position of these bolts
        #        bhole00_pos = FreeCAD.Vector(-kcomp.NEMA_BOLT_SEP[size]/2,
        #                                     -kcomp.NEMA_BOLT_SEP[size]/2,
        #                                     -bolt_depth) + pos
        #        bhole01_pos = FreeCAD.Vector(-kcomp.NEMA_BOLT_SEP[size]/2,
        #                                      kcomp.NEMA_BOLT_SEP[size]/2,
        #                                     -bolt_depth) + pos
        #        bhole10_pos = FreeCAD.Vector( kcomp.NEMA_BOLT_SEP[size]/2,
        #                                     -kcomp.NEMA_BOLT_SEP[size]/2,
        #                                     -bolt_depth) + pos
        #        bhole11_pos = FreeCAD.Vector( kcomp.NEMA_BOLT_SEP[size]/2,
        #                                      kcomp.NEMA_BOLT_SEP[size]/2,
        #                                     -bolt_depth) + pos
        #        bhole00_posrot = DraftVecUtils.rotate(bhole00_pos, rot.Angle, rot.Axis)
        #        bhole01_posrot = DraftVecUtils.rotate(bhole01_pos, rot.Angle, rot.Axis)
        #        bhole10_posrot = DraftVecUtils.rotate(bhole10_pos, rot.Angle, rot.Axis)
        #        bhole11_posrot = DraftVecUtils.rotate(bhole11_pos, rot.Angle, rot.Axis)
        #        shp_bolt00 = fcfun.shp_cyl (
        #                                   r=kcomp.NEMA_BOLT_D[size]/2.+kcomp.TOL/2.,
        #                                   h=bolt_depth + shaft_l,
        #                                   normal = nnormal,
        #                                   pos= bhole00_posrot)
        #        shp_bolt01 = fcfun.shp_cyl (
        #                                   r=kcomp.NEMA_BOLT_D[size]/2.+kcomp.TOL/2.,
        #                                   h=bolt_depth + shaft_l,
        #                                   normal = nnormal,
        #                                   pos= bhole01_posrot)
        #        shp_bolt10 = fcfun.shp_cyl (
        #                                   r=kcomp.NEMA_BOLT_D[size]/2.+kcomp.TOL/2.,
        #                                   h=bolt_depth + shaft_l,
        #                                   normal = nnormal,
        #                                   pos= bhole10_posrot)
        #        shp_bolt11 = fcfun.shp_cyl (
        #                                   r=kcomp.NEMA_BOLT_D[size]/2.+kcomp.TOL/2.,
        #                                   h=bolt_depth + shaft_l,
        #                                   normal = nnormal,
        #                                   pos= bhole11_posrot)
        #        shp_bolts = shp_bolt00.multiFuse([shp_bolt01, shp_bolt10, shp_bolt11])

        # list of shapes to make a fusion of the container
        shp_contfuselist = []
        #        shp_contfuselist.append(shp_bolts)

        b2hole00_pos = FreeCAD.Vector(-kcomp.NEMA_BOLT_SEP[size] / 2,
                                      -kcomp.NEMA_BOLT_SEP[size] / 2,
                                      -bolt_depth)
        b2hole01_pos = FreeCAD.Vector(-kcomp.NEMA_BOLT_SEP[size] / 2,
                                      kcomp.NEMA_BOLT_SEP[size] / 2,
                                      -bolt_depth)
        b2hole10_pos = FreeCAD.Vector(kcomp.NEMA_BOLT_SEP[size] / 2,
                                      -kcomp.NEMA_BOLT_SEP[size] / 2,
                                      -bolt_depth)
        b2hole11_pos = FreeCAD.Vector(kcomp.NEMA_BOLT_SEP[size] / 2,
                                      kcomp.NEMA_BOLT_SEP[size] / 2,
                                      -bolt_depth)

        b2hole00 = addBolt(r_shank=nemabolt_d / 2. + mtol / 2.,
                           l_bolt=bolt_out + bolt_depth,
                           r_head=kcomp.D912_HEAD_D[nemabolt_d] / 2. +
                           mtol / 2.,
                           l_head=kcomp.D912_HEAD_L[nemabolt_d] + mtol,
                           hex_head=0,
                           extra=1,
                           support=1,
                           headdown=0,
                           name="b2hole00")

        b2hole01 = Draft.clone(b2hole00)
        b2hole01.Label = "b2hole01"
        b2hole10 = Draft.clone(b2hole00)
        b2hole10.Label = "b2hole10"
        b2hole11 = Draft.clone(b2hole00)
        b2hole11.Label = "b2hole11"

        b2hole00.ViewObject.Visibility = False
        b2hole01.ViewObject.Visibility = False
        b2hole10.ViewObject.Visibility = False
        b2hole11.ViewObject.Visibility = False

        b2hole00.Placement.Base = b2hole00_pos
        b2hole01.Placement.Base = b2hole01_pos
        b2hole10.Placement.Base = b2hole10_pos
        b2hole11.Placement.Base = b2hole11_pos

        # it doesnt work if dont recompute here! probably the clones
        doc.recompute()

        b2holes_list = [b2hole00, b2hole01, b2hole10, b2hole11]
        # not an efficient way, either use shapes or fco, but not both
        shp_b2holes = b2hole00.Shape.multiFuse(
            [b2hole01.Shape, b2hole10.Shape, b2hole11.Shape])
        #Part.show(shp_b2holes)

        b2holes = doc.addObject("Part::MultiFuse", "b2holes")
        b2holes.Shapes = b2holes_list
        b2holes.ViewObject.Visibility = False

        shp_b2holes.Placement.Base = pos
        shp_b2holes.Placement.Rotation = rot
        shp_contfuselist.append(shp_b2holes)

        # Circle on the base of the shaft
        if circle_r == 0:
            calcircle_r = kcomp.NEMA_BOLT_SEP[size] / 2.
        else:
            calcircle_r = circle_r
        if circle_h != 0:
            shp_circle = fcfun.shp_cyl(
                r=calcircle_r,
                h=circle_h + 1,  #supperposition for union
                normal=nnormal,
                #supperposition for union
                pos=pos - nnormal)
            # fmotor: fused motor
            shp_fmotor = shp_motorshaft.fuse(shp_circle)
        else:
            shp_fmotor = shp_motorshaft

        #fmotor = doc.addObject("Part::Feature", "fmotor")
        #fmotor.Shape = shp_fmotor

        #shp_motor = shp_fmotor.cut(shp_bolts)
        shp_motor = shp_fmotor.cut(shp_b2holes)
        #Part.show(shp_bolts)

        # container
        if container == 1:
            # 2*TOL to make sure it fits
            v1 = FreeCAD.Vector(self.width / 2. - chmf / 2. + 2 * kcomp.TOL,
                                self.width / 2. + 2 * kcomp.TOL, 0)
            v2 = FreeCAD.Vector(self.width / 2. + 2 * kcomp.TOL,
                                self.width / 2. - chmf / 2. + 2 * kcomp.TOL, 0)
            cont_motorwire = fcfun.wire_sim_xy([v1, v2])
            cont_motorwire.Placement.Rotation = rot
            cont_motorwire.Placement.Base = pos
            cont_motorface = Part.Face(cont_motorwire)
            shp_contmotor_box = cont_motorface.extrude(neg_lnormal)

            # the container is much wider than the shaft

            if rshaft_l == 0:  # no rear shaft
                shp_contshaft = fcfun.shp_cyl(r=calcircle_r + kcomp.TOL,
                                              h=shaft_l + 1,
                                              normal=nnormal,
                                              pos=pos - nnormal)
            else:
                shp_contshaft = fcfun.shp_cyl(r=calcircle_r + kcomp.TOL,
                                              h=shaft_l + rshaft_l + length,
                                              normal=nnormal,
                                              pos=pos + rshaft_posend)
            shp_contfuselist.append(shp_contshaft)
            shp_contmotor = shp_contmotor_box.multiFuse(shp_contfuselist)
        else:
            shp_contmotor = shp_motor  # we put the same shape

        doc.recompute()

        #fco_motor = doc.addObject("Part::Cut", name)
        #fco_motor.Base = fmotor
        #fco_motor.Tool = b2holes
        fco_motor = doc.addObject("Part::Feature", name)
        fco_motor.Shape = shp_motor

        self.fco = fco_motor
        self.shp_cont = shp_contmotor
        #Part.show(shp_contmotor)

        doc.recompute()
Пример #5
0
def placa_con_tornillos_fun():
    # generamos una placa de dimensiones 100x100x10
    shp_placa = fcfun.shp_box_dir(box_w=100.,
                                  box_d=100.,
                                  box_h=10.,
                                  fc_axis_w=VX,
                                  fc_axis_d=VY,
                                  fc_axis_h=VZ,
                                  cw=0, cd=0, ch=0,
                                  pos=V0)

    # añadimos un tornillo en la posición 1x1x1
    shp_bolt1 = fcfun.shp_cyl(3., 10., normal=VZ, pos=FreeCAD.Vector(10, 10, 0))

    # sustraemos la forma del primer tornillo de la placa
    shp_placa_1hole = shp_placa.cut(shp_bolt1)

    # añadimos un tornillo en la posición 9x1x1
    shp_bolt2 = fcfun.shp_cyl(3., 10., normal=VZ, pos=FreeCAD.Vector(90, 10, 0))

    # sustraemos la forma del segundo tornillo de la placa
    shp_placa_2hole = shp_placa_1hole.cut(shp_bolt2)

    # añadimos un tornillo en la posición 9x9x1
    shp_bolt3 = fcfun.shp_cyl(3., 10., normal=VZ, pos=FreeCAD.Vector(90, 90, 0))

    # sustraemos la forma del tercero tornillo de la placa
    shp_placa_3hole = shp_placa_2hole.cut(shp_bolt3)

    # añadimos un tornillo en la posición 1x9x1
    shp_bolt4 = fcfun.shp_cyl(3., 10., normal=VZ, pos=FreeCAD.Vector(10, 90, 0))

    # sustraemos la forma del cuarto tornillo de la placa
    shp_placa_4hole = shp_placa_3hole.cut(shp_bolt4)

    # convertimos la placa con cuatro tornillos en objeto
    placa_4hole = FreeCAD.ActiveDocument.addObject("Part::Feature", "Placa_perforada")
    placa_4hole.Shape = shp_placa_4hole

    # generamos cuatro tornillos individualmente y los convertimos a objetos individualmente
    tornillo_1 = fc_clss.Din912Bolt(metric=3, shank_l=10,
                                    shank_l_adjust=0,
                                    shank_out=0,
                                    head_out=0,
                                    axis_h=-VZ, axis_d=None, axis_w=None,
                                    pos_h=0, pos_d=0, pos_w=0,
                                    pos=V0 + FreeCAD.Vector(10, 10, 10),
                                    model_type=0,
                                    name='bolt1')
    tornillo_2 = fc_clss.Din912Bolt(metric=3, shank_l=10,
                                    shank_l_adjust=0,
                                    shank_out=0,
                                    head_out=0,
                                    axis_h=-VZ, axis_d=None, axis_w=None,
                                    pos_h=0, pos_d=0, pos_w=0,
                                    pos=V0 + FreeCAD.Vector(90, 10, 10),
                                    model_type=0,
                                    name='bolt2')
    tornillo_3 = fc_clss.Din912Bolt(metric=3, shank_l=10,
                                    shank_l_adjust=0,
                                    shank_out=0,
                                    head_out=0,
                                    axis_h=-VZ, axis_d=None, axis_w=None,
                                    pos_h=0, pos_d=0, pos_w=0,
                                    pos=V0 + FreeCAD.Vector(90, 90, 10),
                                    model_type=0,
                                    name='bolt3')
    tornillo_4 = fc_clss.Din912Bolt(metric=3, shank_l=10,
                                    shank_l_adjust=0,
                                    shank_out=0,
                                    head_out=0,
                                    axis_h=-VZ, axis_d=None, axis_w=None,
                                    pos_h=0, pos_d=0, pos_w=0,
                                    pos=V0 + FreeCAD.Vector(10, 90, 10),
                                    model_type=0,
                                    name='bolt4')
Пример #6
0
shp_filter_basehole = shp_filter_base.cut(shp_filter_holes)


# the support part, that is fixed on the rail
shp_sup_box = fcfun.shp_boxcen(
                    x=FILT_BASE_L,
                    # Tolerance to avoid being too close to the moving part
                    y=RAIL_SUP_D-kcomp.TOL, 
                    z=RAIL_SUP_H,
                    cx=1, cy=0, cz=0,
                    pos=V0)


# Support bolts
bolt_pos0 = FreeCAD.Vector(-BOLT_SEP_X/2., -1, BOLT_POS_Z)
shp_bolt0 = fcfun.shp_cyl(r=kcomp.M4_SHANK_R_TOL, h=RAIL_SUP_D+1, 
                       normal = VY, pos=bolt_pos0)
bolt_pos1 = FreeCAD.Vector(BOLT_SEP_X/2., -1, BOLT_POS_Z)
shp_bolt1 = fcfun.shp_cyl(r=kcomp.M4_SHANK_R_TOL, h=RAIL_SUP_D+1, 
                       normal = VY, pos=bolt_pos1)
# Support bolt heads
bolth_pos0 = FreeCAD.Vector(-BOLT_SEP_X/2., BOLT_SHANK_THICK, BOLT_POS_Z)
shp_bolth0 = fcfun.shp_cyl(r=kcomp.M4_HEAD_R_TOL+0.5,
                           h=RAIL_SUP_D-BOLT_SHANK_THICK+1, 
                           normal = VY, pos=bolth_pos0)
bolth_pos1 = FreeCAD.Vector(BOLT_SEP_X/2., BOLT_SHANK_THICK, BOLT_POS_Z)
shp_bolth1 = fcfun.shp_cyl(r=kcomp.M4_HEAD_R_TOL+0.5,
                           h=RAIL_SUP_D-BOLT_SHANK_THICK+1, 
                           normal = VY, pos=bolth_pos1)

shp_tbolt0 = shp_bolt0.fuse(shp_bolth0)
shp_tbolt1 = shp_bolt1.fuse(shp_bolth1)