예제 #1
0
    def importBox(self, importType, fileName):
        """
        Exports a simple box to a STEP file and then imports it again
        :param importType: The type of file we're importing (STEP, STL, etc)
        :param fileName: The path and name of the file to write to
        """
        # We're importing a STEP file
        if importType == importers.ImportTypes.STEP:
            # We first need to build a simple shape to export
            shape = Workplane("XY").box(1, 2, 3).val()

            # Export the shape to a temporary file
            shape.exportStep(fileName)

            # Reimport the shape from the new STEP file
            importedShape = importers.importShape(importType, fileName)

            # Check to make sure we got a solid back
            self.assertTrue(importedShape.val().ShapeType() == "Solid")

            # Check the number of faces and vertices per face to make sure we have a box shape
            self.assertTrue(
                importedShape.faces("+X").size() == 1
                and importedShape.faces("+X").vertices().size() == 4)
            self.assertTrue(
                importedShape.faces("+Y").size() == 1
                and importedShape.faces("+Y").vertices().size() == 4)
            self.assertTrue(
                importedShape.faces("+Z").size() == 1
                and importedShape.faces("+Z").vertices().size() == 4)
예제 #2
0
def to_assembly(*cad_objs, render_mates=None, mate_scale=None):
    assembly = PartGroup([], "Group")
    obj_id = 0
    for cad_obj in cad_objs:
        if isinstance(cad_obj, (PartGroup, Part, Faces, Edges, Vertices)):
            assembly.add(cad_obj)

        elif HAS_MASSEMBLY and isinstance(cad_obj, MAssembly):
            assembly.add(
                from_assembly(cad_obj,
                              cad_obj,
                              render_mates=render_mates,
                              mate_scale=mate_scale))

        elif isinstance(cad_obj, CqAssembly):
            assembly.add(from_assembly(cad_obj, cad_obj))

        elif isinstance(cad_obj, Edge):
            assembly.add_list(_from_edgelist(Workplane(cad_obj), obj_id))

        elif isinstance(cad_obj, Face):
            assembly.add_list(_from_facelist(Workplane(cad_obj), obj_id))

        elif isinstance(cad_obj, Wire):
            assembly.add(_from_wirelist(Workplane(cad_obj), obj_id))

        elif isinstance(cad_obj, Vertex):
            assembly.add_list(_from_vertexlist(Workplane(cad_obj), obj_id))

        elif is_cqparts(cad_obj):
            assembly = convert_cqparts(cad_obj)

        elif _is_facelist(cad_obj):
            assembly.add_list(_from_facelist(cad_obj, obj_id))

        elif _is_edgelist(cad_obj):
            assembly.add_list(_from_edgelist(cad_obj, obj_id))

        elif _is_wirelist(cad_obj):
            assembly.add(_from_wirelist(cad_obj, obj_id))

        elif _is_vertexlist(cad_obj):
            assembly.add_list(_from_vertexlist(cad_obj, obj_id))

        elif isinstance(cad_obj, Vector):
            assembly.add_list(_from_vector(cad_obj, obj_id))

        elif isinstance(cad_obj.val(), Vector):
            assembly.add_list(_from_vectorlist(cad_obj, obj_id))

        elif isinstance(cad_obj, Workplane):
            assembly.add(_from_workplane(cad_obj, obj_id))

        else:
            raise NotImplementedError("Type:", cad_obj)

        obj_id += 1
    return assembly
예제 #3
0
def enclosure(height):
    # Bottom enclosure part
    part = Workplane('XY').box(WIDTH, LENGTH, height)\
        .faces('+Z').shell(THICK)
    part = enclosure_passthrough_vertices(part.faces('>Z'))\
        .rect(PASS_OUTTER, PASS_OUTTER).extrude(-height)\
        .edges('|Z').fillet(2)
    part = enclosure_passthrough_vertices(part.faces('<Z'))\
        .cboreHole(PASS_INNER, PASS_CBORE, PASS_CBORE_DEPTH)
    return part
예제 #4
0
    def relocate(name, shape):
        a = assy.objects[name]
        loc = a.loc

        parent = a.parent
        while parent is not None:
            loc = parent.loc * loc
            parent = parent.parent

        if isinstance(shape, str):
            shape = assy._query(shape)[1]
        return Workplane(Workplane(shape).val().located(loc))
예제 #5
0
def to_edge(mate, loc=None, scale=1) -> Workplane:
    w = Workplane()
    for d in (mate.x_dir, mate.y_dir, mate.z_dir):
        edge = Edge.makeLine(mate.origin, mate.origin + d * scale)
        w.objects.append(edge if loc is None else edge.moved(loc))

    return w
예제 #6
0
 def _relocate(assy, origins):
     origin_mate = origins.get(assy.name)
     if origin_mate is not None:
         assy.obj = Workplane(assy.obj.val().moved(origin_mate.loc.inverse))
         assy.loc = Location()
     for c in assy.children:
         _relocate(c, origins)
예제 #7
0
def applyToEachFace(
    wp: cq.Workplane,
    f_workplane_selector: Callable[[cq.Face], cq.Workplane],
    f_draw: Callable[[cq.Workplane, cq.Face], cq.Workplane],
) -> cq.Workplane:
    """
    Basically equivalent to `Workplane.each(..)` but
    applicable only to faces and with tasks of face coordinate
    system selection and actually drawing in this coordinate
    system separated.

    :param wp: Workplane with some faces selected
    :param f_workplane_selector: callback that accepts
        a face and returns a Workplane (a coordinate system to
        that is passed to `f_draw`). See `XAxisInPlane`
        and `XAxisClosestTo`
    :param f_draw: a callback that accepts a workplane and
        a face and draws something in that workplane
    """
    def each_callback(face):
        wp_face = f_workplane_selector(face)

        return f_draw(wp_face, face).vals()[0]

    return wp.each(each_callback)
예제 #8
0
def from_assembly(cad_obj, top, loc=None, render_mates=False, mate_scale=1):
    loc = Location()
    render_loc = cad_obj.loc

    color = Color(get_rgb(cad_obj.color))

    parent = [
        Part(
            Workplane(shape),
            "%s_%d" % (cad_obj.name, i),
            color=color,
        ) for i, shape in enumerate(cad_obj.shapes)
    ]

    if render_mates and cad_obj.mates is not None:
        RGB = (Color((255, 0, 0)), Color((0, 128, 0)), Color((0, 0, 255)))
        parent.append(
            PartGroup(
                [
                    Part(to_edge(mate_def.mate, scale=mate_scale),
                         name=name,
                         color=RGB) for name, mate_def in top.mates.items()
                    if mate_def.assembly == cad_obj
                ],
                name="mates",
                loc=Location(
                ),  # mates inherit the parent location, so actually add a no-op
            ))

    children = [
        from_assembly(c, top, loc, render_mates, mate_scale)
        for c in cad_obj.children
    ]
    return PartGroup(parent + children, cad_obj.name, loc=render_loc)
예제 #9
0
def mounting_holes(parent: cq.Workplane) -> cq.Workplane:
    global mount_inset, mount_radius
    ct = CenterTracker()
    for x, y in [(1, 1), (-1, 1), (1, -1), (-1, -1)]:
        parent = ct.push(parent, x * (width / 2 - mount_inset),
                         y * (height / 2 - mount_inset))
        parent = parent.circle(mount_radius)
        parent = ct.pop(parent)
    return parent
예제 #10
0
def updatePending(wp: cq.Workplane) -> cq.Workplane:
    """
    Clear pendingWires and pendingEdges and then add
    objects that are wires or edges to the appropriate
    pending list. Another way to fix this would be to
    add a parameter to toPending which would do the
    clear before the extending operation.

    Fix cq bug https://github.com/CadQuery/cadquery/issues/421
    """
    wp.ctx.pendingWires = []
    wp.ctx.pendingEdges = []
    return wp.toPending()
