Example #1
0
 def build_part(self, params):
     key = params.pop('classname', None)
     if key in self.class_dict:
         fixes = {}
         for i in params:
             try:
                 fixes[i] = float(params[i])
             except:
                 pass
         item = self.class_dict[key]
         o = item.c(**fixes)
         display(o)
Example #2
0
 def params(self, key):
     if self.exists(key) == False:
         abort(404)
     t = self.k[key]
     if t.built == False:
         t.inst = t.c()
         display(t.inst)
         t.built = True
     d = {}
     pi = t.inst.params().items()
     for i in pi:
         # only grab the floats for now
         if isinstance(i[1], float):
             d[i] = i[1]
         if isinstance(i[1], int):
             d[i] = i[1]
     info = t.info()
     info['params'] = d
     #if isinstance(t.inst,cqparts.Assembly):
     #    info['tree'] = t.inst.tree_str()
     return info
Example #3
0
from cqparts.utils.geometry import CoordSystem
from cqparts_gears import trapezoidal


class TestGear(trapezoidal.TrapezoidalGear):
    effective_radius = PositiveFloat(90)
    tooth_count = PositiveInt(20)
    width = PositiveFloat(20)


class GearStack(cqparts.Part):
    post = PositiveFloat(20)
    offset = PositiveFloat(30)

    def make(self):
        wp = cq.Workplane("XY")
        post = wp.circle(self.post).extrude(self.offset)
        g1 = TestGear().make()
        g2 = (TestGear(tooth_count=14, effective_radius=30).make().translate(
            (0, 0, self.offset)))
        post = post.union(g1)
        post = post.union(g2)
        return post


if __name__ == "__main__":
    from cqparts.display import display

    g = GearStack()
    display(g)
Example #4
0
                self.components["base"].mate_front(),
            ),
            Coincident(
                self.components["Ldrive_b"].mate_corner(flip=-1),
                self.components["base"].mate_RL(),
            ),
            Coincident(
                self.components["Rdrive_b"].mate_corner(flip=1),
                self.components["base"].mate_RR(),
            ),
            Coincident(
                self.components["Ldrive_f"].mate_corner(flip=1),
                self.components["base"].mate_RL(offset=self.length -
                                                self.chamfer),
            ),
            Coincident(
                self.components["Rdrive_f"].mate_corner(flip=-1),
                self.components["base"].mate_RR(offset=self.length -
                                                self.chamfer),
            ),
        ]
        return constr


if __name__ == "__main__":
    from cqparts.display import display

    # B = RobotBase()
    B = Rover()
    display(B)
Example #5
0
# ------------------- Export / Display -------------------
from cqparts.utils.env import env_name

# ------- Models
wheel = Wheel()
axle = Axle()
chassis = Chassis()
wheeled_axle = WheeledAxle(right_width=2)
car = Car()

if env_name == 'cmdline':
    wheel.exporter('gltf')('wheel.gltf')
    axle.exporter('gltf')('axle.gltf')
    chassis.exporter('gltf')('chassis.gltf')
    wheeled_axle.exporter('gltf')('wheel-assembly.gltf')
    print(wheeled_axle.tree_str(name='wheel_assembly'))
    car.exporter('gltf')('car.gltf')
    print(car.tree_str(name='car'))
    car.find('chassis').exporter('gltf')('chassis-altered.gltf')


elif env_name == 'freecad':
    pass  # manually switchable for testing
    #display(wheel)
    #display(axle)
    #display(chassis)
    #display(wheeled_axle)
    display(car)
    #display(car.find('chassis'))
Example #6
0
        cutout = cq.Workplane("XY").circle(self.diam / 2).extrude(self.length)
        return cutout

    # TODO , mate for shafts

    def get_cutout(self, clearance=0):
        " clearance cut out for shaft "
        return (cq.Workplane(
            "XY", origin=(0, 0, 0)).circle((self.diam / 2) +
                                           clearance).extrude(self.length * 2))

    def mate_tip(self, offset=0):
        return Mate(
            self,
            CoordSystem(origin=(0, 0, self.length),
                        xDir=(1, 0, 0),
                        normal=(0, 0, 1)),
        )


class BearingMount(cqparts.Assembly):
    pass


if __name__ == "__main__":
    from cqparts.display import display

    # sb = SimpleBearing()
    t = BearingMount()
    display(t)
Example #7
0
            'base': base,
            'top': top,
            'fastener': NutAndBoltFastener(parts=[base, top]),
        }

    def make_constraints(self):
        base = self.components['base']
        top = self.components['top']
        fastener = self.components['fastener']
        return [
            Fixed(base.mate_bottom),
            Coincident(top.mate_bottom, base.mate_top),
            Coincident(fastener.mate_origin, top.mate_top),
        ]


thing = Thing()

# ------------------- Export -------------------

from cqparts.params import *
from cqparts.display import display

from cqparts.display import get_display_environment
env_name = get_display_environment().name

if env_name == 'freecad':
    display(thing)
else:
    thing.exporter('gltf')('thing.gltf', embed=False)
Example #8
0
        constr = [
            Fixed(self.components["stepper"].mate_origin),
            Coincident(
                self.components["drive"].pulley_A_mate(offset=10),
                self.components["stepper"].mate_origin,
            ),
            Coincident(
                self.components["idler"].mate_origin,
                self.components["drive"].pulley_B_mate(offset=10),
            ),
        ]
        return constr

    def mate_mount(self, offset=0):
        return Mate(
            self,
            CoordSystem(origin=(0, 0, 0), xDir=(1, 0, 0), normal=(0, 1, 0)))


## test setup
class MyPulley(Pulley):
    rad = PositiveFloat(7)


if __name__ == "__main__":
    from cqparts.display import display

    p = BeltDrive(pulley=MyPulley, length=100)
    # p = ThreadedDrive(length=50)
    display(p)
    cqparts.search.class_criteria[cls].get('name', set())
    for cls in cqparts.solidtypes.threads.search()
]
names_list = set()
for name_set in name_sets:
    names_list |= name_set
names_list = sorted(names_list)


from cqparts.utils.env import env_name
if (not args.name) and (env_name == 'freecad'):
    args.name = 'triangular'

if not args.name or args.list:
    # List screw drives and exit
    for name in names_list:
        print("  - %s" % name)

else:
    thread = find(name=args.name)()
    thread._simple = False  # force complex threads

    if env_name == 'freecad':
        # force complex thread
        from Helpers import show
        show(thread.local_obj)
        show(thread.profile)

    else:
        display(thread)
Example #10
0
        board = board.cut(holes)
        return board


@register(export="controller")
class GlasgowRevC(PCBBoard):
    length = PositiveFloat(80.0)
    width = PositiveFloat(49)
    thickness = PositiveFloat(1)
    hole_size = PositiveFloat(3.2)
    corner_radius = PositiveFloat(4)

    hole_length = PositiveFloat(72.0)
    hole_width = PositiveFloat(41.0)

    def make(self):
        board = super(GlasgowRevC, self).make()
        return board


if __name__ == "__main__":
    from cqparts.display import display

    db = _Boards()
    db.add(Arduino())
    db.add(GlasgowRevC())
    db.add(Pizero())
    db.add(BeagleBoneBlack())
    db.add(PCBBoard(length=100, width=30))
    display(db)
Example #11
0
        mount = Mount(
            width=60,
            wall_thickness=1,
            toggle_width=toggle.width,
            toggle_height=toggle.height,
            extra_space=0.1,
            slot_width=2 * toggle.slot_width + toggle.pin_width,
            bracket_width=10,
            bracket_height=7,
            mount_hole_diameter=screw_diameter,
            probe_hole_distance=probe.radius +
            (toggle.height - toggle.slot_height),
            hide_front=True,
        )
        return {"toggle": toggle, "mount": mount, "probe": probe}

    def make_constraints(self):
        toggle = self.components["toggle"]
        mount = self.components["mount"]
        probe = self.components["probe"]
        return [
            cp.constraint.Fixed(mate=mount.mate_origin,
                                world_coords=CoordSystem()),
            cp.constraint.Coincident(toggle.mate, probe.toggle_mate),
            cp.constraint.Coincident(probe.screw_hole, mount.screw_hole)
        ]


