Now uses the dependencies to locate modules for printed parts and assemblies.
This commit is contained in:
parent
2eef050f60
commit
2210396234
|
@ -243,3 +243,10 @@ Some parametric designs might have several configurations, for example a 3D prin
|
||||||
The target config file is selected by generating ```target.scad``` that includes ```config_<target_name>.scad```.
|
The target config file is selected by generating ```target.scad``` that includes ```config_<target_name>.scad```.
|
||||||
The rest of the project includes ```target.scad``` to use the configuration.
|
The rest of the project includes ```target.scad``` to use the configuration.
|
||||||
Additionally all the generated file directories (assemblies, bom, stls, dxfs, etc.) are placed in a sub-directory called ```<target_name>```.
|
Additionally all the generated file directories (assemblies, bom, stls, dxfs, etc.) are placed in a sub-directory called ```<target_name>```.
|
||||||
|
|
||||||
|
### Other libraries
|
||||||
|
|
||||||
|
The build scripts need to be able to locate the source files where the modules to generate the STL files and assemblies reside. They will search all the scad files
|
||||||
|
in the project plus any ```printed``` directories outside the project. This covers the printed parts in NopSCADlib but also allows other libraries of printed parts.
|
||||||
|
|
||||||
|
Other libraries of vitamins and utilities can be used provided they follow the same convensions of NopSCADlib. The build scripts don't need to search those.
|
||||||
|
|
|
@ -221,7 +221,7 @@ def boms(target = None, assembly = None):
|
||||||
#
|
#
|
||||||
# Run openscad
|
# Run openscad
|
||||||
#
|
#
|
||||||
openscad.run("-D","$bom=2","-D","$preview=true","-o", "openscad.echo", bom_maker_name)
|
openscad.run("-D","$bom=2","-D","$preview=true","-o", "openscad.echo", "-d", bom_dir + "/bom.deps", bom_maker_name)
|
||||||
os.remove(bom_maker_name)
|
os.remove(bom_maker_name)
|
||||||
print("Generating bom ...", end=" ")
|
print("Generating bom ...", end=" ")
|
||||||
|
|
||||||
|
|
|
@ -48,3 +48,17 @@ def check_deps(target, dname):
|
||||||
if mtime(dep) > target_mtime:
|
if mtime(dep) > target_mtime:
|
||||||
return dep + ' changed'
|
return dep + ' changed'
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def source_dirs(bom_dir):
|
||||||
|
dirs = set()
|
||||||
|
lib_dirs = set()
|
||||||
|
deps = read_deps(bom_dir + '/bom.deps')
|
||||||
|
cwd = os.getcwd().replace('\\', '/')
|
||||||
|
for dep in deps:
|
||||||
|
dir = os.path.dirname(dep)
|
||||||
|
if dir.startswith(cwd):
|
||||||
|
dirs.add(dir[len(cwd) + 1:])
|
||||||
|
else:
|
||||||
|
if dir.endswith('/printed'):
|
||||||
|
lib_dirs.add(dir)
|
||||||
|
return sorted(dirs) + sorted(lib_dirs)
|
||||||
|
|
|
@ -30,14 +30,14 @@ import times
|
||||||
from deps import *
|
from deps import *
|
||||||
import json
|
import json
|
||||||
|
|
||||||
def bom_to_parts(target_dir, part_type, assembly = None):
|
def bom_to_parts(bom_dir, part_type, assembly = None):
|
||||||
#
|
#
|
||||||
# Make a list of all the parts in the BOM
|
# Make a list of all the parts in the BOM
|
||||||
#
|
#
|
||||||
part_files = []
|
part_files = []
|
||||||
bom = assembly + '.txt' if assembly else "bom.txt"
|
bom = assembly + '.txt' if assembly else "bom.txt"
|
||||||
suffix = ".dxf" if part_type == 'svg' else '.' + part_type
|
suffix = ".dxf" if part_type == 'svg' else '.' + part_type
|
||||||
with open(target_dir + "/../bom/" + bom, "rt") as f:
|
with open(bom_dir + '/' + bom, "rt") as f:
|
||||||
for line in f.readlines():
|
for line in f.readlines():
|
||||||
words = line.split()
|
words = line.split()
|
||||||
if words:
|
if words:
|
||||||
|
@ -63,6 +63,7 @@ def make_parts(target, part_type, parts = None):
|
||||||
top_dir = set_config(target, lambda: usage(part_type))
|
top_dir = set_config(target, lambda: usage(part_type))
|
||||||
target_dir = top_dir + part_type + 's'
|
target_dir = top_dir + part_type + 's'
|
||||||
deps_dir = top_dir + "deps"
|
deps_dir = top_dir + "deps"
|
||||||
|
bom_dir = top_dir + "bom"
|
||||||
if not os.path.isdir(target_dir):
|
if not os.path.isdir(target_dir):
|
||||||
os.makedirs(target_dir)
|
os.makedirs(target_dir)
|
||||||
if not os.path.isdir(deps_dir):
|
if not os.path.isdir(deps_dir):
|
||||||
|
@ -74,7 +75,7 @@ def make_parts(target, part_type, parts = None):
|
||||||
if parts:
|
if parts:
|
||||||
targets = list(parts) #copy the list so we dont modify the list passed in
|
targets = list(parts) #copy the list so we dont modify the list passed in
|
||||||
else:
|
else:
|
||||||
targets = bom_to_parts(target_dir, part_type)
|
targets = bom_to_parts(bom_dir, part_type)
|
||||||
for file in os.listdir(target_dir):
|
for file in os.listdir(target_dir):
|
||||||
if file.endswith('.' + part_type):
|
if file.endswith('.' + part_type):
|
||||||
if not file in targets:
|
if not file in targets:
|
||||||
|
@ -93,12 +94,11 @@ def make_parts(target, part_type, parts = None):
|
||||||
#
|
#
|
||||||
# Find all the scad files
|
# Find all the scad files
|
||||||
#
|
#
|
||||||
lib_dirs = [path + '/' + lib + '/printed' for path in os.environ['OPENSCADPATH'].split(os.pathsep) for lib in sorted(os.listdir(path))]
|
|
||||||
module_suffix = '_dxf' if part_type == 'svg' else '_' + part_type
|
module_suffix = '_dxf' if part_type == 'svg' else '_' + part_type
|
||||||
for dir in [source_dir, source_dir + '/printed'] + lib_dirs:
|
for dir in source_dirs(bom_dir):
|
||||||
if os.path.isdir(dir):
|
if targets and os.path.isdir(dir):
|
||||||
for filename in os.listdir(dir):
|
for filename in os.listdir(dir):
|
||||||
if filename[-5:] == ".scad":
|
if targets and filename[-5:] == ".scad":
|
||||||
#
|
#
|
||||||
# find any modules ending in _<part_type>
|
# find any modules ending in _<part_type>
|
||||||
#
|
#
|
||||||
|
@ -148,9 +148,6 @@ def make_parts(target, part_type, parts = None):
|
||||||
#
|
#
|
||||||
if targets:
|
if targets:
|
||||||
for part in targets:
|
for part in targets:
|
||||||
if part[-4:] != '.' + part_type:
|
print("Could not find a module called", part[:-4] + module_suffix, "to make", part)
|
||||||
print(part, "is not a", part_type, "file")
|
|
||||||
else:
|
|
||||||
print("Could not find a module called", part[:-4] + module_suffix, "to make", part)
|
|
||||||
usage(part_type)
|
usage(part_type)
|
||||||
times.print_times()
|
times.print_times()
|
||||||
|
|
|
@ -38,13 +38,15 @@ def render(target, type):
|
||||||
#
|
#
|
||||||
# Make the target directory
|
# Make the target directory
|
||||||
#
|
#
|
||||||
target_dir = set_config(target, usage) + type + 's'
|
top_dir = set_config(target, usage)
|
||||||
|
target_dir = top_dir + type + 's'
|
||||||
|
bom_dir = top_dir + 'bom'
|
||||||
if not os.path.isdir(target_dir):
|
if not os.path.isdir(target_dir):
|
||||||
os.makedirs(target_dir)
|
os.makedirs(target_dir)
|
||||||
#
|
#
|
||||||
# Find all the parts
|
# Find all the parts
|
||||||
#
|
#
|
||||||
parts = bom_to_parts(target_dir, type)
|
parts = bom_to_parts(bom_dir, type)
|
||||||
#
|
#
|
||||||
# Remove unused png files
|
# Remove unused png files
|
||||||
#
|
#
|
||||||
|
|
|
@ -137,8 +137,7 @@ def views(target, do_assemblies = None):
|
||||||
# Find all the scad files
|
# Find all the scad files
|
||||||
#
|
#
|
||||||
main_blurb = None
|
main_blurb = None
|
||||||
lib_dirs = [path + '/' + lib + '/printed' for path in os.environ['OPENSCADPATH'].split(os.pathsep) for lib in sorted(os.listdir(path))]
|
for dir in source_dirs(bom_dir):
|
||||||
for dir in [source_dir, source_dir + '/printed'] + lib_dirs:
|
|
||||||
if os.path.isdir(dir):
|
if os.path.isdir(dir):
|
||||||
for filename in os.listdir(dir):
|
for filename in os.listdir(dir):
|
||||||
if filename.endswith('.scad'):
|
if filename.endswith('.scad'):
|
||||||
|
|
Loading…
Reference in New Issue