예제 #11
0
    def addReceiver(
            self,
            shape: cq.Workplane,
            face: str,
            location: Tuple[float, float, float] = (0, 0, 0),
    ) -> cq.Workplane:
        """
        Add a receiver to the face of the shape passed.
        """

        show(shape, name="shape")
        f = shape.faces(face)
        dbg(f"f={f}")
        show(f, name="f")
        r = self.receiver
        show(r, name="r")
        # f.cut(self.receiver.rotate((0, 0, 0), (1, 0, 0), 180).translate((0, 0, bodyLen))
        # cq.SelectbodyLen = 30
        # body = cq.Workplane("XY").circle(bodyDiameter / :2).extrude(bodyLen)
        # body1 = body.cut(
        #    c.receiver.rotate((0, 0, 0), (1, 0, 0), 180).translate((0, 0, bodyLen))
        # ).cut(c.receiver)
        # show(body1, name="body1")
        return shape
예제 #12
0
from cadquery import Workplane as WP
from pallet import Pallet
from gear import gear

GEARS = False

P = Pallet()

od, id, l, fw, v = 30, 3, 20, 4, 5
d1, d2 = 5, 5
mod, teeth, bore, width, helixAngle = 2, 15, 2, l, 0
n = 31 / 2

outline = [(-21, -21), (-21, 21), (42, 21), (42, -21)]

box = WP("YZ").polyline(outline).close().extrude(6)

box = box.cut(WP("YZ").circle(22.3/2).pushPoints([(n,n),(-n,n),(n,-n),(-n,-n)])\
              .circle(3.5/2).extrude(6)).faces(">X").edges("%circle").chamfer(2.5)

box = box.union(
    WP("YZ").moveTo(od, 0).circle(
        9.8 / 2).extrude(16).faces(">X").edges().chamfer(1))

box = box.faces(">Y").edges("|X").fillet(5)
box = box.faces("<Y").edges("|X").fillet(5)

cq.exporters.export(box.rotate((0, 0, 0), (0, 1, 0), -90), "box.stl")
cq.exporters.export(box.rotate((0, 0, 0), (0, 1, 0), -90), "box.step")

show_object(box)
예제 #13
0
def to_compound(obj : cq.Workplane):
    
    return cq.Compound.makeCompound(obj.vals())
예제 #14
0
from math import cos, sin, pi

h, w, l, wall = 40, 60, 100, 3
laserS = 33.3
railP, railD = 50, 6.5
motorBossD, motorBossL, motorMountP = 12.5, 16, 35
caridgeH, caridgeL = 30, 40
plateT = 8
plateW, plateH = 81, 100

motorD = WP().circle(26 / 2)
motor = WP().pushPoints([(motorMountP / 2, 0),
                         (-motorMountP / 2, 0)]).circle(4.3 / 2)
laser = WP()

caridge = WP().rect(w, caridgeH).extrude(caridgeL)
caridge = caridge.cut(WP().pushPoints([(railP / 2, 0), (-railP / 2, 0)
                                       ]).circle(railD / 2).extrude(h))
caridge = caridge.cut(WP().rect(
    railP - wall * 2 - railD, caridgeH - wall * 2).extrude(
        (caridgeL - 5.6) / 2).edges("|Z").fillet(wall))
caridge = caridge.cut(WP().workplane(offset=caridgeL).rect(
    railP - wall * 2 - railD, caridgeH - wall * 2).extrude(
        -(caridgeL - 5.6) / 2).edges("|Z").fillet(wall))
caridge = caridge.cut(WP().circle(2.5 / 2).extrude(caridgeL))
caridge = caridge.union(WP().moveTo(0, laserS / 2 + caridgeH / 2).rect(
    laserS, laserS).rect(laserS + wall * 2,
                         laserS + wall * 2).extrude(caridgeL))
caridge = caridge.faces("<X or >X").edges("|Z").chamfer(8)
caridge = caridge.faces("<X[-2] or >X[-2] or >X or <X").edges("|Z").fillet(
    wall / 2)
예제 #15
0
#compartmentalized tray
from cadquery import Workplane as WP
import cadquery as cq

h, w, d, wall = 30, 170, 170, 2
rows, cols = 3, 3
fillet = wall

cw = (w - wall * (cols + 1)) / cols
rw = (w - wall * (rows + 1)) / rows

cp = w / cols
rp = d / rows

a = WP().rect(w, d).extrude(h)