assembly = Assembly()
display(assembly)
Example #12
0
            "top":
            PencilCaseTop(
                length=self.length,
                width=self.width,
                height=self.height,
                thickness=self.thickness,
            ),
            "bottom":
            OpenBox(
                length=self.length - 2 * self.thickness - self.clearance,
                width=self.width - 2 * self.thickness - self.clearance,
                height=self.height - self.thickness - self.clearance,
                thickness=self.thickness,
            ),
        }
        return comps

    def make_constraints(self):
        constr = [
            Fixed(self.components["bottom"].mate_origin),
            Fixed(self.components["top"].mate_top()),
        ]
        return constr


if __name__ == "__main__":
    from cqparts.display import display

    FB = PencilCase()
    display(FB)
Example #13
0
    def get_cutout(self, clearance=0):
        " clearance cut out for shaft "
        return (
            cq.Workplane("XY", origin=(0, 0, 0))
            .circle((self.diam / 2) + clearance)
            .extrude(self.length * 2)
        )

    def make_cutout(self, part, clearance=0):
        part = part.local_obj.cut(
            (self.world_coords - part.world_coords) + self.cutout(clearance=clearance)
        )

    def cutout(self, clearance=0):
        so = cq.Workplane("XY").circle(clearance + self.diam / 2).extrude(self.length)
        return so

    def mate_tip(self, offset=0):
        return Mate(
            self,
            CoordSystem(origin=(0, 0, self.length), xDir=(1, 0, 0), normal=(0, 0, 1)),
        )


if __name__ == "__main__":
    from cqparts.display import display

    a = Shaft()
    display(a)
Example #14
0
        }
        return comps

    def make_constraints(self):
        return [
            Fixed(self.components["cowl"].mate_origin),
            Coincident(
                self.components["motor"].mate_origin,
                self.components["cowl"].mate_mount(),
            ),
            Coincident(
                self.components["turbine"].mate_origin,
                self.components["cowl"].mate_mount(),
            ),
            Coincident(
                self.components["spinner"].mate_origin,
                self.components["turbine"].mate_top(),
            ),
        ]


if __name__ == "__main__":
    from cqparts.display import display

    # display(Spinner())
    # display(Cowl())
    # display(Turbine())
    # display(Blade())
    # display(AeroMotor())
    display(TurbineAssembly())
Example #15
0
    countZ = Int(1)
    batt = PartRef(Li18650)

    def make_components(self):
        return {
            "m":
            Battpack(
                batt=self.batt,
                countX=self.countX,
                countY=self.countY,
                countZ=self.countZ,
            )
        }

    def make_constraints(self):
        return [Fixed(self.components["m"].mate_flat())]


if __name__ == "__main__":
    from cqparts.display import display

    # bv = _BattView()
    # bv.add(AAA())
    # bv.add(AA())
    # bv.add(C())
    # bv.add(D())
    # bv = Battpack(batt=Li18650,countX=5,countY=3,countZ=2)
    # bv = Battpack(batt=Li18650,countX=5,countY=1,countZ=1)
    bv = _FlatBatt()
    display(bv)
Example #16
0
    def make_components(self):
        return {
            'front_rod': ThreadedRod(),
            'rear_rod': ThreadedRod(),
        }

    # def make_constraints(self):
    #     return [
    #         Fixed(self.components['front_rod'].mate_origin, CoordSystem()),
    #         Coincident(
    #             self.components['rear_rod'].mate_origin,
    #             Mate(self.components['front_rod'],
    #                  CoordSystem((self.rod_offset, 0, 0))),
    #         ),
    #     ]


# ------------------- Display Result -------------------
# Could also export to another format
if __name__ != 'TestEngineWholeModel':
    # not run as a module, so display result
    # m = Train()
    #m = Chassis()
    # m = WheeledAxle()
    # m = Axle()
    # m = Wheel()
    # m = Motor()
    #m = ThreadedRod()
    m = TopAssembly()
    display(m)
Example #17
0
        return h.objects

    def make(self):
        # base plate
        pl = cq.Workplane("XY").box(self.length, self.width, self.height)
        pl = pl.translate((0, 0, self.height / 2))
        # add the bosses
        mp = self.mount_points()
        for i in mp:
            b = _boss(boss_height=self.boss_height,
                      boss_diameter=self.boss_diameter)
            b = b.local_obj.translate((i.X, i.Y, self.height))
            pl = pl.union(b)
        # cur the holes
        for i in mp:
            h = (cq.Workplane("XY").circle(self.hole_diameter /
                                           2).extrude(self.height +
                                                      self.boss_height))
            h = h.translate((i.X, i.Y, 0))
            pl = pl.cut(h)
        pl = pl.faces(">Z[1]").edges("not(<X or >X or <Y or >Y)").fillet(1)
        pl = pl.edges("|Z").fillet(3)
        return pl


if __name__ == "__main__":
    from cqparts.display import display

    bb = BeardBoss(height=6, boss_height=20, boss_diameter=10, hole_diameter=5)
    display(bb)
Example #18
0
    radius = PositiveFloat(8)

    def make(self):
        em = cq.Workplane("XY").circle(self.radius).extrude(self.height)
        return em


@register(export="sensor")
class Sonar(PCBBoard):
    length = PositiveFloat(45)
    width = PositiveFloat(20)
    corner_radius = PositiveFloat(0)
    thickness = PositiveFloat(1.2)
    hole_size = PositiveFloat(1.0)

    def make(self):
        obj = super(Sonar, self).make()
        em1 = Emmitter().local_obj.translate((13.5, 0, 0))
        em2 = Emmitter().local_obj.translate((-13.5, 0, 0))
        obj = obj.union(em1)
        obj = obj.union(em2)
        return obj


if __name__ == "__main__":
    from cqparts.display import display

    # em  = Emmitter()
    em = Sonar()
    display(em)
Example #19
0
connected_exact = ConnectedPlanks()
connected_catalogue = ConnectedPlanksCatalogue()

if env_name == 'cmdline':
    screw.exporter('gltf')('screw.gltf')
    anchor.exporter('gltf')('anchor.gltf')
    panel.exporter('gltf')('panel.gltf')

    connected_exact.exporter('gltf')('connected_exact.gltf')
    print(connected_exact.tree_str(name='connected'))
    connected_catalogue.exporter('gltf')('connected_catalogue.gltf')

    #display(connected_exact)

elif env_name == 'freecad':
    pass  # manually switchable for testing
    #display(screw)
    #display(screw.make_cutter())
    #display(anchor)
    #display(together)

    display(connected_exact)

# ------------------- Catalogue : Cleanup -------------------

# Cleanup catalogue file (just for this script)
import os
os.unlink(catalogue_filename)
#print('catalogue: %s' % catalogue_filename)
Example #20
0
from cqparts.display import render_props, display


class Box(cqparts.Part):
    _render = render_props(template='red', alpha=0.2)

    def make(self):
        return cadquery.Workplane('XY').box(10, 10, 10)


red_box = Box()

# ------------------- Export -------------------
from cqparts.display import get_display_environment
env_name = get_display_environment().name

if env_name == 'freecad':
    pass
    #display(box)
    #display(wheel)
    #display(my_wheel)
    #display(joined_wheel)
    display(red_box)

else:
    box.exporter('gltf')('box.gltf', embed=True)
    wheel.exporter('gltf')('wheel.gltf', embed=True)
    my_wheel.exporter('gltf')('holy-wheel.gltf', embed=True)
    joined_wheel.exporter('gltf')('joined-wheel.gltf', embed=True)
    red_box.exporter('gltf')('red-box.gltf', embed=True)
