mirror of
https://github.com/nophead/NopSCADlib.git
synced 2025-08-13 19:03:58 +02:00
Merge branch 'master' into Execute_attributes
This commit is contained in:
@@ -37,9 +37,10 @@ def read_deps(dname):
|
||||
deps.append(dep)
|
||||
return deps
|
||||
|
||||
def check_deps(target_mtime, dname):
|
||||
def check_deps(target, dname):
|
||||
target_mtime = mtime(target)
|
||||
if not target_mtime:
|
||||
return "target missing"
|
||||
return target + " missing"
|
||||
if not os.path.isfile(dname):
|
||||
return "no deps"
|
||||
deps = read_deps(dname)
|
||||
|
@@ -84,7 +84,6 @@ def make_parts(target, part_type, parts = None):
|
||||
# Find all the scad files
|
||||
#
|
||||
lib_dir = os.environ['OPENSCADPATH'] + '/NopSCADlib/printed'
|
||||
used = []
|
||||
module_suffix = '_dxf' if part_type == 'svg' else '_' + part_type
|
||||
for dir in [source_dir, lib_dir]:
|
||||
for filename in os.listdir(dir):
|
||||
@@ -113,7 +112,7 @@ def make_parts(target, part_type, parts = None):
|
||||
#
|
||||
part_file = target_dir + "/" + part
|
||||
dname = deps_name(deps_dir, filename)
|
||||
changed = check_deps(mtime(part_file), dname)
|
||||
changed = check_deps(part_file, dname)
|
||||
changed = times.check_have_time(changed, part)
|
||||
if part_type == 'stl' and not changed and not part in bounds_map:
|
||||
changed = "No bounds"
|
||||
@@ -125,14 +124,9 @@ def make_parts(target, part_type, parts = None):
|
||||
if part_type == 'stl':
|
||||
bounds = c14n_stl.canonicalise(part_file)
|
||||
bounds_map[part] = bounds
|
||||
|
||||
targets.remove(part)
|
||||
os.remove(part_maker_name)
|
||||
#
|
||||
# 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:] == '.' + part_type + '"\n':
|
||||
used.append(line[7:-2])
|
||||
#
|
||||
# Write new bounds file
|
||||
#
|
||||
@@ -150,4 +144,3 @@ def make_parts(target, part_type, parts = None):
|
||||
print("Could not find a module called", part[:-4] + module_suffix, "to make", part)
|
||||
sys.exit(1)
|
||||
times.print_times()
|
||||
return used
|
||||
|
@@ -26,6 +26,7 @@ from exports import make_parts
|
||||
from bom import boms
|
||||
from render import render
|
||||
from views import views
|
||||
from plateup import plateup
|
||||
|
||||
if __name__ == '__main__':
|
||||
target = None if len(sys.argv) == 1 else sys.argv[1]
|
||||
@@ -33,4 +34,6 @@ if __name__ == '__main__':
|
||||
for part in ['stl', 'dxf']:
|
||||
make_parts(target, part)
|
||||
render(target, part)
|
||||
plateup(target, part)
|
||||
|
||||
views(target)
|
||||
|
@@ -24,11 +24,12 @@ from __future__ import print_function
|
||||
|
||||
import subprocess, sys
|
||||
|
||||
def run(*args):
|
||||
def run(*args, silent = False):
|
||||
cmd = ["openscad"] + list(args)
|
||||
for arg in cmd:
|
||||
print(arg, end=" ")
|
||||
print()
|
||||
if not silent:
|
||||
for arg in cmd:
|
||||
print(arg, end=" ")
|
||||
print()
|
||||
with open("openscad.log", "w") as log:
|
||||
rc = subprocess.call(cmd, stdout = log, stderr = log)
|
||||
for line in open("openscad.log", "rt"):
|
||||
|
33
scripts/panels.py
Normal file
33
scripts/panels.py
Normal file
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
#
|
||||
# NopSCADlib Copyright Chris Palmer 2018
|
||||
# nop.head@gmail.com
|
||||
# hydraraptor.blogspot.com
|
||||
#
|
||||
# This file is part of NopSCADlib.
|
||||
#
|
||||
# NopSCADlib is free software: you can redistribute it and/or modify it under the terms of the
|
||||
# GNU General Public License as published by the Free Software Foundation, either version 3 of
|
||||
# the License, or (at your option) any later version.
|
||||
#
|
||||
# NopSCADlib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with NopSCADlib.
|
||||
# If not, see <https://www.gnu.org/licenses/>.
|
||||
#
|
||||
#! Panelises DXF files so they can be routed together by running scad files found in the ```panels``` directory.
|
||||
|
||||
from __future__ import print_function
|
||||
import sys
|
||||
|
||||
from plateup import plateup
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) > 1:
|
||||
target = sys.argv[1]
|
||||
else:
|
||||
target = None
|
||||
plateup(target, 'dxf')
|
98
scripts/plateup.py
Normal file
98
scripts/plateup.py
Normal file
@@ -0,0 +1,98 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
#
|
||||
# NopSCADlib Copyright Chris Palmer 2018
|
||||
# nop.head@gmail.com
|
||||
# hydraraptor.blogspot.com
|
||||
#
|
||||
# This file is part of NopSCADlib.
|
||||
#
|
||||
# NopSCADlib is free software: you can redistribute it and/or modify it under the terms of the
|
||||
# GNU General Public License as published by the Free Software Foundation, either version 3 of
|
||||
# the License, or (at your option) any later version.
|
||||
#
|
||||
# NopSCADlib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with NopSCADlib.
|
||||
# If not, see <https://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
from __future__ import print_function
|
||||
import os
|
||||
import openscad
|
||||
import sys
|
||||
import c14n_stl
|
||||
from set_config import *
|
||||
from deps import *
|
||||
from shutil import copyfile
|
||||
|
||||
source_dirs = { "stl" : "platters", "dxf" : "panels" }
|
||||
target_dirs = { "stl" : "printed", "dxf" : "routed" }
|
||||
|
||||
def plateup(target, part_type):
|
||||
#
|
||||
# Make the target directory
|
||||
#
|
||||
top_dir = set_config(target)
|
||||
parts_dir = top_dir + part_type + 's'
|
||||
target_dir = parts_dir + '/' + target_dirs[part_type]
|
||||
source_dir = top_dir + source_dirs[part_type]
|
||||
deps_dir = source_dir + "/deps"
|
||||
if not os.path.isdir(source_dir):
|
||||
return
|
||||
if not os.path.isdir(target_dir):
|
||||
os.makedirs(target_dir)
|
||||
if not os.path.isdir(deps_dir):
|
||||
os.makedirs(deps_dir)
|
||||
#
|
||||
# Decide which files to make
|
||||
#
|
||||
sources = [file for file in os.listdir(source_dir) if file.endswith('.scad')]
|
||||
#
|
||||
# Run OpenSCAD on the source files to make the targets
|
||||
#
|
||||
used = []
|
||||
for src in sources:
|
||||
src_file = source_dir + '/' + src
|
||||
part_file = target_dir + '/' + src[:-4] + part_type
|
||||
dname = deps_name(deps_dir, src)
|
||||
changed = check_deps(part_file, dname)
|
||||
if changed:
|
||||
print(changed)
|
||||
openscad.run("-D$bom=1", "-d", dname, "-o", part_file, src_file)
|
||||
if part_type == 'stl':
|
||||
c14n_stl.canonicalise(part_file)
|
||||
log_name = 'openscad.log'
|
||||
else:
|
||||
log_name = 'openscad.echo'
|
||||
openscad.run("-D$bom=1", "-o", log_name, src_file, silent = True)
|
||||
#
|
||||
# Add the files on the BOM to the used list
|
||||
#
|
||||
with open(log_name) as file:
|
||||
for line in file.readlines():
|
||||
if line.startswith('ECHO: "~') and line.endswith('.' + part_type + '"\n'):
|
||||
used.append(line[8:-2])
|
||||
#
|
||||
# Copy file that are not included
|
||||
#
|
||||
copied = []
|
||||
for file in os.listdir(parts_dir):
|
||||
if file.endswith('.' + part_type) and not file in used:
|
||||
src = parts_dir + '/' + file
|
||||
dst = target_dir + '/' + file
|
||||
if mtime(src) > mtime(dst):
|
||||
print("Copying %s to %s" % (src, dst))
|
||||
copyfile(src, dst)
|
||||
copied.append(file)
|
||||
#
|
||||
# Remove any cruft
|
||||
#
|
||||
targets = [file[:-4] + part_type for file in sources]
|
||||
for file in os.listdir(target_dir):
|
||||
if file.endswith('.' + part_type):
|
||||
if not file in targets and not file in copied:
|
||||
print("Removing %s" % file)
|
||||
os.remove(target_dir + '/' + file)
|
33
scripts/platters.py
Normal file
33
scripts/platters.py
Normal file
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
#
|
||||
# NopSCADlib Copyright Chris Palmer 2018
|
||||
# nop.head@gmail.com
|
||||
# hydraraptor.blogspot.com
|
||||
#
|
||||
# This file is part of NopSCADlib.
|
||||
#
|
||||
# NopSCADlib is free software: you can redistribute it and/or modify it under the terms of the
|
||||
# GNU General Public License as published by the Free Software Foundation, either version 3 of
|
||||
# the License, or (at your option) any later version.
|
||||
#
|
||||
# NopSCADlib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with NopSCADlib.
|
||||
# If not, see <https://www.gnu.org/licenses/>.
|
||||
#
|
||||
#! Generates build plates of STL files for efficient printing by running scad files found in the ```platters``` directory.
|
||||
|
||||
from __future__ import print_function
|
||||
import sys
|
||||
|
||||
from plateup import plateup
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) > 1:
|
||||
target = sys.argv[1]
|
||||
else:
|
||||
target = None
|
||||
plateup(target, 'stl')
|
@@ -12,6 +12,8 @@ They should work with both Python 2 and Python 3.
|
||||
| ```dxfs.py``` | Generates DXF files for all the routed parts listed on the BOM or a specified list. |
|
||||
| ```gallery.py``` | Finds projects and adds them to the gallery. |
|
||||
| ```make_all.py``` | Generates all the files for a project by running ```bom.py```, ```stls.py```, ```dxfs.py```, ```render.py``` and ```views.py```. |
|
||||
| ```panels.py``` | Panelises DXF files so they can be routed together by running scad files found in the ```panels``` directory. |
|
||||
| ```platters.py``` | Generates build plates of STL files for efficient printing by running scad files found in the ```platters``` directory. |
|
||||
| ```render.py``` | Renders STL and DXF files to PNG for inclusion in the build instructions. |
|
||||
| ```set_config.py``` | Sets the target configuration for multi-target projects that have variable configurations. |
|
||||
| ```stls.py``` | Generates STL files for all the printed parts listed on the BOM or a specified list. |
|
||||
|
@@ -107,7 +107,7 @@ def tests(tests):
|
||||
#
|
||||
# List of individual part files
|
||||
#
|
||||
scads = [i for i in os.listdir(scad_dir) if i[-5:] == ".scad"]
|
||||
scads = [i for i in sorted(os.listdir(scad_dir)) if i[-5:] == ".scad"]
|
||||
|
||||
for scad in scads:
|
||||
base_name = scad[:-5]
|
||||
@@ -187,7 +187,7 @@ def tests(tests):
|
||||
body += ["\n" %(base_name, png_name)]
|
||||
|
||||
dname = deps_name(deps_dir, scad)
|
||||
oldest = min(mtime(png_name), mtime(bom_name))
|
||||
oldest = png_name if mtime(png_name) < mtime(bom_name) else bom_name
|
||||
changed = check_deps(oldest, dname)
|
||||
changed = times.check_have_time(changed, scad_name)
|
||||
if changed:
|
||||
@@ -257,7 +257,7 @@ See [usage](docs/usage.md) for requirements, installation instructions and a usa
|
||||
print('<tr>', file = doc_file, end = '')
|
||||
for type in types:
|
||||
if i < len(index[type]):
|
||||
name = index[type][i]
|
||||
name = sorted(index[type])[i]
|
||||
print('<td> <a href = "#' + name + '">' + name + '</a> </td>', file = doc_file, end = '')
|
||||
else:
|
||||
print('<td></td>', file = doc_file, end = '')
|
||||
|
@@ -154,14 +154,14 @@ def views(target, do_assemblies = None):
|
||||
f.write("use <%s/%s>\n" % (dir, filename))
|
||||
f.write("%s();\n" % module);
|
||||
#
|
||||
# Run openscad on the created file
|
||||
# Run openscad on th created file
|
||||
#
|
||||
dname = deps_name(deps_dir, filename)
|
||||
for explode in [0, 1]:
|
||||
png_name = target_dir + '/' + module + '.png'
|
||||
if not explode:
|
||||
png_name = png_name.replace('_assembly', '_assembled')
|
||||
changed = check_deps(mtime(png_name), dname)
|
||||
changed = check_deps(png_name, dname)
|
||||
changed = times.check_have_time(changed, png_name)
|
||||
tmp_name = 'tmp.png'
|
||||
if changed:
|
||||
|
Reference in New Issue
Block a user