for y in range(rows):
    Y = -float(rp * rows - rp) / 2 + y * rp
    for x in range(cols):
        X = -float(cp * cols - cp) / 2 + x * cp
        a = a.cut(WP().workplane(offset=wall).moveTo(X, Y).rect(
            cw, rw).extrude(h * 2))

a = a.edges("|Z").fillet(fillet)
a = a.faces("<Z").edges().chamfer(wall)
a = a.cut(WP().workplane(offset=h - wall / 2).rect(
    w, d).extrude(h).faces("<Z").edges().chamfer(wall))

cq.exporters.export(
    a, f"tray-({h}x{w}x{d})-rows({rows})-cols({cols})-wall({wall}).stl")
예제 #16
0
#clares watch thingy
from cadquery import Workplane as WP

wD, oD, h, ledD = 40, 55, 25, 12
knobD = 7
strapW = 30

a = WP().circle(ledD / 2).circle(oD / 2).extrude(h)
a = a.cut(WP().workplane(offset=h).rect(oD, strapW).extrude(-10))
a = a.cut(WP().workplane(offset=h).moveTo(0, oD / 2).rect(knobD,
                                                          oD).extrude(-10))
a = a.cut(WP().workplane(offset=h).moveTo(12.5, -5.2).lineTo(
    12.5, 5.2).close().offset2D(7.6 / 2).extrude(-18))
a = a.cut(WP().workplane(offset=h).moveTo(12.5, 0).lineTo(
    12.5, -oD).close().offset2D(6.5 / 2).extrude(-17))
a = a.cut(WP().workplane(offset=h).lineTo(-oD, 12).lineTo(
    -oD, -12).close().offset2D(ledD / 2).extrude(-h))
a = a.cut(WP().workplane(offset=h).circle(40.5 / 2).extrude(-10))
a = a.edges("|Z").fillet(2)
a = a.faces(">Z").edges().fillet(1)

cq.exporters.export(a, "claresWatchStand.stl")
예제 #17
0
def _from_vector(vec, obj_id, name="Vector"):
    tmp = Workplane()
    obj = tmp.newObject([vec])
    return _from_vectorlist(obj, obj_id, name)
예제 #18
0
def from_assembly(cad_obj,
                  top,
                  loc=None,
                  render_mates=False,
                  mate_scale=1,
                  default_color=None):
    loc = Location()
    render_loc = cad_obj.loc

    if cad_obj.color is None:
        if default_color is None:
            color = Color(get_default("default_color"))
        else:
            color = Color(default_color)
    else:
        color = Color(get_rgb(cad_obj.color))

    # Special handling for edge lists in an MAssembly
    is_edges = [isinstance(obj, Edge) for obj in cad_obj.shapes]
    if is_edges and all(is_edges):
        if cad_obj.color is None:
            if default_color is None:
                color = Color(get_default("default_edgecolor"))
            else:
                color = Color(default_color)
        else:
            color = Color(get_rgb(cad_obj.color))

        workplane = Workplane()
        workplane.objects = cad_obj.shapes
        parent = [Edges(
            workplane,
            name="%s_0" % cad_obj.name,
            color=color,
        )]
    else:
        if cad_obj.color is None:
            if default_color is None:
                color = Color(get_default("default_color"))
            else:
                color = Color(default_color)
        else:
            color = Color(get_rgb(cad_obj.color))
        parent = [
            Part(
                Workplane(shape),
                "%s_%d" % (cad_obj.name, i),
                color=color,
            ) for i, shape in enumerate(cad_obj.shapes)
        ]

    if render_mates and cad_obj.mates is not None:
        rgb = (Color((255, 0, 0)), Color((0, 128, 0)), Color((0, 0, 255)))
        pg = PartGroup(
            [
                Edges(to_edge(mate_def.mate, scale=mate_scale),
                      name=name,
                      color=rgb) for name, mate_def in top.mates.items()
                if mate_def.assembly == cad_obj
            ],
            name="mates",
            loc=Location(
            ),  # mates inherit the parent location, so actually add a no-op
        )
        if pg.objects:
            parent.append(pg)

    children = [
        from_assembly(c, top, loc, render_mates, mate_scale)
        for c in cad_obj.children
    ]
    return PartGroup(parent + children, cad_obj.name, loc=render_loc)
