#reload(Ex006_Moving_the_Current_Working_Point) #You'll need to delete the original shape that was created, and the new shape should be named sequentially (Shape001, etc). #You can also tie these blocks of code to macros, buttons, and keybindings in FreeCAD for quicker access. #You can get a more information on this example at http://parametricparts.com/docs/examples.html#an-extruded-prismatic-solid import cadquery import Part #The dimensions of the model. These can be modified rather than changing the box's code directly. circle_radius = 3.0 thickness = 0.25 #Make the plate with two cutouts in it result = cadquery.Workplane("front").circle( circle_radius) #Current point is the center of the circle, at (0,0) result = result.center(1.5, 0.0).rect(0.5, 0.5) #New work center is (1.5,0.0) result = result.center(-1.5, 1.5).circle(0.25) #New work center is ( 0.0,1.5). #The new center is specified relative to the previous center, not global coordinates! result = result.extrude(thickness) #Get a cadquery solid object solid = result.val() #Use the wrapped property of a cadquery primitive to get a FreeCAD solid Part.show(solid.wrapped) #Would like to zoom to fit the part here, but FreeCAD doesn't seem to have that scripting functionality
def make_cutter(self): # A solid to cut away from another; makes room to install the anchor return cadquery.Workplane('XY', origin=(0, 0, -self.height)) \ .circle(self.diameter / 2) \ .extrude(self.height + 1000) # 1m bore depth
def MakeBase(pins, highDetail=True): #length of the base block L = pins * 2.54 + 7.66 #Width of base block W1 = 8.85 #internal width W2 = 6.35 #wall thickness T = (W1 - W2) / 2 #length of pin array D = (pins - 1) * 2.54 #height of the base H = 8.85 - 6.50 base = cq.Workplane("XY").rect(W1, L).extrude(H) #wall height H2 H2 = 6.50 #extrude the edge up around the base wall = cq.Workplane("XY").workplane(offset=H).rect(W1, L).extrude(H2) wall = wall.cut( cq.Workplane("XY").rect(W2, (pins - 1) * 2.54 + 7.88).extrude(8.85)) # add a chamfer to the wall inner (only for high detail version) # if (highDetail): # wall = wall.faces(">Z").edges("not(<X or >X or <Y or >Y)").chamfer(0.5) base = base.union(wall) #cut a notch out of one side CW = 4.5 # in detail version, this tab extends slightly below base top surface if (highDetail): undercut = 0.5 else: undercut = 0.0 cutout = cq.Workplane("XY").workplane(offset=H - undercut).rect( 2 * 2.0, CW).extrude(H2 + undercut).translate((-W1 / 2, 0, 0)) base = base.cut(cutout) # add visual / non-critical details if (highDetail): # long bobbles bobbleR = 0.5 bobbleH = 9.10 - 8.85 longbobble1 = cq.Workplane("XY").center( W1 / 2 - bobbleR + bobbleH, L / 2 - 2.5).circle(bobbleR).extrude(8.5) longbobble2 = cq.Workplane("XY").center(W1 / 2 - bobbleR + bobbleH, 0).circle(bobbleR).extrude(8.5) longbobble3 = cq.Workplane("XY").center( W1 / 2 - bobbleR + bobbleH, -L / 2 + 2.5).circle(bobbleR).extrude(8.5) base = base.union(longbobble1) base = base.union(longbobble2) base = base.union(longbobble3) # wee bobbles weebobbles = cq.Workplane("XY").center( 2.85, L / 2 - 2.5).circle(0.5).extrude(8.85 - 9.10) weebobbles = weebobbles.union( cq.Workplane("XY").center(2.85, 0).circle(0.5).extrude(8.85 - 9.10)) weebobbles = weebobbles.union( cq.Workplane("XY").center(2.85, -L / 2 + 2.5).circle(0.5).extrude(8.85 - 9.10)) weebobbles = weebobbles.union(weebobbles.translate((-5.7, 0, 0))) base = base.union(weebobbles) # sidecuts sidecut = cq.Workplane("XY").rect(3.5, 1.25 * 2).extrude(H2).translate( (0, L / 2, 0)) sidecut = sidecut.union(sidecut.translate((0, -L, 0))) base = base.cut(sidecut) #now offset the location of the base appropriately base = base.translate((1.27, (pins - 1) * -1.27, 9.10 - 8.85)) return base
p_sideRadius = 10.0 # Radius for the curves around the sides of the bo p_topAndBottomRadius = 2.0 # Radius for the curves on the top and bottom edges p_screwpostInset = 12.0 # How far in from the edges the screwposts should be p_screwpostID = 4.0 # Inner diameter of the screwpost holes, should be roughly screw diameter not including threads p_screwpostOD = 10.0 # Outer diameter of the screwposts. Determines overall thickness of the posts p_boreDiameter = 8.0 # Diameter of the counterbore hole, if any p_boreDepth = 1.0 # Depth of the counterbore hole, if p_countersinkDiameter = 0.0 # Outer diameter of countersink. Should roughly match the outer diameter of the screw head p_countersinkAngle = 90.0 # Countersink angle (complete angle between opposite sides, not from center to one side) p_flipLid = True # Whether to place the lid with the top facing down or not. p_lipHeight = 1.0 # Height of lip on the underside of the lid. Sits inside the box body for a snug fit. # Outer shell oshell = cadquery.Workplane("XY").rect(p_outerWidth, p_outerLength) \ .extrude(p_outerHeight + p_lipHeight) # Weird geometry happens if we make the fillets in the wrong order if p_sideRadius > p_topAndBottomRadius: oshell.edges("|Z").fillet(p_sideRadius) oshell.edges("#Z").fillet(p_topAndBottomRadius) else: oshell.edges("#Z").fillet(p_topAndBottomRadius) oshell.edges("|Z").fillet(p_sideRadius) # Inner shell ishell = oshell.faces("<Z").workplane(p_thickness, True)\ .rect((p_outerWidth - 2.0 * p_thickness), (p_outerLength - 2.0 * p_thickness))\ .extrude((p_outerHeight - 2.0 * p_thickness), False) # Set combine false to produce just the new boss ishell.edges("|Z").fillet(p_sideRadius - p_thickness)
import cadquery as cq # 1. Establishes a workplane that an object can be built on. # 1a. Uses the named plane orientation "front" to define the workplane, meaning # that the positive Z direction is "up", and the negative Z direction # is "down". # 2. Creates a 3D box that will have a hole placed in it later. result = cq.Workplane("front").box(3, 2, 0.5) # 3. Select the lower left vertex and make a workplane. # 3a. The top-most Z face is selected using the >Z selector. # 3b. The lower-left vertex of the faces is selected with the <XY selector. # 3c. A new workplane is created on the vertex to build future geometry on. result = result.faces(">Z").vertices("<XY").workplane() # 4. A circle is drawn with the selected vertex as its center. # 4a. The circle is cut down through the box to cut the corner out. result = result.circle(1.0).cutThruAll()
def __init__(self, **kwargs): d = { "locationFiducialSize": 0.25, "switchSizeX": 19.05, "switchSizeY": 19.05, "switchCutX": 14, "switchCutY": 14, "switchCutFillet": 0.5, "outlineOffset": 5, "handAngleDegrees": 10, "rowCounts": [], "columnDeltas": [], "extraKeys": [], "outlineLocations": [], "spacerOffset": 1, "extraDrills": [], "edgeLEDCounts": [], "drillRadius": 1.6, "drillPadRadius": 3.5, "spacerRadius": 2.25, # size of holes that brass spacers need to pass through "lcdX": 7.6, # in keyswitch units "lcdY": 2.7, # in keyswitch units "lcdWidth": 40.1, "lcdHeight": 67.2, "lcdDrillWidth": 34.1, "lcdDrillHeight": 61.2, "lcdDrillRadius": 1.6, "lcdDrillPadRadius": 3.5, "lcdPinCutoutWidth": 26.2, "lcdPinCutoutHeight": 2.9, "lcdPinCutoutY": 32.14701, "lcdPinCutoutFillet": 1, "encoderX": 7.65, # in keyswitch units "encoderY": 4, # in keyswitch units "encoderCutX": 13, "encoderCutY": 13, "encoderCutFillet": 0.5, "encoderKnobDiameter": 26.2, "dpadX": 5.375, # in keyswitch units "dpadY": 5.5, # in keyswitch units "dpadCutDiameter": 6, "dpadHousingWidth": 14, "dpadHousingHeight": 14, "resetX": 8.625, # in keyswitch units "resetY": 3.375, # in keyswitch units "resetCutDiameter": 3, # hole for reset button "resetHousingWidth": 7, "resetHousingHeight": 7, "ledSizeX": 8, "ledSizeY": 4, "ledCutFillet": 1.5, "ledOffset": 1.5, "usbX": 6.3, # in keyswitch units "usbY": -1.037234, # in keyswitch units "usbWidth": 9.5, "usbHeight": 8, "splitX": 7.375, # in keyswitch units "splitY": -0.7265, # in keyswitch units "splitWidth": 9.5, "splitHeight": 8, } d.update(kwargs) self.__switchOrder = d["switchOrder"] self.__ledFlip = d["ledFlip"] self.__switchSizeX = float(d["switchSizeX"]) self.__switchSizeY = float(d["switchSizeY"]) self.__switchCutX = float(d["switchCutX"]) self.__switchCutY = float(d["switchCutY"]) self.__switchCutFillet = float(d["switchCutFillet"]) self.__outlineOffset = float(d["outlineOffset"]) self.__spacerOffset = float(d["spacerOffset"]) self.__handAngle = math.radians(float(d["handAngleDegrees"])) self.__locationFiducialSize = float(d["locationFiducialSize"]) self.__rowCounts = d["rowCounts"] self.__columnDeltas = d["columnDeltas"] self.__extraKeys = d["extraKeys"] self.__outlineLocations = d["outlineLocations"] self.__spacerLocations = d["spacerLocations"] self.__extraDrills = d["extraDrills"] self.__edgeLEDCounts = d["edgeLEDCounts"] self.__extraLeds = d["extraLeds"] self.__drillRadius = float(d["drillRadius"]) self.__drillPadRadius = float(d["drillPadRadius"]) self.__spacerRadius = float(d["spacerRadius"]) self.__lcdX = float(d["lcdX"]) self.__lcdY = float(d["lcdY"]) self.__lcdWidth = float(d["lcdWidth"]) self.__lcdHeight = float(d["lcdHeight"]) self.__lcdDrillWidth = float(d["lcdDrillWidth"]) self.__lcdDrillHeight = float(d["lcdDrillHeight"]) self.__lcdDrillRadius = float(d["lcdDrillRadius"]) self.__lcdDrillPadRadius = float(d["lcdDrillPadRadius"]) self.__lcdPinCutoutWidth = float(d["lcdPinCutoutWidth"]) self.__lcdPinCutoutHeight = float(d["lcdPinCutoutHeight"]) self.__lcdPinCutoutY = float(d["lcdPinCutoutY"]) self.__lcdPinCutoutFillet = float(d["lcdPinCutoutFillet"]) self.__encoderX = float(d["encoderX"]) self.__encoderY = float(d["encoderY"]) self.__encoderCutX = float(d["encoderCutX"]) self.__encoderCutY = float(d["encoderCutY"]) self.__encoderCutFillet = float(d["encoderCutFillet"]) self.__encoderKnobDiameter = float(d["encoderKnobDiameter"]) self.__dpadX = float(d["dpadX"]) self.__dpadY = float(d["dpadY"]) self.__dpadCutDiameter = float(d["dpadCutDiameter"]) self.__dpadHousingWidth = float(d["dpadHousingWidth"]) self.__dpadHousingHeight = float(d["dpadHousingHeight"]) self.__resetX = float(d["resetX"]) self.__resetY = float(d["resetY"]) self.__resetCutDiameter = float(d["resetCutDiameter"]) self.__resetHousingWidth = float(d["resetHousingWidth"]) self.__resetHousingHeight = float(d["resetHousingHeight"]) self.__ledSizeX = float(d["ledSizeX"]) self.__ledSizeY = float(d["ledSizeY"]) self.__ledCutFillet = float(d["ledCutFillet"]) self.__ledOffset = float(d["ledOffset"]) self.__usbX = float(d["usbX"]) self.__usbY = float(d["usbY"]) self.__usbWidth = float(d["usbWidth"]) self.__usbHeight = float(d["usbHeight"]) self.__splitX = float(d["splitX"]) self.__splitY = float(d["splitY"]) self.__splitWidth = float(d["splitWidth"]) self.__splitHeight = float(d["splitHeight"]) self.__workplane = cq.Workplane("XY") self.__post_processing()
import cadquery as cq result = cq.Workplane().rect(3, 4, centered=False).extrude(1)
import cadquery as cq from cadquery_massembly import MAssembly, relocate from jupyter_cadquery.viewer.client import show from jupyter_cadquery import set_defaults set_defaults(axes=True, axes0=True, mate_scale=5) box0 = cq.Workplane("XY").box(10, 20, 10) box1 = cq.Workplane("XZ").box(10, 20, 10) box2 = cq.Workplane("YX").box(10, 20, 10) box3 = cq.Workplane("YZ").box(10, 20, 10) for box, name, dirs in ( (box0, "box0", ("Y", "X")), (box1, "box1", ("Z", "X")), (box2, "box2", ("X", "Y")), (box3, "box3", ("Z", "Y")), ): for i, direction in enumerate(dirs): box.faces(f">{direction}").tag(f"{name}_m{i}") cyl1 = cq.Workplane("XY").circle(2).extrude(10) cyl2 = cq.Workplane("XZ").circle(2).extrude(10) cyl3 = cq.Workplane("YZ").circle(2).extrude(10) for cyl, name, ax in ( (cyl1, "cyl1", "Z"), (cyl2, "cyl2", "Y"), (cyl3, "cyl3", "X"), ): cyl.faces(f">{ax}").tag(f"{name}_m0")
#result = cadquery.Workplane("XY").rect(rectangle_width, rectangle_length).revolve(angle_degrees,(-5,-5)) #result = cadquery.Workplane("XY").rect(rectangle_width, rectangle_length).revolve(angle_degrees,(-5, -5),(-5, 5)) #result = cadquery.Workplane("XY").rect(rectangle_width, rectangle_length).revolve(angle_degrees,(-5,-5),(-5,5), False) ## color_attr=(255,255,255,0) ## show(pinmark, color_attr) ##sphere = cq.Workplane("XY", (-D1_t2/2+fp_d+fp_r, -E1_t2/2+fp_d+fp_r, sphere_z)). \ ## sphere(sphere_r) # color_attr=(255,255,255,0) # show(sphere, color_attr) #case = case.cut(sphere) if (color_pin_mark == False) and (place_pinMark == True): case = case.cut(pinmark) # Create a pin object at the center of top side. bpin = cq.Workplane("XY").box(L, b, c).translate( ((E - L) / 2, 0, c / 2)).rotate((0, 0, 0), (0, 0, 1), 90) pins = [] pincounter = 1 first_pos_x = (npx - 1) * e / 2 for i in range(npx): if pincounter not in excluded_pins: pin = bpin.translate((first_pos_x-i*e, 0, 0)).\ rotate((0,0,0), (0,0,1), 180) pins.append(pin) pincounter += 1 first_pos_y = (npy - 1) * e / 2 for i in range(npy): if pincounter not in excluded_pins: pin = bpin.translate((first_pos_y-i*e, (D1-E1)/2, 0)).\
import cadquery as cq from cqextension.monkey_patch import seamSelector from slicer.slice import setSlicerSettings p = cq.Workplane().box(40, 60, 4).edges("|Z and >X and <Y").chamfer(20) p = p.faces(">Z").workplane().pushPoints([(-10, 20), (-10, 0), (-10, -20), (10, 20)]).hole(5) p = p.pushPoints([(7, -10)]).hole(3) show_object(p)
from fattenTe import fattenTe #from pprint import pprint import cadquery as cq # type: ignore from typing import Tuple, List chord: float = 50 span: float = 20 # Normalize mh49 to 1. Assumes first point is # the length of the chord and will scale all # of the points to 1/mh49[0][0] scaleFactor: float = 1 / mh49[0][0] #print(f'scaleFactor={scaleFactor}') nMh49 = scaleListOfTuple(mh49, scaleFactor) # Scale the normalized mh49 to the size of the chord # and turn it into a list sMh49: List[Tuple[float, float]] = scaleListOfTuple(nMh49, chord) #print(f'SKINNY sMh49={sMh49}') fMh49: List[Tuple[float, float]] = fattenTe(sMh49, 0.5, 10) #print(f'FATTENed fMh49={fMh49}') result = cq.Workplane("XY").spline(fMh49).close().extrude(span) #pprint(vars(result)) import io tolerance = 0.001 f = io.open(f'wing1-spline-50x20-direct-{tolerance}.stl', 'w+') cq.exporters.exportShape(result, cq.exporters.ExportTypes.STL, f, tolerance) f.close()
import cadquery as cq # base slab width varies from 1560mm to 685mm length 1220mm # base thickness 100mm # back wall height 1000mm with opening 400mm dia. # wingwalls height varies from 1000mm to 320mm # walls thickness 100mm # shear key depth 600mm # base slab (with walls thickness) base_pts = [(0.0, 0.0), (1560.0, 0.0), (1654.13, 33.76), (1192.87, 1320.0), (367.13, 1320.0), (-94.13, 33.76), (0.0, 0.0)] headwall = cq.Workplane("XY") \ .polyline(base_pts).close() \ .extrude(-100) # back wall backw_pts = [(331.26, 1220.0), (1228.73, 1220.0), (1192.87, 1320.0), (367.13, 1320.0), (331.26, 1220.0)] headwall = headwall \ .polyline(backw_pts).close() \ .extrude(1000) # opening open_dia = 400.0 open_centre = (780.0, 1220.0, open_dia / 2 + 100.0) headwall = headwall \ .copyWorkplane(cq.Workplane("XZ", origin=open_centre)) \
def make_radial_smd(params): L = params.L # overall height D = params.D # diameter A = params.A # base width (x&y) H = params.H # max width (x) with pins P = params.P # distance between pins W = params.W # pin width PM = params.PM # hide pin marker if not color_pin_mark: PM=False c = 0.15 # pin thickness bh = L/6 # belt start height br = min(D, L)/20. # belt radius bf = br/10 # belt fillet D2 = A+0.1 # cut diameter h1 = 1. # bottom plastic height, cathode side h2 = 0.5 # bottom plastic base height, mid side h3 = 0.7 # bottom plastic height, anode side cf = 0.4 # cathode side corner fillet ac = min(1, A/4) # anode side chamfer ef = D/15 # fillet of the top and bottom edges of the metallic body rot = params.rotation cimw = D/2.*0.7 # cathode identification mark width # draw aluminium the body body = cq.Workplane("XZ", (0,0,c+h2)).\ lineTo(D/2., 0).\ line(0, bh).\ threePointArc((D/2.-br, bh+br), (D/2., bh+2*br)).\ lineTo(D/2., L-c-h2).\ line(-D/2, 0).\ close().revolve() # fillet the belt edges BS = cq.selectors.BoxSelector body = body.edges(BS((-0.1,-0.1,c+h2+0.1), (0.1,0.1,L-0.1))).\ fillet(bf) # fillet the top and bottom body = body.faces(">Z").fillet(ef).\ faces("<Z").fillet(ef) # draw the plastic base base = cq.Workplane("XY", (0,0,c)).\ moveTo(-A/2.,-A/2.).\ line(A-ac, 0).\ line(ac, ac).\ line(0, A-2*ac).\ line(-ac, ac).\ line(-A+ac, 0).\ close().extrude(h1) # fillet cathode side base = base.edges(BS((-A,-A,0), (-A/2.+0.01,-A/2.+0.01,c+h1+0.01))).\ fillet(cf).\ edges(BS((-A,A,0), (-A/2.+0.01,A/2.-0.01,c+h1+0.01))).\ fillet(cf) # cut base center base = base.cut( cq.Workplane("XY", (0,0,c+h2)).\ circle(D2/2.).extrude(h1-h2)) # cut anode side of the base base = base.cut( cq.Workplane("XY", (0,-A/2.,c+h3)).\ box(A/2., A, h1-h3, centered=(False, False, False))) # draw pins pins = cq.Workplane("XY").\ moveTo(H/2., -W/2.).\ line(0, W).\ lineTo(P/2.+W/2., W/2.).\ threePointArc((P/2.,0), (P/2.+W/2., -W/2)).\ close().extrude(c) pins = pins.union(pins.rotate((0,0,0), (0,0,1), 180)) cim = cq.Workplane("XY", (0,0, 0.0)).circle(0.01).extrude(0.01) # draw the cathode identification mark if PM: cim = cq.Workplane("XY", (-D/2.,0,L-ef)).\ box(cimw, D, ef, centered=(False, True, False)) # do intersection cim = cim.cut(cim.translate((0,0,0)).cut(body)) body.cut(cim) #show(body) #show(base) #show(cim) #show(pins) #sleep return (body, base, cim, pins)
# Example cadquery script # Usage: test.py output.stl import cadquery as cq from cadquery import exporters import sys result = cq.Workplane("XY").box(3, 3, 0.5).edges("|Z").fillet(0.125) with open(sys.argv[1], 'w') as f: exporters.exportShape(result, exporters.ExportTypes.STL, f)
import cadquery as cq result = cq.Workplane("XZ").box(10, 10, 10) result = result.cut(cq.Workplane("XZ").box(5, 5, 5)) selector = result.faces().vertices() rim = cq.Workplane("XZ") for Vert in range(selector.size()): rim = rim.union(selector.item(Vert).circle(0.5).extrude(0.5)) result = result.union(rim) # The following method is now outdated, but can still be used to display the # results of the script if you want # from Helpers import show show_object(result) # Render the result of this script #result.exportSvg( "./88/Runner.svg"); #with open("./88/Runner.stl", 'w') as f: #f.write(cq.exporters.toString(result, 'STL', 10)) #f.close(); #show_object(result)
def make_gw(params): c = params.c the = params.the ef = params.ef fp_s = params.fp_s fp_r = params.fp_r fp_d = params.fp_d fp_z = params.fp_z D1 = params.D1 E1 = params.E1 E = params.E A1 = params.A1 A2 = params.A2 b = params.b e = params.e npx = params.npx npy = params.npy mN = params.modelName rot = params.rotation dest_dir_pref = params.dest_dir_prefix if params.excluded_pins: excluded_pins = params.excluded_pins else: excluded_pins = () ##no pin excluded A = A1 + A2 A2_t = A - c # body top part height A2_b = c - A1 # body bottom part height D1_t = D1 - 2 * tan(radians(the)) * A2_t # top part upper width E1_t = E1 - 2 * tan(radians(the)) * A2_t # top part upper length D1_b = D1 - 2 * tan(radians(the)) * A2_b # bottom width E1_b = E1 - 2 * tan(radians(the)) * A2_b # bottom length if params.L: L = params.L else: L = (E - E1_b) / 2 epad_rotation = 0.0 epad_offset_x = 0.0 epad_offset_y = 0.0 if params.epad: #if isinstance(params.epad, float): if not isinstance(params.epad, tuple): sq_epad = False epad_r = params.epad else: sq_epad = True D2 = params.epad[0] E2 = params.epad[1] if len(params.epad) > 2: epad_rotation = params.epad[2] if len(params.epad) > 3: if isinstance(params.epad[3], str): if params.epad[3] == '-topin': epad_offset_x = ((D1 + E - E1) / 2 - L - D2 / 2) * -1 elif params.epad[3] == '+topin': epad_offset_x = ((D1 + E - E1) / 2 - L - D2 / 2) else: epad_offset_x = params.epad[3] if len(params.epad) > 4: if isinstance(params.epad[4], str): if params.epad[4] == '-topin': epad_offset_y = (E / 2 - L - E2 / 2) * -1 elif params.epad[4] == '+topin': epad_offset_y = (E / 2 - L - E2 / 2) else: epad_offset_y = params.epad[4] # calculated dimensions for body # checking pin lenght compared to overall width # d=(E-E1 -2*(S+L)-2*(R1)) FreeCAD.Console.PrintMessage('E=' + str(E) + ';E1=' + str(E1) + '\r\n') totpinwidthx = (npx - 1) * e + b # total width of all pins on the X side totpinwidthy = (npy - 1) * e + b # total width of all pins on the Y side case = cq.Workplane(cq.Plane.XY()).workplane(offset=A1).rect(D1_b, E1_b). \ workplane(offset=A2_b).rect(D1, E1).workplane(offset=A2_t).rect(D1_t,E1_t). \ loft(ruled=True).faces(">Z") #bottomrect = cq.Workplane("XY").rect(E1_t1,D1_t1).translate((0,0,A1)) #middlerect =cq.Workplane("XY").rect(E1,D1).translate((0,0,A1+c)) #fp_s = True if fp_r == 0: global place_pinMark place_pinMark = False fp_r = 0.1 if fp_s == False: pinmark = cq.Workplane(cq.Plane.XY()).workplane(offset=A).box( fp_r, E1_t - fp_d, fp_z * 2) #.translate((E1/2,0,A1)).rotate((0,0,0), (0,0,1), 90) #translate the object pinmark = pinmark.translate((-D1_t / 2 + fp_r / 2. + fp_d / 2, 0, 0)) #.rotate((0,0,0), (0,1,0), 0) else: # first pin indicator is created with a spherical pocket sphere_r = (fp_r * fp_r / 2 + fp_z * fp_z) / (2 * fp_z) sphere_z = A + sphere_r * 2 - fp_z - sphere_r # Revolve a cylinder from a rectangle # Switch comments around in this section to try the revolve operation with different parameters ##cylinder = #pinmark=cq.Workplane("XZ", (-D1_t2/2+fp_d+fp_r, -E1_t2/2+fp_d+fp_r, A)).rect(sphere_r/2, -fp_z, False).revolve() pinmark = cq.Workplane( "XZ", (-D1_t / 2 + fp_d + fp_r, -E1_t / 2 + fp_d + fp_r, A)).rect( fp_r / 2, -fp_z, False).revolve() #result = cadquery.Workplane("XY").rect(rectangle_width, rectangle_length, False).revolve(angle_degrees) #result = cadquery.Workplane("XY").rect(rectangle_width, rectangle_length).revolve(angle_degrees,(-5,-5)) #result = cadquery.Workplane("XY").rect(rectangle_width, rectangle_length).revolve(angle_degrees,(-5, -5),(-5, 5)) #result = cadquery.Workplane("XY").rect(rectangle_width, rectangle_length).revolve(angle_degrees,(-5,-5),(-5,5), False) ## color_attr=(255,255,255,0) ## show(pinmark, color_attr) ##sphere = cq.Workplane("XY", (-D1_t2/2+fp_d+fp_r, -E1_t2/2+fp_d+fp_r, sphere_z)). \ ## sphere(sphere_r) # color_attr=(255,255,255,0) # show(sphere, color_attr) #case = case.cut(sphere) if (color_pin_mark == False) and (place_pinMark == True): case = case.cut(pinmark)
import cadquery as cq # 1. Establishes a workplane that an object can be built on. # 1a. Uses the named plane orientation "front" to define the workplane, meaning # that the positive Z direction is "up", and the negative Z direction # is "down". # 2. Creates a plain box to base future geometry on with the box() function. # 3. Selects the top-most Z face of the box. # 4. Creates a new workplane and then moves and rotates it with the # transformed function. # 5. Creates a for-construction rectangle that only exists to use for placing # other geometry. # 6. Selects the vertices of the for-construction rectangle. # 7. Places holes at the center of each selected vertex. # 7a. Since the workplane is rotated, this results in angled holes in the face. result = ( cq.Workplane("front") .box(4.0, 4.0, 0.25) .faces(">Z") .workplane() .transformed(offset=(0, -1.5, 1.0), rotate=(60, 0, 0)) .rect(1.5, 1.5, forConstruction=True) .vertices() .hole(0.25) ) # Displays the result of this script show_object(result)
#import sys #sys.path.append('/home/user/Downloads/cadquery/examples/FreeCAD') #import Ex009_Polylines #If you need to reload the part after making a change, you can use the following lines within the FreeCAD console. #reload(Ex009_Polylines) #You'll need to delete the original shape that was created, and the new shape should be named sequentially # (Shape001, etc). #You can also tie these blocks of code to macros, buttons, and keybindings in FreeCAD for quicker access. #You can get a more information on this example at # http://parametricparts.com/docs/examples.html#an-extruded-prismatic-solid import cadquery import Part #Set up our Length, Height, Width, and thickness that will be used to define the locations that the polyline #is drawn to/thru (L, H, W, t) = (100.0, 20.0, 20.0, 1.0) #Define the locations that the polyline will be drawn to/thru pts = [(0, H / 2.0), (W / 2.0, H / 2.0), (W / 2.0, (H / 2.0 - t)), (t / 2.0, (H / 2.0 - t)), (t / 2.0, (t - H / 2.0)), (W / 2.0, (t - H / 2.0)), (W / 2.0, H / -2.0), (0, H / -2.0)] #We generate half of the I-beam outline and then mirror it to create the full I-beam result = cadquery.Workplane("front").polyline(pts).mirrorY().extrude(L) #Boiler plate code to render our solid in FreeCAD's GUI Part.show(result.toFreecad())
def create_solid(self): """Creates a rotated 3d solid using points with straight and spline edges. Returns: A CadQuery solid: A 3D solid volume """ # obtains the first two values of the points list XZ_points = [(p[0], p[1]) for p in self.points] # obtains the last values of the points list connections = [p[2] for p in self.points[:-1]] current_linetype = connections[0] current_points_list = [] instructions = [] # groups together common connection types for i, c in enumerate(connections): if c == current_linetype: current_points_list.append(XZ_points[i]) else: current_points_list.append(XZ_points[i]) instructions.append({current_linetype: current_points_list}) current_linetype = c current_points_list = [XZ_points[i]] instructions.append({current_linetype: current_points_list}) if list(instructions[-1].values())[0][-1] != XZ_points[0]: keyname = list(instructions[-1].keys())[0] instructions[-1][keyname].append(XZ_points[0]) solid = cq.Workplane(self.workplane) for entry in instructions: if list(entry.keys())[0] == "spline": solid = solid.spline(listOfXYTuple=list(entry.values())[0]) if list(entry.keys())[0] == "straight": solid = solid.polyline(list(entry.values())[0]) if list(entry.keys())[0] == "circle": p0 = list(entry.values())[0][0] p1 = list(entry.values())[0][1] p2 = list(entry.values())[0][2] solid = solid.moveTo(p0[0], p0[1]).threePointArc(p1, p2) solid = solid.close().revolve(self.rotation_angle) # Checks if the azimuth_placement_angle is a list of angles if isinstance(self.azimuth_placement_angle, Iterable): rotated_solids = [] # Perform seperate rotations for each angle for angle in self.azimuth_placement_angle: rotated_solids.append( solid.rotate((0, 0, -1), (0, 0, 1), angle)) solid = cq.Workplane(self.workplane) # Joins the seperate solids together for i in rotated_solids: solid = solid.union(i) else: # Peform rotations for a single azimuth_placement_angle angle solid = solid.rotate((0, 0, -1), (0, 0, 1), self.azimuth_placement_angle) self.perform_boolean_operations(solid) return solid
import cadquery as cq result = cq.Workplane("XY").box(90, 90, 90) """ pcd = 68; bc = (cq.Workplane("XY") .polygon(6, pcd, forConstruction=True) .vertices() .circle(2) .extrude(5) .translate((0,0,-5)) .rotate((0,0,0), (0,0,1), 15) ) """ def side(f): diameter = 6 depth = 10 boreDir = -f.normalAt() center = f.Center() # first make the hole hole = cq.Solid.makeCylinder(diameter / 2.0, depth, center, boreDir) # local coordianates! return hole result = (result.faces("#Z").each(side, True)) result.end().cut(result) show_object(result)
def create_solid(self): solid = None if self.points is not None: # obtains the first two values of the points list XZ_points = [(p[0], p[1]) for p in self.points] # obtains the last values of the points list connections = [p[2] for p in self.points[:-1]] current_linetype = connections[0] current_points_list = [] instructions = [] # groups together common connection types for i, connection in enumerate(connections): if connection == current_linetype: current_points_list.append(XZ_points[i]) else: current_points_list.append(XZ_points[i]) instructions.append( {current_linetype: current_points_list}) current_linetype = connection current_points_list = [XZ_points[i]] instructions.append({current_linetype: current_points_list}) if list(instructions[-1].values())[0][-1] != XZ_points[0]: keyname = list(instructions[-1].keys())[0] instructions[-1][keyname].append(XZ_points[0]) if hasattr(self, "path_points"): factor = 1 if self.workplane in ["XZ", "YX", "ZY"]: factor *= -1 solid = cq.Workplane(self.workplane).center(0, 0) if self.force_cross_section: for point in self.path_points[:-1]: solid = solid.workplane(offset=point[1] * factor).\ center(point[0], 0).workplane() for entry in instructions: if list(entry.keys())[0] == "spline": solid = solid.spline( listOfXYTuple=list(entry.values())[0]) if list(entry.keys())[0] == "straight": solid = solid.polyline(list(entry.values())[0]) if list(entry.keys())[0] == "circle": p0, p1, p2 = list(entry.values())[0][:3] solid = solid.moveTo(p0[0], p0[1]).\ threePointArc(p1, p2) solid = solid.close() solid = solid.center(-point[0], 0).\ workplane(offset=-point[1] * factor) elif self.force_cross_section == False: solid = solid.workplane(offset=self.path_points[0][1] * factor).center( self.path_points[0][0], 0).workplane() for entry in instructions: if list(entry.keys())[0] == "spline": solid = solid.spline( listOfXYTuple=list(entry.values())[0]) if list(entry.keys())[0] == "straight": solid = solid.polyline(list(entry.values())[0]) if list(entry.keys())[0] == "circle": p0 = list(entry.values())[0][0] p1 = list(entry.values())[0][1] p2 = list(entry.values())[0][2] solid = solid.moveTo(p0[0], p0[1]).threePointArc(p1, p2) solid = solid.close().center(0, 0).\ center(-self.path_points[0][0], 0).\ workplane(offset=-self.path_points[0][1] * factor) solid = solid.workplane(offset=self.path_points[-1][1] * factor).\ center(self.path_points[-1][0], 0).workplane() else: # for rotate and extrude shapes solid = cq.Workplane(self.workplane) # for extrude shapes if hasattr(self, "extrusion_start_offset"): extrusion_offset = -self.extrusion_start_offset solid = solid.workplane(offset=extrusion_offset) for entry in instructions: if list(entry.keys())[0] == "spline": solid = solid.spline(listOfXYTuple=list(entry.values())[0]) if list(entry.keys())[0] == "straight": solid = solid.polyline(list(entry.values())[0]) if list(entry.keys())[0] == "circle": p0 = list(entry.values())[0][0] p1 = list(entry.values())[0][1] p2 = list(entry.values())[0][2] solid = solid.moveTo(p0[0], p0[1]).threePointArc(p1, p2) return solid
#You run this example by typing the following in the FreeCAD python console, making sure to change #the path to this example, and the name of the example appropriately. #import sys #sys.path.append('/home/user/Downloads/cadquery/examples/FreeCAD') #import Ex021_Splitting_an_Object #If you need to reload the part after making a change, you can use the following lines within the FreeCAD console. #reload(Ex021_Splitting_an_Object) #You'll need to delete the original shape that was created, and the new shape should be named sequentially (Shape001, etc). #You can also tie these blocks of code to macros, buttons, and keybindings in FreeCAD for quicker access. #You can get a more information on this example at http://parametricparts.com/docs/examples.html#an-extruded-prismatic-solid import cadquery import Part #Create a simple block with a hole through it that we can split c = cadquery.Workplane("XY").box(1, 1, 1).faces(">Z").workplane().circle(0.25).cutThruAll() #Cut the block in half sideways result = c.faces(">Y").workplane(-0.5).split(keepTop=True) #Get a cadquery solid object solid = result.val() #Use the wrapped property of a cadquery primitive to get a FreeCAD solid Part.show(solid.wrapped) #Would like to zoom to fit the part here, but FreeCAD doesn't seem to have that scripting functionality
import cadquery as cq # Points we will use to create spline and polyline paths to sweep over pts = [(0, 1), (1, 2), (2, 4)] # Spline path generated from our list of points (tuples) path = cq.Workplane("XZ").spline(pts) # Sweep a circle with a diameter of 1.0 units along the spline path we just created defaultSweep = cq.Workplane("XY").circle(1.0).sweep(path) # Sweep defaults to making a solid and not generating a Frenet solid. Setting Frenet to True helps prevent creep in # the orientation of the profile as it is being swept frenetShell = cq.Workplane("XY").circle(1.0).sweep(path, makeSolid=True, isFrenet=True) # We can sweep shapes other than circles defaultRect = cq.Workplane("XY").rect(1.0, 1.0).sweep(path) # Switch to a polyline path, but have it use the same points as the spline path = cq.Workplane("XZ").polyline(pts) # Using a polyline path leads to the resulting solid having segments rather than a single swept outer face plineSweep = cq.Workplane("XY").circle(1.0).sweep(path) # Switch to an arc for the path path = cq.Workplane("XZ").threePointArc((1.0, 1.5), (0.0, 1.0)) # Use a smaller circle section so that the resulting solid looks a little nicer arcSweep = cq.Workplane("XY").circle(0.5).sweep(path) # Translate the resulting solids so that they do not overlap and display them left to right
A = A1 + A2 case = cq.Workplane("XY").box(D - A1, E - A1, A2) #margin to see fused pins if ef != 0: case.edges("|X").fillet(ef) case.edges("|Z").fillet(ef) #translate the object case = case.translate((0, 0, A / 2 + A1)).rotate((0, 0, 0), (0, 0, 1), 0) # first pin indicator is created with a spherical pocket sphere_r = (fp_r * fp_r / 2 + fp_z * fp_z) / (2 * fp_z) sphere_z = A + sphere_r * 2 - fp_z - sphere_r pinmark = cq.Workplane( "XZ", (-D / 2 + fp_d + fp_r, -E / 2 + fp_d + fp_r, A + fp_z)).rect( fp_r / 2, -fp_z, False).revolve() if (color_pin_mark == False) and (place_pinMark == True): case = case.cut(pinmark) bpin1 = cq.Workplane("XY"). \ moveTo(b, 0). \ lineTo(b, L-b/2). \ threePointArc((b/2,L),(0, L-b/2)). \ lineTo(0, 0). \ close().extrude(c).translate((b/2,E/2,0)) #close().extrude(c).translate((b/2,E/2,A1/2)) bpin = bpin1.rotate((b / 2, E / 2, A1 / 2), (0, 0, 1), 180)
def make_simple(self): # Just return the core cylinder return cadquery.Workplane('XY') \ .circle(self.diameter / 2) \ .extrude(-self.height)
def make(self): ob = cq.Workplane("XY").circle(self.diam / 2).extrude(self.length) return ob
def make(self): return cadquery.Workplane('XY') \ .box(self.length, self.width, self.thickness)
def generate_straight_body(params): num_pins = params.num_pins body_width = params.body_width body_height = params.body_height body_length = params.body_length body_plug_depth = 4.2 body_side_cutout_depth = 2 body_side_cutout_width = 0.8 body_side_cutout_from_front = 1.5 body_off_center_y = (body_front_width-body_back_width)/2 body = cq.Workplane("XY").workplane()\ .move(body_corner_x, body_corner_y)\ .rect(body_length, body_width, centered=False)\ .extrude(body_height) body = body.faces(">Z").workplane().move(0,body_off_center_y)\ .rect(body_length-2*body_side_width, body_width-body_front_width-body_back_width)\ .cutBlind(-body_plug_depth) pcs1 = (body_width/2-body_side_cutout_from_front, body_height/2) pcs2 = v_add(pcs1, (0, -body_side_cutout_depth+body_side_cutout_width/2)) pcs3 = v_add(pcs2, (-body_side_cutout_width, -0)) #pcsam = get_third_arc_point(pcs2, pcs3) pcsam = v_add(pcs2, (-body_side_cutout_width/2, -body_side_cutout_width/2)) body = body.faces("<X").workplane()\ .moveTo(pcs1[0], pcs1[1])\ .lineTo(pcs2[0], pcs2[1])\ .threePointArc(pcsam, pcs3)\ .line(0, body_side_cutout_depth-body_side_cutout_width/2).close()\ .cutThruAll() cutout1 = body.faces("<Y").workplane()\ .move(-body_length/2+body_front_main_cutout_to_side,body_height/2)\ .vLine(-body_front_main_cutout_depth)\ .hLineTo(body_length/2-body_front_main_cutout_to_side)\ .vLine(body_front_main_cutout_depth)\ .close().extrude(-1,False) body = body.cut(cutout1) cutout2 = cq.Workplane("XZ").workplane(offset=-body_corner_y)\ .moveTo(body_corner_x+body_front_cutout_from_side, body_height-body_front_cutout_from_top)\ .vLine(-body_front_cutout_height)\ .hLine(body_front_cutout_width)\ .vLine(body_front_cutout_height)\ .close().extrude(-1,False) body = body.cut(cutout2) cutout3 = cq.Workplane("XZ").workplane(offset=-body_corner_y)\ .moveTo(body_corner_x+body_length-body_front_cutout_from_side, body_height-body_front_cutout_from_top)\ .vLine(-body_front_cutout_height)\ .hLine(-body_front_cutout_width)\ .vLine(body_front_cutout_height)\ .close().extrude(-1,False) body = body.cut(cutout3) bottom_cutout_width = 1.5 bottom_cutout_depth = 0.2 bottom_cutout_platou_len = 1 bottom_cutout_platou_depth = 0.1 bottom_cutout = cq.Workplane("YZ").workplane(offset=-bottom_cutout_width/2)\ .moveTo(body_corner_y, 0).vLine(bottom_cutout_depth)\ .lineTo(-bottom_cutout_platou_len/2.0, bottom_cutout_platou_depth)\ .line(bottom_cutout_platou_len,0)\ .lineTo((body_width+body_corner_y), bottom_cutout_depth)\ .vLineTo(0).close().extrude(bottom_cutout_width) for i in range(0,num_pins): body = body.cut(bottom_cutout.translate((i*pin_pitch,0,0))) body_back_prodrucion_from_top = 2.3 body_back_prodrucion_width = 0.4 body_back_prodrucion_depth = 0.3 body_back_prodrucion = cq.Workplane("XY")\ .workplane(offset=body_height-body_plug_depth)\ .moveTo(pin_pitch/2.0, body_corner_y + body_width - body_back_width - body_back_prodrucion_depth/2.0)\ .rect(body_back_prodrucion_width, body_back_prodrucion_depth)\ .extrude(body_plug_depth - body_back_prodrucion_from_top) for i in range(num_pins-1): body = body.union(body_back_prodrucion.translate((i*pin_pitch,0,0))) body_pin1_prodrucion_depth = 0.05 body_pin1_prodrucion_width = 0.5 body_pin1_prodrucion = cq.Workplane("XY")\ .workplane(offset = body_height-body_front_cutout_from_top)\ .moveTo(body_corner_x + body_length - body_front_cutout_width - body_pin1_prodrucion_width/2.0, body_corner_y - body_pin1_prodrucion_depth/2.0)\ .rect(body_pin1_prodrucion_width, body_pin1_prodrucion_depth)\ .extrude(body_front_cutout_from_top) body = body.union(body_pin1_prodrucion) return body
import cadquery as cq # Create a plate with 4 counter-sunk holes in it. # 1. Establishes a workplane using an XY object instead of a named plane. # 2. Creates a plain box to base future geometry on with the box() function. # 3. Selects the top-most face of the box and established a workplane on that. # 4. Draws a for-construction rectangle on the workplane which only exists for # placing other geometry. # 5. Selects the corner vertices of the rectangle and places a counter-sink # hole, using each vertex as the center of a hole using the cskHole() # function. # 5a. When the depth of the counter-sink hole is set to None, the hole will be # cut through. result = (cq.Workplane(cq.Plane.XY()).box( 4, 2, 0.5).faces(">Z").workplane().rect( 3.5, 1.5, forConstruction=True).vertices().cskHole(0.125, 0.25, 82.0, depth=None)) # Displays the result of this script show_object(result)
# This example is meant to be used from within the CadQuery module of FreeCAD. import cadquery from Helpers import show # Make a basic prism result = cadquery.Workplane("front").box(3, 2, 0.5) # Select the lower left vertex and make a workplane result = result.faces(">Z").vertices("<XY").workplane() # Cut the corner out result = result.circle(1.0).cutThruAll() # Render the solid show(result)