Example #1
0
def sheets(machine, parts=None):
    #
    # Make the target directory
    #
    target_dir = machine + "/sheets"
    if os.path.isdir(target_dir):
        shutil.rmtree(target_dir)
        sleep(0.1)
        os.makedirs(target_dir)
    else:
        os.makedirs(target_dir)

    #
    # Set the target machine
    #
    set_machine(machine)

    #
    # Find all the scad files
    #
    for filename in os.listdir(source_dir):
        if filename[-5:] == ".scad":
            #
            # find any modules ending in _dxf
            #
            for line in open(source_dir + "/" + filename, "r").readlines():
                words = line.split()
                if len(words) and words[0] == "module":
                    module = words[1].split('(')[0]
                    if module[-4:] == "_dxf" and (not parts or
                                                  (module[:-4] + ".dxf")
                                                  in parts):
                        #
                        # make a file to use the module
                        #
                        dxf_maker_name = target_dir + "/" + module + ".scad"
                        f = open(dxf_maker_name, "w")
                        f.write("use <../../%s/%s>\n" % (source_dir, filename))
                        f.write("%s();\n" % module)
                        f.close()
                        #
                        # Run openscad on the created file
                        #
                        base_name = target_dir + "/" + module[:-4]
                        dxf_name = base_name + ".dxf"
                        openscad.run("-o", dxf_name, dxf_maker_name)
                        #
                        # Make SVG drill template
                        #
                        dxf_to_svg(dxf_name)
                        #
                        # Make PDF for printing
                        #
                        InkCL.run("-f", base_name + ".svg", "-A",
                                  base_name + ".pdf")
                        os.remove(dxf_maker_name)
Example #2
0
def views(machine):
    scad_dir = "views"
    render_dir = machine + os.sep + "views"

    if not os.path.isdir(render_dir):
        os.makedirs(render_dir)
    #
    # Set the target machine
    #
    set_machine(machine)

    #
    # List of individual part files
    #
    scads = [i for i in os.listdir(scad_dir) if i[-5:] == ".scad"]

    for scad in scads:
        scad_name = scad_dir + os.sep + scad
        png_name = render_dir + os.sep + scad[:-4] + "png"

        for line in open(scad_name, "r").readlines():
            words = line.split()
            if len(words) > 10 and words[0] == "//":
                cmd = words[1]
                if cmd == "view" or cmd == "assembled" or cmd == "assembly":
                    w = int(words[2]) * 2
                    h = int(words[3]) * 2

                    dx = float(words[4])
                    dy = float(words[5])
                    dz = float(words[6])

                    rx = float(words[7])
                    ry = float(words[8])
                    rz = float(words[9])

                    d = float(words[10])
                    camera = "%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f" % (
                        dx, dy, dz, rx, ry, rz, d)

                    exploded = "0"
                    if cmd == "assembly":
                        exploded = "1"

                    if cmd == "assembled":
                        png_name = png_name.replace("assembly", "assembled")

                    if not os.path.isfile(png_name) or os.path.getmtime(
                            png_name) < os.path.getmtime(scad_name):
                        openscad.run("--projection=p",
                                     ("--imgsize=%d,%d" % (w, h)),
                                     "--camera=" + camera,
                                     "-D$exploded=" + exploded, "-o", png_name,
                                     scad_name)
                        print
Example #3
0
def sheets(machine, parts = None):
    #
    # Make the target directory
    #
    target_dir = machine + "/sheets"
    if os.path.isdir(target_dir):
        shutil.rmtree(target_dir)
        sleep(0.1)
        os.makedirs(target_dir)
    else:
        os.makedirs(target_dir)

    #
    # Set the target machine
    #
    set_machine(machine)

    #
    # Find all the scad files
    #
    for filename in os.listdir(source_dir):
        if filename[-5:] == ".scad":
            #
            # find any modules ending in _dxf
            #
            for line in open(source_dir + "/" + filename, "r").readlines():
                words = line.split()
                if len(words) and words[0] == "module":
                    module = words[1].split('(')[0]
                    if module[-4:] == "_dxf" and (not parts or (module[:-4] + ".dxf") in parts):
                        #
                        # make a file to use the module
                        #
                        dxf_maker_name = target_dir + "/" + module + ".scad"
                        f = open(dxf_maker_name, "w")
                        f.write("use <../../%s/%s>\n" % (source_dir, filename))
                        f.write("%s();\n" % module);
                        f.close()
                        #
                        # Run openscad on the created file
                        #
                        base_name = target_dir + "/" + module[:-4]
                        dxf_name = base_name + ".dxf"
                        openscad.run("-o", dxf_name, dxf_maker_name)
                        #
                        # Make SVG drill template
                        #
                        dxf_to_svg(dxf_name)
                        #
                        # Make PDF for printing
                        #
                        InkCL.run("-f", base_name + ".svg", "-A", base_name + ".pdf")
                        os.remove(dxf_maker_name)
Example #4
0
def views(machine):
    scad_dir = "views"
    render_dir = machine + os.sep + "views"

    if not os.path.isdir(render_dir):
        os.makedirs(render_dir)
    #
    # Set the target machine
    #
    set_machine(machine)

    #
    # List of individual part files
    #
    scads = [i for i in os.listdir(scad_dir) if i[-5:] == ".scad"]

    for scad in scads:
        scad_name = scad_dir + os.sep + scad
        png_name = render_dir + os.sep + scad[:-4] + "png"

        for line in open(scad_name, "r").readlines():
            words = line.split()
            if len(words) > 10 and words[0] == "//":
                cmd = words[1]
                if cmd == "view" or cmd == "assembled" or cmd == "assembly":
                    w = int(words[2]) * 2
                    h = int(words[3]) * 2

                    dx = float(words[4])
                    dy = float(words[5])
                    dz = float(words[6])

                    rx = float(words[7])
                    ry = float(words[8])
                    rz = float(words[9])

                    d = float(words[10])
                    camera = "%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f" % (dx, dy, dz, rx, ry, rz, d)

                    exploded = "0"
                    if cmd == "assembly":
                        exploded = "1"

                    if cmd == "assembled":
                        png_name = png_name.replace("assembly","assembled")

                    if not os.path.isfile(png_name) or os.path.getmtime(png_name) < os.path.getmtime(scad_name):
                        openscad.run("--projection=p",
                                    ("--imgsize=%d,%d" % (w, h)),
                                     "--camera=" + camera,
                                      "-D$exploded=" + exploded,
                                      "-o", png_name, scad_name)
                        print
Example #5
0
def views(machine):
    scad_dir = "views"
    render_dir = machine + os.sep + "views"

    if not os.path.isdir(render_dir):
        os.makedirs(render_dir)
    #
    # Set the target machine
    #
    set_machine(machine)

    #
    # List of individual part files
    #
    scads = [i for i in os.listdir(scad_dir) if i[-5:] == ".scad"]

    for scad in scads:
        scad_name = scad_dir + os.sep + scad
        png_name = render_dir + os.sep + scad[:-4] + "png"

        dx = None
        rx = None
        d = None
        for line in open(scad_name, "r").readlines():
            m = re.match(r'\$vpt *= *\[ *(.*) *, *(.*) *, *(.*) *\].*', line[:-1])
            if m:
                dx = float(m.group(1))
                dy = float(m.group(2))
                dz = float(m.group(3))
            m = re.match(r'\$vpr *= *\[ *(.*) *, *(.*) *, *(.*) *\].*', line[:-1])
            if m:
                rx = float(m.group(1))
                ry = float(m.group(2))
                rz = float(m.group(3))
            m = re.match(r'\$vpd *= * *(.*) *;.*', line[:-1])
            if m:
                d = float(m.group(1))
            words = line.split()
            if len(words) > 3 and words[0] == "//":
                cmd = words[1]
                if cmd == "view" or cmd == "assembled" or cmd == "assembly":
                    w = int(words[2]) * 2
                    h = int(words[3]) * 2

                    if len(words) > 10:
                        dx = float(words[4])
                        dy = float(words[5])
                        dz = float(words[6])

                        rx = float(words[7])
                        ry = float(words[8])
                        rz = float(words[9])

                        d = float(words[10])

                    if dx == None or rx == None or d == None:
                        print "Missing camera data in " + scad_name
                        sys.exit(1)

                    camera = "%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f" % (dx, dy, dz, rx, ry, rz, d)

                    exploded = "0"
                    if cmd == "assembly":
                        exploded = "1"

                    if cmd == "assembled":
                        png_name = png_name.replace("assembly","assembled")

                    if not os.path.isfile(png_name) or os.path.getmtime(png_name) < os.path.getmtime(scad_name):
                        openscad.run("--projection=p",
                                    ("--imgsize=%d,%d" % (w, h)),
                                     "--camera=" + camera,
                                      "-D$exploded=" + exploded,
                                      "-o", png_name, scad_name)
                        print
Example #6
0
def stls(machine, parts=None):
    #
    # Make the target directory
    #
    target_dir = machine + "/stls"
    if os.path.isdir(target_dir):
        if not parts:
            shutil.rmtree(
                target_dir)  #if making the BOM clear the directory first
            sleep(0.1)
            os.makedirs(target_dir)
    else:
        os.makedirs(target_dir)

    #
    # Set the target machine
    #
    set_machine(machine)

    #
    # Decide which files to make
    #
    if parts:
        targets = list(
            parts)  #copy the list so we dont modify the list passed in
    else:
        targets = bom_to_stls(machine)
    #
    # Find all the scad files
    #
    used = []
    for filename in os.listdir(source_dir):
        if filename[-5:] == ".scad":
            #
            # find any modules ending in _stl
            #
            for line in open(source_dir + "/" + filename, "r").readlines():
                words = line.split()
                if (len(words) and words[0] == "module"):
                    module = words[1].split('(')[0]
                    stl = module.replace("_stl", ".stl")
                    if stl in targets:
                        #
                        # make a file to use the module
                        #
                        stl_maker_name = source_dir + "/stl.scad"
                        f = open(stl_maker_name, "w")
                        f.write("use <%s>\n" % filename)
                        f.write("%s();\n" % module)
                        f.close()
                        #
                        # Run openscad on the created file
                        #
                        stl_name = target_dir + "/" + module[:-4] + ".stl"
                        openscad.run("-D$bom=1", "-o", stl_name,
                                     stl_maker_name)
                        c14n_stl.canonicalise(stl_name)
                        targets.remove(stl)
                        #
                        # Add the files on the BOM to the used list for plates.py
                        #
                        for line in open("openscad.log"):
                            if line[:7] == 'ECHO: "' and line[-6:] == '.stl"\n':
                                used.append(line[7:-2])
    #
    # List the ones we didn't find
    #
    for module in targets:
        print("Could not find", module)
    return used
Example #7
0
def stls(machine, parts = None):
    #
    # Make the target directory
    #
    target_dir = machine + "/stls"
    if os.path.isdir(target_dir):
        if not parts:
            shutil.rmtree(target_dir)   #if making the BOM clear the directory first
            sleep(0.1)
            os.makedirs(target_dir)
    else:
        os.makedirs(target_dir)

    #
    # Set the target machine
    #
    set_machine(machine)

    #
    # Decide which files to make
    #
    if parts:
        targets = list(parts)           #copy the list so we dont modify the list passed in
    else:
        targets = bom_to_stls(machine)
    #
    # Find all the scad files
    #
    used = []
    for filename in os.listdir(source_dir):
        if filename[-5:] == ".scad":
            #
            # find any modules ending in _stl
            #
            for line in open(source_dir + "/" + filename, "r").readlines():
                words = line.split()
                if(len(words) and words[0] == "module"):
                    module = words[1].split('(')[0]
                    stl = module.replace("_stl", ".stl")
                    if stl in targets:
                        #
                        # make a file to use the module
                        #
                        stl_maker_name = source_dir + "/stl.scad"
                        f = open(stl_maker_name, "w")
                        f.write("use <%s>\n" % filename)
                        f.write("%s();\n" % module);
                        f.close()
                        #
                        # Run openscad on the created file
                        #
                        stl_name = target_dir + "/" + module[:-4] + ".stl"
                        openscad.run("-D$bom=1","-o", stl_name, stl_maker_name)
                        c14n_stl.canonicalise(stl_name)
                        targets.remove(stl)
                        #
                        # Add the files on the BOM to the used list for plates.py
                        #
                        for line in open("openscad.log"):
                            if line[:7] == 'ECHO: "' and line[-6:] == '.stl"\n':
                                used.append(line[7:-2])
    #
    # List the ones we didn't find
    #
    for module in targets:
        print("Could not find", module)
    return used