예제 #19
0
from cadquery import Workplane as WP
import cadquery as cq

h = 34
D = 30
r = 3
N = 3
flange = 2
c = 0.5

#thread_profile = cq.Workplane("XZ",origin=(R,0,0)).circle(r)
#path = cq.Workplane("XY", obj=cq.Wire.makeHelix(R,N*R,R))
#res = thread_profile.sweep(path)

a = WP().circle(D / 2).extrude(h)
a = a.union(WP().circle(D / 2 +
                        2).extrude(flange).faces(">Z").edges().chamfer(flange -
                                                                       c))
a = a.union(WP().workplane(
    offset=h -
    flange).circle(D / 2 +
                   2).extrude(flange).faces("<Z").edges().chamfer(flange - c))

b = WP("YZ").center(D/2,h/2).polyline([(2,-4),(2,4),(-3,2.2),(-3,-2.2)]).close().extrude(20,both=True)\
    .edges("|X").fillet(2).rotate((0,0,0),(0,1,0),10)

for n in range(-12, 12):
    a = a.cut(
        b.rotate((0, 0, 0), (0, 0, 1), n * 30).translate((0, 0, n * 0.75)))

w = (2.5**2 - 1.9**2)**0.5
예제 #20
0
def cutRectOfPolarArray(part: cq.Workplane, point, rotateAnglesList):
    for rotateAngle in rotateAnglesList:
        part = part.rotate((0, 0, 0), (0, 0, 1), rotateAngle)
        part = part.moveTo(*point).rect(10, 15).cutThruAll(clean=True)
        part = part.rotate((0, 0, 0), (0, 0, 1), -rotateAngle)
    return part
예제 #21
0
from cadquery import Workplane as WP
import cadquery as cq

pitch,d,h,w,n  = 2.54, 2, 8, 4, 4

#pts = [(3.81,0),(1.27,0),(-1.27.0),(-3.81,0)]
pts = [(pitch*(p- n/2+ 0.5),0) for p in range(n)]
for p in pts: log(p)

a = WP().rect((pitch+0.5)*n,w).extrude(h)
a = a.cut(WP().pushPoints(pts).circle(2/2).extrude(h))

cq.exporters.export(a.rotate((0,0,0),(0,0,1),a),f"housing-{n}-way-{pitch}-pitch.stl")
예제 #22
0
verbose = False

d1, pcd, pin, pitch, t = 20, 15, 3, 30, -3

#calculate link lenght at limit of design travel -45 degrees | (-pi/4) radians
y = pcd / 2 * cos(-pi / 4)
linkLength = ((y * 2)**2 + pitch**2)**0.5