Example #21
0
    def make_alterations(self):
        self.apply_cutout()

    def boss_cutout(self, clearance=0):
        bc = cq.Workplane("XY").circle(self.boss_size / 2).extrude(
            self.shaft_length)
        return bc

    def cutout(self, part):
        self.cut_boss(part)

    def cut_boss(self, part, clearance=0):
        co = self.boss_cutout(clearance=clearance)
        lo = part.local_obj.cut((self.world_coords - part.world_coords) + co)

    def mate_tip(self):
        return Mate(
            self,
            CoordSystem(origin=(0, 0, self.shaft_length),
                        xDir=(1, 0, 0),
                        normal=(0, 0, 1)),
        )


if __name__ == "__main__":
    from cqparts.display import display

    st = Stepper()
    display(st)
Example #22
0
import cadquery as cq
import cqparts
from cqparts.params import *
from cqparts.constraint import Fixed, Coincident
from cqparts_misc.basic.primatives import Box
from cqparts.display import render_props

from .manufacture import Lasercut


class Plank(Box, Lasercut):
    length = PositiveFloat(90)
    width = PositiveFloat(90)
    thickness = PositiveFloat(3)
    _render = render_props(template="wood")
    fillet = PositiveFloat(3)

    def make(self):
        pl = cq.Workplane("XY").box(self.length, self.width, self.thickness)
        pl = pl.translate((0, 0, self.thickness / 2))
        if self.fillet > 0:
            pl = pl.edges("|Z").fillet(self.fillet)
        return pl


if __name__ == "__main__":
    from cqparts.display import display

    display(Plank())
Example #23
0
            cls = cqparts_fasteners.solidtypes.fastener_heads.find(name=name)
            components[name] = cls(_render={'alpha': 0.5})
        return components

    def make_constraints(self):
        constraints = []
        index_width = int(math.sqrt(len(self.names)))
        for (i, name) in enumerate(self.names):
            (row, col) = ((i % index_width), int(i / index_width))

            constraints.append(Fixed(
                self.components[name].mate_origin,
                CoordSystem(origin=(
                    row * (self.box_size + self.gap),
                    -col * (self.box_size + self.gap),
                    0
                )),
            ))

        return constraints


names = names_list
if args.name:
    # single
    names = [args.name]

showcase = Showcase(names=names)

display(showcase)
Example #24
0
class FourArm(_MultiArm):
    arms = Int(4)


@register(export="horns")
class ServoArm(_MultiArm):
    arms = Int(6)


@register(export="horns")
class Circle(_ServoHorn):
    length = PositiveFloat(20)
    holes = Int(10)

    def make(self):
        c = self.circle()
        c = c.union(self.hub())
        c = c.cut(self.mount())
        return c


if __name__ == "__main__":
    from cqparts.display import display

    sh = ShowHorns(offset=40)
    sh.add(SingleArm())
    for i in range(2, 7):
        sh.add(_MultiArm(arms=i))
    sh.add(Circle())
    display(sh)
Example #25
0
                    base2.mate_nut_top(i),
                ),
                Coincident(
                    bolt_b.mate_head_end(rotation=(180, 0, 0)),
                    base3.mate_nut_bottom(i),
                ),
            ]
        return constraints

    def make_alterations(self):
        # Cutout the inserted nuts
        base = self.components["base"]
        base2 = self.components["base2"]
        base3 = self.components["base3"]
        for i, size in enumerate(self.tests):
            self.components[self.insert_bolt_name(size)].apply_cutout(base)
            self.components[self.nut_on_top_name(size)].apply_cutout(base2)
            self.components[self.bolt_on_bottom_name(size)].apply_cutout(base3)


# ------------------- Display Result -------------------
# Could also export to another format
if __name__ == "__cq_freecad_module__":
    # r = Nut()
    # r = Head()
    # r = Bolt()
    # r = Bolt(size = 'M3', embedded_length=3)
    # r = Bolt(size = 'M3', embedded_length=3, show_cutout=True)
    r = NutDisplay()
    display(r)
Example #26
0
        rails = self.components["rails"]
        for i, j in enumerate(rails.rail_pos()):
            item = rails.components[rails.rail_name(i)]
            item.make_cutout(part=de.components["block"])
            item.make_cutout(part=ie.components["block"])


