def __init__(self, base_h, midblock, name): doc = FreeCAD.ActiveDocument self.base_place = (0,0,0) # Clamp base self.CBASE_H = base_h # divides how much is rail and how much is wall # It has to be greater than 1. If it is 1, there is no wall. # if it is 2. Half is wall, half is indent self.CBASE_RAIL_DIV = 1.6 #2.0 self.CBASE_RAIL = self.CBASE_H / self.CBASE_RAIL_DIV # rail for the base # the part that is wall, divided by 2, because one goes at the bottom # and the other on top # rail for the base self.CBASE_WALL = (self.CBASE_H - self.CBASE_RAIL)/2.0 # Indentation, if midblock == 0, the Indentation is negative, which # means it will be outward, otherwise, inward self.CBASERAILIND = self.CBASE_RAIL/3.0 self.midblock = midblock # Width of the interior/middle clamp blocks self.CB_MW = midblock * self.CB_W if midblock == 0: self.CBASE_W = self.CB_IW + 2 * self.CB_W self.CBASERAILIND_SIG = - self.CBASERAILIND # Since the indentation is outwards, we have to add it self.TotW = self.CBASE_W + 2 * self.CBASERAILIND # external indent, so all the internal elements have to have this # nternal offset. In Y axis self.extind = self.CBASERAILIND else: self.CBASE_W = 2 * self.CB_IW + 2 * self.CB_W + self.CB_MW self.CBASERAILIND_SIG = self.CBASERAILIND # Since the indentation is inward, it is just the base self.TotW = self.CBASE_W # no external indent, so the internal elements don't have to have # this internal offset self.extind = 0 gt2_clamp_list = [] # we make it using points-plane and extrusions #gt2_base =addBox (self.CBASE_L, self.CBASE_W, self.CBASE_H, "gt2_base") gt2_cb_1 = addBox (self.CB_L, self.CB_W, self.C_H+1, name + "_cb1") gt2_cb_1.Placement.Base = FreeCAD.Vector (self.CBASE_L-self.CB_L, self.extind, self.CBASE_H-1) gt2_clamp_list.append (gt2_cb_1) if midblock > 0: gt2_cb_2 = addBox (self.CB_L, self.CB_MW, self.C_H+1, name + "_cb2") gt2_cb_2.Placement.Base = FreeCAD.Vector (self.CBASE_L-self.CB_L, self.CB_W + self.CB_IW + self.extind, self.CBASE_H-1) gt2_clamp_list.append (gt2_cb_2) gt2_cb_3 = addBox (self.CB_L, self.CB_W, self.C_H + 1, name + "_cb3") gt2_cb_3.Placement.Base = FreeCAD.Vector (self.CBASE_L-self.CB_L, self.CBASE_W - self.CB_W + self.extind, self.CBASE_H-1) gt2_clamp_list.append (gt2_cb_3) gt2_cyl = addCyl (self.CCYL_R, self.C_H + 1, name + "_cyl") gt2_cyl.Placement.Base = FreeCAD.Vector (self.CCYL_R, self.CBASE_W/2 + self.extind, self.CBASE_H-1) gt2_clamp_list.append (gt2_cyl) # base # calling to the method that gets a list of the points to make # the polygon of the base #gt2_base_list = self.get_base_list_v() # doing this because the carriage is already printed, so I am going # to make the base smaller to fit. CHANGE to the upper sentence gt2_base_list = self.get_base_list_v(offs_y = -TOL/2, offs_z = - TOL) """ gt2_base_plane_yz = Part.makePolygon(gt2_base_list) gt2_base = gt2_base_plane_xy.extrude(FreeCAD.Vector(self.CBASE_L,0,0)) """ gt2_base_plane_yz = doc.addObject("Part::Polygon", name + "base_plane_yz") gt2_base_plane_yz.Nodes = gt2_base_list gt2_base_plane_yz.Close = True gt2_base = doc.addObject("Part::Extrusion", name + "extr_base") gt2_base.Base = gt2_base_plane_yz gt2_base.Dir = (self.CBASE_L,0,0) gt2_base.Solid = True gt2_clamp_list.append(gt2_base) gt2_clamp_basic = doc.addObject("Part::MultiFuse", name + "clamp_base") gt2_clamp_basic.Shapes = gt2_clamp_list # creation of the same base, but with a little offset to be able to # cut the piece where it will be inserted #gt2_baseof_list = self.get_base_list_v(offs_y = TOL, offs_z = TOL/2.0) # CHANGE TO THE UPPER SENTENCE gt2_baseof_list = self.get_base_list_v(offs_y = TOL, offs_z = 0) gt2_baseof_plane_yz = doc.addObject("Part::Polygon", name + "_baseof_plane_yz") gt2_baseof_plane_yz.Nodes = gt2_baseof_list gt2_baseof_plane_yz.Close = True gt2_baseof = doc.addObject("Part::Extrusion", name + "_baseof") gt2_baseof.Base = gt2_baseof_plane_yz gt2_baseof.Dir = (self.CBASE_L,0,0) gt2_baseof.Solid = True self.fco_cont = gt2_baseof # hole for the leadscrew bolt # the head is longer because it can be inserted deeper into the piece # so a shorter bolt will be needed gt2_base_lscrew = addBolt (kcomp.M3_SHANK_R_TOL, self.CBASE_L, kcomp.M3_HEAD_R_TOL, 2.5*kcomp.M3_HEAD_L, extra = 1, support = 0, name= name + "_base_lscrew") gt2_base_lscrew.Placement.Base = FreeCAD.Vector (self.CBASE_L, self.CBASE_W/2.0 + self.extind, self.CBASE_H/2.0) gt2_base_lscrew.Placement.Rotation = FreeCAD.Rotation (VY, -90) # ------------ hole for a nut, also M3, for the leadscrew gt2_base_lscrew_nut = doc.addObject("Part::Prism", name + "_base_lscrew_nut") gt2_base_lscrew_nut.Polygon = 6 gt2_base_lscrew_nut.Circumradius = kcomp.M3_NUT_R_TOL gt2_base_lscrew_nut.Height = kcomp.M3NUT_HOLE_H gt2_base_lscrew_nut.Placement.Rotation = \ gt2_base_lscrew.Placement.Rotation # + TOL so it will be a little bit higher, so more room gt2_base_lscrew_nut.Placement.Base = FreeCAD.Vector ( #(self.CBASE_L-kcomp.M3_HEAD_L)/2.0 - kcomp.M3NUT_HOLE_H/2.0, self.NUT_HOLE_EDGSEP, self.CBASE_W/2.0 + self.extind, self.CBASE_H/2.0 + TOL) gt2_base_lscrew_nut.Placement.Rotation = FreeCAD.Rotation (VY, 90) # ------------ hole to reach out the nut hole # X is the length: M3NUT_HOLE_H. Y is the width. M3_2APOT_TOL gt2_base_lscrew_nut2 = addBox (kcomp.M3NUT_HOLE_H, kcomp.M3_2APOT_TOL, self.CBASE_H/2.0 + TOL, name + "_base_lscrew_nut2") gt2_base_lscrew_nut2.Placement.Base = ( #((self.CBASE_L-kcomp.M3_HEAD_L) - kcomp.M3NUT_HOLE_H)/2.0, self.NUT_HOLE_EDGSEP, (self.CBASE_W - kcomp.M3_2APOT_TOL)/2.0 + self.extind, 0) gt2_base_holes_l = [ gt2_base_lscrew, gt2_base_lscrew_nut, gt2_base_lscrew_nut2] # fuse the holes gt2_clamp_holes = doc.addObject("Part::MultiFuse", name + "_clamp_hole") gt2_clamp_holes.Shapes = gt2_base_holes_l # Substract the holes gt2_clamp = doc.addObject("Part::Cut", name) gt2_clamp.Base = gt2_clamp_basic gt2_clamp.Tool = gt2_clamp_holes self.fco = gt2_clamp # the FreeCad Object
sk12_bl.Label = "sk12_bl" sk12_bl.Placement.Base = FreeCAD.Vector (-rod_y_sep/2.0, kcit.CIT_Y - kcit.ALU_W, kcit.ALU_W) # ------------------ Y Shafts -------------------------------------- # rod_y_off is defined abover # the length of the rod inside the rod holders rod_y_use = 2*rod_y_off + kcomp.SK12['L'] # the height of the Y rod rod_y_pos_z = sk12_fr.Placement.Base.z + h_sk12_fr.HoleH rod_y_l = addCyl(r= kcit.ROD_D/2.0, h=kcit.ROD_Y_L, name= "rod_y_l") rod_y_l.Placement.Base = FreeCAD.Vector (-rod_y_sep/2.0, alu_x_bm_ypos - rod_y_off, rod_y_pos_z) rod_y_l.Placement.Rotation = FreeCAD.Rotation (VX,-90) rod_y_r = addCyl(r= kcit.ROD_D/2.0, h=kcit.ROD_Y_L, name= "rod_y_r") rod_y_r.Placement.Base = FreeCAD.Vector ( rod_y_sep/2.0, alu_x_bm_ypos - rod_y_off, rod_y_pos_z) rod_y_r.Placement.Rotation = FreeCAD.Rotation (VX,-90) """ lm_bearing = fcfun.addCylHole (r_ext = kcomp.LMEUU_D[kcit.ROD_Di]/2.0, r_int = kcit.ROD_D/2.0,
def __init__(self, size, name, hole_x=1, cx=0, cy=0): self.size = size self.name = name self.cx = cx self.cy = cy if size != 12: logging.warning("only size 12 supported") print("only size 12 supported") else: doc = FreeCAD.ActiveDocument # Total height: sk_z = kcomp.SK12['H'] self.TotH = sk_z # Total width (Y): sk_y = kcomp.SK12['W'] self.TotW = sk_y # Total depth (x): sk_x = kcomp.SK12['L'] self.TotD = sk_x # Base height sk_base_z = 6 # center width sk_center_y = 20 # Axis height: sk_axis_z = 23 self.HoleH = sk_axis_z # tightening bolt with added tolerances: # Bolt's head radius tbolt_head_r = (self.holtol * kcomp.D912_HEAD_D[kcomp.SK12['tbolt']]) / 2.0 # Bolt's head lenght tbolt_head_l = (self.holtol * kcomp.D912_HEAD_L[kcomp.SK12['tbolt']]) # Mounting bolt radius with added tolerance mbolt_r = self.holtol * kcomp.SK12['mbolt'] / 2 # the total dimensions: LxWxH # we will cut it total_box = addBox(x=sk_x, y=sk_y, z=sk_z, name="total_box", cx=False, cy=True) # what we have to cut from the sides side_box_y = (sk_y - kcomp.SK12['I']) / 2 side_box_z = sk_z - kcomp.SK12['g'] side_cut_box_r = addBox(sk_x, side_box_y, side_box_z, "side_box_r") side_cut_pos_r = FreeCAD.Vector(0, kcomp.SK12['I'] / 2, kcomp.SK12['g']) side_cut_box_r.Placement.Base = side_cut_pos_r side_cut_box_l = addBox(sk_x, side_box_y, side_box_z, "side_box_l") side_cut_pos_l = FreeCAD.Vector(0, -sk_y / 2, kcomp.SK12['g']) side_cut_box_l.Placement.Base = side_cut_pos_l # union side_boxes = doc.addObject("Part::Fuse", "side_boxes") side_boxes.Base = side_cut_box_r side_boxes.Tool = side_cut_box_l # difference sk_shape = doc.addObject("Part::Cut", "sk_shape") sk_shape.Base = total_box sk_shape.Tool = side_boxes # Shaft hole, its height has +2 to make it throughl L all de way shaft_hole = addCyl(kcomp.SK12['d'] / 2, sk_x + 2, "shaft_hole") """ First argument defines de position: -1, 0, h Second argument rotation: 90 degrees rotation in Y. Third argument the center of the rotation, in this case, it is in the cylinder axis at the base of the cylinder """ shaft_hole.Placement = FreeCAD.Placement( FreeCAD.Vector(-1, 0, kcomp.SK12['h']), FreeCAD.Rotation(VY, 90), V0) # the upper sepparation up_sep = addBox(sk_x + 2, self.up_sep_dist, sk_z - kcomp.SK12['h'] + 1, "up_sep") up_sep_pos = FreeCAD.Vector(-1, -self.up_sep_dist / 2, kcomp.SK12['h'] + 1) up_sep.Placement.Base = up_sep_pos """ Tightening bolt shaft hole, its height has +2 to make it throughl L all de way kcomp.SK12['tbolt'] is the diameter of the bolt: (M..) M4, ... tbolt_head_r: is the radius of the tightening bolt's head (including tolerance), which its bottom either - is at the middle point between - A: the total height :sk_z - B: the top of the shaft hole: kcomp.SK12['h']+kcomp.SK12['d']/2 - so the result will be (A + B)/2 or it is aligned with the top of the 12mm shaft, whose height is: kcomp.SK12['h']+kcomp.SK12['d']/2 """ tbolt_shaft = addCyl(kcomp.SK12['tbolt'] / 2, kcomp.SK12['I'] + 2, "tbolt_shaft") tbolt_shaft_pos = FreeCAD.Vector( sk_x / 2, kcomp.SK12['I'] / 2 + 1, kcomp.SK12['h'] + kcomp.SK12['d'] / 2 + tbolt_head_r / self.holtol) #(sk_z + kcomp.SK12['h']+kcomp.SK12['d']/2)/2) tbolt_shaft.Placement = FreeCAD.Placement(tbolt_shaft_pos, FreeCAD.Rotation(VX, 90), V0) # Head of the thigthening bolt tbolt_head = addCyl(tbolt_head_r, tbolt_head_l + 1, "tbolt_head") tbolt_head_pos = FreeCAD.Vector( sk_x / 2, kcomp.SK12['I'] / 2 + 1, kcomp.SK12['h'] + kcomp.SK12['d'] / 2 + tbolt_head_r / self.holtol) #(sk_z + kcomp.SK12['h']+kcomp.SK12['d']/2)/2) tbolt_head.Placement = FreeCAD.Placement(tbolt_head_pos, FreeCAD.Rotation(VX, 90), V0) #Make an union of all these parts fuse_shaft_holes = doc.addObject("Part::MultiFuse", "fuse_shaft_holes") fuse_shaft_holes.Shapes = [ tbolt_head, tbolt_shaft, up_sep, shaft_hole ] #Cut from the sk_shape sk_shape_w_holes = doc.addObject("Part::Cut", "sk_shape_w_holes") sk_shape_w_holes.Base = sk_shape sk_shape_w_holes.Tool = fuse_shaft_holes #Mounting bolts mbolt_sh_r = addCyl(mbolt_r, kcomp.SK12['g'] + 2, "mbolt_sh_r") mbolt_sh_l = addCyl(mbolt_r, kcomp.SK12['g'] + 2, "mbolt_sh_l") mbolt_sh_r_pos = FreeCAD.Vector(sk_x / 2, kcomp.SK12['B'] / 2, -1) mbolt_sh_l_pos = FreeCAD.Vector(sk_x / 2, -kcomp.SK12['B'] / 2, -1) mbolt_sh_r.Placement.Base = mbolt_sh_r_pos mbolt_sh_l.Placement.Base = mbolt_sh_l_pos """ Equivalente expresions to the ones above mbolt_sh_l.Placement = FreeCAD.Placement(mbolt_sh_l_pos, v0rot, v0) mbolt_sh_r.Placement = FreeCAD.Placement(mbolt_sh_r_pos, v0rot, v0) """ mbolts_sh = doc.addObject("Part::Fuse", "mbolts_sh") mbolts_sh.Base = mbolt_sh_r mbolts_sh.Tool = mbolt_sh_l # Instead of moving all the objects from the begining. I do it here # so it is easier, and since a new object will be created, it is # referenced correctly # Now, it is centered on Y, having the width on X, hole facing X # on the positive side of X if hole_x == 1: # this is how it is, no rotation rot = FreeCAD.Rotation(VZ, 0) if cx == 1: #we want centered on X,bring back the half of depth xpos = -self.TotD / 2.0 else: xpos = 0 # how it is if cy == 1: # centered on Y, how it is ypos = 0 else: ypos = self.TotW / 2.0 # bring forward the width else: # hole facing Y rot = FreeCAD.Rotation(VZ, 90) # After rotating, it is centered on X, if cx == 1: # centered on X, how it is xpos = 0 else: xpos = self.TotW / 2.0 if cy == 1: # we want centered on Y, bring back ypos = -self.TotD / 2.0 else: ypos = 0 sk_shape_w_holes.Placement.Base = FreeCAD.Vector(xpos, ypos, 0) mbolts_sh.Placement.Base = FreeCAD.Vector(xpos, ypos, 0) sk_shape_w_holes.Placement.Rotation = rot mbolts_sh.Placement.Rotation = rot sk_final = doc.addObject("Part::Cut", name) sk_final.Base = sk_shape_w_holes sk_final.Tool = mbolts_sh self.fco = sk_final # the FreeCad Object
EXTR_IN_H = kcomp.E3DV6_IN_H - TOL EXTR_OUT_D = kcomp.E3DV6_OUT_DIAM + TOL EXTR_OUTUP_H = kcomp.E3DV6_OUTUP_H EXTR_OUTBOT_H = kcomp.E3DV6_OUTBOT_H + TOL EXTR_HOLD_FLLT_R = 2.0 # this is the distance that the bottom of the bottom ring will be outside # of the carriage EXTR_BOT_OUT = 1.0 NUT_HOLE_EDGSEP = 3 # separation from the edge # Outer up ring extr_outup = addCyl(r=EXTR_OUT_D / 2.0, h=EXTR_OUTUP_H, name="extr_outup") extr_outup_2 = addCyl(r=EXTR_OUT_D / 2.0, h=EXTR_OUTUP_H, name="extr_outup_2") extr_outup_pos = FreeCAD.Vector(0, 0, EXTR_OUTBOT_H + EXTR_IN_H - EXTR_BOT_OUT) extr_outup.Placement = FreeCAD.Placement(extr_outup_pos, V0ROT, V0) extr_outup_2.Placement = FreeCAD.Placement(extr_outup_pos, V0ROT, V0) # Inner ring extr_in = addCyl(r=EXTR_IN_D / 2.0, h=EXTR_IN_H, name="extr_in") extr_in_2 = addCyl(r=EXTR_IN_D / 2.0, h=EXTR_IN_H, name="extr_in_2") extr_in_pos = FreeCAD.Vector(0, 0, EXTR_OUTBOT_H - EXTR_BOT_OUT) extr_in.Placement = FreeCAD.Placement(extr_in_pos, V0ROT, V0) extr_in_2.Placement = FreeCAD.Placement(extr_in_pos, V0ROT, V0) # Outer bottom ring extr_outbot = addCyl(r=EXTR_OUT_D / 2.0, h=EXTR_OUTBOT_H, name="extr_outbot") extr_outbot_2 = addCyl(r=EXTR_OUT_D / 2.0, h=EXTR_OUTBOT_H, name="extr_outbot_2")