log("*" * 80)
N = 20
for n in range(N):
    theta = (n - N / 2) * pi / (N * 2)
    x1, y1 = pcd / 2 * sin(theta), pcd / 2 * cos(theta)
    linkLength = ((y1 * 2)**2 + pitch**2)**0.5
    lv = ((x1 - pitch)**2 + (y1)**2)**0.5
    wheel1 = WP().circle(d1 / 2).moveTo(x1, y1).circle(pin / 2).extrude(t)
    #wheel1 = wheel1.cut(WP().moveTo(-d1/2,0).rect(4,d1).extrude(t).rotate())

    #rearange Cosine rule to get angle between lv and linklenght CosA = (b² + c² - a²)/2bc
    gamma = atan(y1 / abs(x1 - pitch)) + acos(
        (linkLength**2 + lv**2 - (pcd / 2)**2) / (2 * linkLength * lv))

    if verbose:
        log(f"x1:{round(x1,3)} y1:{round(y1,3)} lenght:{abs(x1-pitch)/y1} gamma:{gamma}"
            )
    #log(gamma)

    #x2,y2 are relative to wheel 2 center
    x2, y2 = linkLength * cos(
        gamma) + x1 - pitch, linkLength * -sin(gamma) + y1
    wheel2 = WP().circle(d1 / 2).moveTo(x2, y2).circle(
예제 #23
0
def _from_sketch(cad_obj, obj_id, show_parent=True, show_selection=True):

    result = []

    locs = cad_obj.locs if cad_obj.locs else [Location()]

    workplane = Workplane()
    if cad_obj._faces:
        for loc in locs:
            workplane.objects += cad_obj._faces.moved(loc).Faces()
        result += _from_facelist(workplane,
                                 obj_id,
                                 name="Faces",
                                 show_parent=show_parent)
    elif cad_obj._edges:
        workplane.objects = [
            edge.moved(loc) for edge in cad_obj._edges for loc in locs
        ]
        result += _from_edgelist(workplane,
                                 obj_id,
                                 name="Edges",
                                 show_parent=show_parent)

    if show_selection and cad_obj._selection:
        workplane = Workplane()
        if isinstance(cad_obj._selection[0], Location):
            workplane.objects = [
                Vertex.makeVertex(0, 0, 0).moved(loc * obj)
                for obj in cad_obj._selection for loc in locs
            ]
            sel = _from_vertexlist(workplane,
                                   obj_id,
                                   name="Locations",
                                   show_parent=show_parent)

        elif isinstance(cad_obj._selection[0], Face):
            for loc in locs:
                workplane.objects += flatten([
                    obj._faces.moved(loc).Faces() for obj in cad_obj._selection
                ])
            sel = _from_facelist(workplane,
                                 obj_id,
                                 name="Faces",
                                 show_parent=show_parent)

        elif isinstance(cad_obj._selection[0], (Edge, Wire)):
            workplane.objects = [
                edge.moved(loc) for edge in cad_obj._selection for loc in locs
            ]
            sel = _from_edgelist(workplane,
                                 obj_id,
                                 name="Edges",
                                 show_parent=show_parent)

        elif isinstance(cad_obj._selection[0], Vertex):
            workplane.objects = [
                vertex.moved(loc) for vertex in cad_obj._selection
                for loc in locs
            ]
            sel = _from_vertexlist(workplane,
                                   obj_id,
                                   name="Vertices",
                                   show_parent=show_parent)

        result.append(PartGroup(sel, name=f"Selection_{obj_id}"))

    return result
예제 #24
0
def show_constraints(assy, qs):
    colors = [
        "#e41a1c",
        "#377eb8",
        "#4daf4a",
        "#984ea3",
        "#ff7f00",
        "#ffff33",
        "#a65628",
        "#f781bf",
        "#999999",
        "#8dd3c7",
        "#ffffb3",
        "#bebada",
        "#fb8072",
        "#80b1d3",
        "#fdb462",
        "#b3de69",
        "#fccde5",
        "#d9d9d9",
    ]

    constraints = []
    objects = []
    cache = {}

    for i, q1q2 in enumerate(qs):
        parts = []

        kind = q1q2[-1]

        if len(q1q2) == 3:
            q1q2 = ((q1q2[0].split("@")[0], q1q2[0]), (q1q2[1].split("@")[0], q1q2[1]))
        else:
            q1q2 = (q1q2[0:2], q1q2[2:4])

        for q in q1q2:
            name, shape = q
            if name in cache:
                obj = cache[name]["obj"]
                loc = cache[name]["loc"]
            else:
                obj = assy.objects[name].obj
                loc = assy.objects[name].loc

                parent = assy.objects[name].parent
                while parent is not None:
                    loc = parent.loc * loc
                    parent = parent.parent

                cache[name] = {"obj": obj, "loc": loc, "shape": shape}

                objects.append(Part(Workplane(obj.val().located(loc)), name=name, show_faces=False))

            label = str(shape)
            if isinstance(shape, str):
                shape = assy._query(shape)[1]

            parts.append(
                Faces(
                    Workplane(Workplane(shape).val().located(loc)),
                    name=html.escape(label),
                    color=colors[i % len(colors)],
                )
            )
        constraints.append(PartGroup(parts, "%s_%d" % (kind, i)))

    show(PartGroup([PartGroup(objects, "objects")] + constraints), axes=True, axes0=True)
예제 #25
0
def to_assembly(*cad_objs,
                name="Group",
                render_mates=None,
                mate_scale=1,
                default_color=None,
                show_parent=True):
    default_color = get_default(
        "default_color") if default_color is None else default_color
    assembly = PartGroup([], name)
    obj_id = 0
    for cad_obj in cad_objs:
        if isinstance(cad_obj, (PartGroup, Part, Faces, Edges, Vertices)):
            _debug(
                f"CAD Obj {obj_id}: PartGroup, Part, Faces, Edges, Vertices")
            assembly.add(cad_obj)

        elif HAS_MASSEMBLY and isinstance(cad_obj, MAssembly):
            _debug(f"CAD Obj {obj_id}: MAssembly")
            assembly.add(
                from_assembly(cad_obj,
                              cad_obj,
                              render_mates=render_mates,
                              mate_scale=mate_scale,
                              default_color=default_color))

        elif isinstance(cad_obj, CqAssembly):
            _debug(f"CAD Obj {obj_id}: cqAssembly")
            assembly.add(
                from_assembly(cad_obj, cad_obj, default_color=default_color))

        elif isinstance(cad_obj, Edge):
            _debug(f"CAD Obj {obj_id}: Edge")
            assembly.add_list(
                _from_edgelist(Workplane(cad_obj),
                               obj_id,
                               show_parent=show_parent))

        elif isinstance(cad_obj, Sketch):
            _debug(f"CAD Obj {obj_id}: Sketch")
            assembly.add_list(
                _from_sketch(
                    cad_obj,
                    obj_id,
                    show_parent=show_parent,
                ))

        elif isinstance(cad_obj, Face):
            _debug(f"CAD Obj {obj_id}: Face")
            assembly.add_list(
                _from_facelist(Workplane(cad_obj),
                               obj_id,
                               show_parent=show_parent))

        elif isinstance(cad_obj, Wire):
            _debug(f"CAD Obj {obj_id}: Wire")
            assembly.add(
                _from_wirelist(Workplane(cad_obj),
                               obj_id,
                               show_parent=show_parent))

        elif isinstance(cad_obj, Vertex):
            _debug(f"CAD Obj {obj_id}: Vertex")
            assembly.add_list(
                _from_vertexlist(Workplane(cad_obj),
                                 obj_id,
                                 show_parent=show_parent))

        elif _is_facelist(cad_obj):
            _debug(f"CAD Obj {obj_id}: facelist")
            assembly.add_list(
                _from_facelist(cad_obj, obj_id, show_parent=show_parent))

        elif _is_edgelist(cad_obj):
            _debug(f"CAD Obj {obj_id}: edgelist")
            assembly.add_list(
                _from_edgelist(cad_obj, obj_id, show_parent=show_parent))

        elif _is_wirelist(cad_obj):
            _debug(f"CAD Obj {obj_id}: wirelist")
            assembly.add_list(
                _from_wirelist(cad_obj, obj_id, show_parent=show_parent))

        elif _is_vertexlist(cad_obj):
            _debug(f"CAD Obj {obj_id}: vertexlist")
            assembly.add_list(
                _from_vertexlist(cad_obj, obj_id, show_parent=show_parent))

        elif isinstance(cad_obj, Vector):
            _debug(f"CAD Obj {obj_id}: Vector")
            assembly.add_list(_from_vector(cad_obj, obj_id))

        elif isinstance(cad_obj, (Shape, Compound)):
            _debug(f"CAD Obj {obj_id}: Shape, Compound")
            assembly.add(
                _from_workplane(Workplane(cad_obj),
                                obj_id,
                                default_color=default_color,
                                show_parent=show_parent))

        elif is_compound(cad_obj):
            _debug(f"CAD Obj {obj_id}: TopoDS Compound")
            assembly.add(_Part([cad_obj], color=default_color))

        elif is_shape(cad_obj):
            _debug(f"CAD Obj {obj_id}: TopoDS Shape")
            assembly.add(_Part([cad_obj], color=default_color))

        elif isinstance(cad_obj.val(), Vector):
            _debug(f"CAD Obj {obj_id}: Vector val()")
            assembly.add_list(
                _from_vectorlist(cad_obj, obj_id, show_parent=show_parent))

        elif isinstance(cad_obj, Workplane):
            _debug(f"CAD Obj {obj_id}: Workplane")
            if len(cad_obj.vals()) == 1 and not isinstance(
                    cad_obj.val(), Sketch):
                assembly.add(
                    _from_workplane(cad_obj,
                                    obj_id,
                                    default_color=default_color,
                                    show_parent=show_parent))
            else:
                assembly2 = PartGroup([], name="Group_%s" % obj_id)
                for j, obj in enumerate(cad_obj.vals()):
                    if isinstance(obj, Sketch):
                        for sketch_obj in _from_sketch(obj,
                                                       j,
                                                       show_parent=False):
                            assembly2.add(sketch_obj)
                    else:
                        assembly2.add(
                            _from_workplane(Workplane(obj),
                                            j,
                                            default_color=default_color,
                                            show_parent=show_parent))
                assembly.add(assembly2)

        else:
            raise NotImplementedError("Type:", cad_obj)

        obj_id += 1
    return assembly
예제 #26
0
def lineTo_scaled(wp: cq.Workplane, x, y, v) -> cq.Workplane:
    return wp.lineTo(x * v, y * v)
예제 #27
0
import cadquery as cq
from cadquery import Workplane as WP

Dc, Ds, Kw, Kh = 40, 24.2, 8.2, 27.2
p = ((Ds / 2)**2 - (Kw / 2)**2)**0.5

keyway = WP().moveTo(-Kw/2,p).threePointArc((0,-Ds/2),(Kw/2,p))\
    .lineTo(Kw/2,Kh-Ds/2).lineTo(-Kw/2,Kh-Ds/2).close().extrude(40)\
    .translate((0,0,-30))

c = WP().circle(Dc / 2).extrude(5).cut(keyway)

r = -120
txt = WP()
for t in f"{Kw}x{Kh}x{Ds}":
    txt = txt.union(WP().text(t, 8, 5.5).translate(
        (0, -Dc / 2 + (Dc - Ds) / 4, 0)).rotate((0, 0, 0), (0, 0, 1), r))
    r += 20

c = c.union(txt)

show_object(c)

cq.exporters.export(c, "0point2.stl")
예제 #28
0
from cadquery import Workplane as WP
import cadquery as cq

tag = WP().moveTo(0, 6).text("LIZZIE", 10, 1)
tag = WP().moveTo(0, 6).text("HARGREAVES", 10, 1)
tag = tag.union(WP().polygon(5, 50).extrude(-2))

#cq.exporters.export(a.rotate((0,0,0),(0,0,1),a),f"housing-{n}-way-{pitch}-pitch.stl")
예제 #29
0
from cadquery import Workplane as WP
import cadquery as cq

pins, pitch, sq, h, w = 6, 2, 1, 6, 3.3
offset = (pitch * (pins - 1)) / 2
clearance = 0.2

a = WP().rect(pitch * pins + pitch / 2 - clerance, w).extrude(h - 1)
#a = WP().moveTo()

for p in range(pins):
    log(f"{offset + p*pitch} , {p}")
    a = a.cut(WP().moveTo(-offset + p * pitch, 0.6).rect(sq, sq).extrude(h))

cq.exporters.export(a, f"JST-PH_housing-{pins}_way.stl")
예제 #30
0
from math import sin, cos, pi
from cadquery import Workplane as WP
import cadquery as cq

AF = 12.2
r = 12.2 / cos(pi / 6) / 2
pts = [(r * cos(p * pi / 3), r * sin(p * pi / 3)) for p in range(6)]
part = WP().polyline(pts).close().extrude(-4)

pts = [(0, 0), (8, 0), (11.5, 11), (11.5, 22), (0, 22)]
part = part.union(
    WP("XZ").polyline(pts).close().revolve(360, (0, 0, 0), (0, 1, 0)))

r, af = 5.1 / 2, 4.5
y = af - r
x = (r**2 - y**2)**0.5
part = part.cut(WP().workplane(offset=22).moveTo(x, y).threePointArc(
    (0, -r), (-x, y)).close().extrude(-15))
part = part.cut(WP().workplane(offset=-4).circle(3.3 / 2).extrude(12))
part = part.cut(
    WP("YZ").polyline([(AF / 2, -4), (AF / 2 + 4, -4), (AF / 2 + 4, 0)
                       ]).close().revolve(360, (0, 0, 0), (0, 1, 0)))