@register(export="cnc")
class BeltAxis(Axis):
    drive = PartRef(BeltDrive)


@register(export="cnc")
class ThreadAxis(Axis):
    drive = PartRef(ThreadedDrive)


class CNC_show(Arrange):
    offset = PositiveFloat(100)


if __name__ == "__main__":
    from cqparts.display import display

    ar = CNC_show()
    # ar.add(Axis(width=90, length=200, pos=100))
    # ar.add(Axis(drive=BeltDrive, width=60, length=250, pos=50))
    ar.add(Axis(drive=ThreadedDrive, length=200, width=100, pos=70))
    # e = Axis()
    display(ar)
Example #27
0
# base shaft type
@register(export="misc")
class Shell(cqparts.Part):
    length = PositiveFloat(124, doc="shaft length")
    diam = PositiveFloat(40, doc="shaft diameter")
    count = Int(5)

    def make(self):
        shft = cq.Workplane("XY").circle(self.diam / 2).extrude(self.length)
        inc = 360.0 / float(self.count)
        for i in range(self.count):
            b = cq.Workplane("XY").circle(self.diam / 4).extrude(self.length /
                                                                 2)
            b = b.translate((self.diam / 2, 0, self.length / 8))
            b = b.rotate((0, 0, 0), (0, 0, 1), float(i * inc))
            shft = shft.union(b)
            c = cq.Workplane("XY").circle(self.diam / 8).extrude(self.length -
                                                                 6)
            c = c.translate((self.diam / 2, 0, 0))
            c = c.rotate((0, 0, 0), (0, 0, 1), float(i * inc))
            shft = shft.union(c)
        shft = shft.faces(">Z").shell(-1)
        return shft


if __name__ == "__main__":
    from cqparts.display import display

    s = Shell()
    display(s)
Example #28
0
        # cut all the mount points out of the target
        if self.target is not None:
            pass
        pass


class OtherBatt(Battpack):
    countX = Int(5)
    countY = Int(2)
    countZ = Int(1)
    batt = PartRef(battery.AA)


class OtherController(MountedBoard):
    board = PartRef(BeagleBoneBlack)


@register(export="electronics")
class type1(Electronics):
    battpack = PartRef(OtherBatt)
    controller = PartRef(OtherController)
    motorcontroller = PartRef(MotorController)
    target = PartRef()  # what the electronics are bound to


if __name__ == "__main__":
    from cqparts.display import display

    e = Electronics()
    display(e)
Example #29
0
            Coincident(
                self.components['branch_r'].mate_origin,
                self.components['trunk_split'].mate_right,
            ),
        ]


#house = Splitter()
#display(house)

#block_tree.world_coords = CoordSystem()

# ------------------- Export / Display -------------------
from cqparts.utils.env import get_env_name

env_name = get_env_name()

# ------- Models
block_tree = BlockTree(trunk_diam=7)

#import ipdb
#ipdb.set_trace()

if env_name == 'cmdline':
    block_tree.exporter('gltf')('exports/block-tree.gltf', embed=True)
    print(block_tree.tree_str(name="block_tree"))

elif env_name == 'freecad':
    pass  # manually switchable for testing
    display(block_tree)
Example #30
0
            _PegSide(**params),
            "spring":
            _Spring(
                diam=self.spring_diam,
                arm_length=self.spring_arm_length,
                wire_diam=self.spring_wire_diam,
                width=self.width,
            ),
        }

    def make_constraints(self):
        bottom = self.components["bottom"]
        top = self.components["top"]
        spring = self.components["spring"]
        return [
            constraint.Fixed(bottom.mate_side),
            constraint.Coincident(
                top.mate_spring_center,
                bottom.mate_spring_center + CoordSystem(normal=(0, 0, -1)),
            ),
            constraint.Coincident(spring.mate_origin,
                                  bottom.mate_spring_center),
        ]


if __name__ == "__main__":
    from cqparts.display import display

    cp = ClothesPeg()
    display(cp)