Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optionally supply dict for use and include functions #13

Closed
wants to merge 1 commit into from

Conversation

ipsod
Copy link

@ipsod ipsod commented Mar 17, 2023

I've found this useful.

Here's an example of how I used it to import and use the polygears library:

class PolyGears:
    # TODO: add my centering

    scad = dict()
    use("/gk/shapes/PolyGear/PolyGear.scad", to_dict=scad)
    _PGDemo = scad['PGDemo']
    _spur_gear = scad['spur_gear']
    _bevel_gear = scad['bevel_gear']
    _bevel_pair = scad['bevel_pair']
    _constant = scad['constant']
    _zerol = scad['zerol']
    _spiral = scad['spiral']
    _herringbone = scad['herringbone']


    def spur_gear(
            self,
            # basic options
            n=16,  # number of teeth
            m=1.0,  # module
            h=1.0,  # thickness
            pressure_angle=20.0,
            helix_angle: list[float]|float=0.0,  # the sign gives the handiness, can be a list
            backlash=0.1,  # in module units
            # shortcuts
            w=None,  # overrides z when defined
            a0=None,  # overrides pressure angle when defined
            b0=None,  # overrides helix angle when defined
            tol=None,  # overrides backlash
            # advanced options
            chamfer=0.0,  # degrees, should be in [0:90[
            chamfer_shift=0.0,  # from the pitch radius in module units
            add=0,  # add to addendum
            ded=0,  # subtract to the dedendum
            x=0,  # profile shift
            type=1,  # -1: internal 1: external. In practice it flips the sing of the profile shift

            # finesse options
            # fn=5,  # tooth profile subdivisions
            # TODO: get FN, etc. working, and figure them out
            # mine
            center=shapes.CC,
            exz=0.0,
            extend_up=0.0,
            extend_down=0.0,
    ):
        extend_up = extend_up or exz / 2
        extend_down = extend_down or exz / 2
        h += extend_up + extend_down
        it = self._spur_gear(
            n, m, h, pressure_angle, helix_angle, backlash, w, a0, b0, tol, chamfer,
            chamfer_shift, add, ded, x, type
        )
        it = up(h/2)(it)
        return shapes.vcenter(thing_at_top=it, h=h, extend_down=extend_down, center=center)

    def bevel_gear(
            self,
            # basic options
            n=16,  # number of teeth
            m=1,  # module
            w=1,  # tooth width
            cone_angle=45,
            pressure_angle=20,
            helix_angle=0,  # the sign gives the handiness
            backlash=0.1,  # in module units
            # shortcuts
            h=None,  # gear thickness, overrides w when defined
            a0=None,  # overrides pressure angle when defined
            b0=None,  # overrides helix angle when defined
            tol=None,  # overrides backlash
            # advanced options
            add=0,  # add to addendum
            ded=0,  # subtract to the dedendum
            x=0,  # profile shift
            type=1,  # -1: internal 1: external. In practice it flips the sing of the profile shift
            # finesse options
            fn=5,  # tooth profile subdivisions
    ):
        return self._bevel_gear(
            n, m, w, cone_angle, pressure_angle, helix_angle, backlash, h, a0, b0, tol, add, ded, x, type, fn
        )

    def bevel_pair(
            self,
            # basic options
            n1=16,  # number of teeth
            n2=16,  # number of teeth
            m=1,  # module
            w=1,  # tooth width
            axis_angle=90,
            pressure_angle=0,
            helix_angle=0,  # the sign gives the handiness
            backlash=0.1,  # in module units
            only=0,  # build only gear 1 or 2 (0 for both)
            # shortcuts
            a0=None,  # overrides pressure angle when defined
            b0=None,  # overrides helix angle when defined
            tol=None,  # overrides backlash
            # advanced options
            add=0,  # add to addendum
            ded=0,  # subtract to the dedendum
            x=0,  # profile shift
            type=1,  # -1: internal 1: external. In practice it flips the sing of the profile shift
            # finesse options
            fn=5,  # tooth profile subdivisions
    ):
        return self._bevel_pair(
            n1, n2, m, w, axis_angle, pressure_angle, helix_angle, backlash, only, a0, b0, tol, add, ded, x, type, fn,
        )

    def wig_wag(self, h=10.0, lh=0.2, cycles=1.0):
        # print('H', h % lh, h / lh)
        assert h % lh < 0.001 or h % lh - lh < .001
        num_steps = ceil(h / lh)
        steps = [180*cycles*(step/num_steps) for step in range(num_steps)]
        # steps = range(0, int(180*cycles), ceil(h / lh))
        return [30 * math.sin(math.radians(s)) for s in steps]

    def demo(self, i=0):
        if i == 0:
            # hlx = [20, 10, 0, -10, -20]
            h = 10
            LH = 0.2
            hlx = [40 * math.sin(math.radians(x)) for x in range(0, 180, ceil(h / LH))]
            return self.spur_gear(w=10, helix_angle=hlx, n=44,)  # chamfer=30, chamfer_shift=-1, )
        if i == 1:
            return self.bevel_gear(w=5, cone_angle=45, helix_angle=self.zerol(60))


def assembly():
    return Display().draw()

    make = part()

    for i in range(10):
        make += left(i*20)(
            cube([20, 20, 20], center=True)
            - cylinder(d=i, h=100, center=True)
        )

    return make

    return Gears().left(marble_color=None)
    return gear_hold_downs()
    return Gears().draw(marbles=True)
    return bolt_hole_test()
    return BaseCase().bottom()
    return JoinCarvedBlockToBigBlock().draw()
    return CarvedBlock().draw()
    return JoinBaseToBigBlock().draw()

@jeff-dh
Copy link
Owner

jeff-dh commented Mar 17, 2023

hmmmmm I don't have to time right now to have a closer look at it and really understand what you're trying to do, buuuuut..... ;)

Do you know about import_scad ?

    # MCAD is OpenSCAD's most common utility library: https://github.com/openscad/MCAD
    # If it's installed for OpenSCAD (on MacOS, at: ``$HOME/Documents/OpenSCAD/libraries``)
    mcad = import_scad('MCAD')

    # MCAD contains about 15 separate packages, each included as its own namespace
    print(dir(mcad)) # => ['bearing', 'bitmap', 'boxes', etc...]
    mount = mcad.motors.stepper_motor_mount(nema_standard=17)
    mount.save_as_scad('motor_mount_file.scad')

Isn't this maybe 90% of what you're trying to achieve?

@jeff-dh
Copy link
Owner

jeff-dh commented Mar 17, 2023

After having a look at your diff, I think it's a "reimplementation" of import_scad,right?

@ipsod
Copy link
Author

ipsod commented Mar 17, 2023

Yeah, it looks to be the same thing. Seeing it now, I'd rather modify import_scad.

@ipsod ipsod closed this Mar 17, 2023
@ipsod
Copy link
Author

ipsod commented Mar 17, 2023

Oh, no, maybe I don't need to change anything. I need to slow down and read code and study, and see what's already there.

Sorry, I'm in a blind rush. I'll try and slow down.

@ipsod ipsod deleted the patch-1 branch March 17, 2023 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants