1
0
mirror of https://github.com/nophead/NopSCADlib.git synced 2025-08-06 15:36:30 +02:00

Add generating SVG file for CNC usage

Generate SVG files, like DXF files for CNC usage
This commit is contained in:
Jeroen Roos
2024-02-04 17:32:39 +01:00
parent e3ad32713d
commit f85fdca051
12 changed files with 85 additions and 19 deletions

View File

@@ -104,14 +104,14 @@ class BOM:
def add_part(self, s):
args = []
match = re.match(r'^(.*?\.stl|.*?\.dxf)\((.*)\)$', s) #look for name.stl(...) or name.dxf(...)
match = re.match(r'^(.*?\.stl|.*?\.dxf|.*?\.svg)\((.*)\)$', s) #look for name.stl(...), name.dxf(...) or name.svg(...)
if match:
s = match.group(1)
args = [match.group(2)]
if s[-4:] == ".stl":
parts = self.printed
else:
if s[-4:] == ".dxf":
if s[-4:] == ".dxf" or s[-4:] == ".svg":
parts = self.routed
else:
parts = self.vitamins

View File

@@ -35,7 +35,7 @@ def read_deps(dname):
for line in lines:
if line.startswith('\t'):
dep = line[1 : -1].rstrip(' \\').replace('\\ ', ' ')
if not os.path.basename(dep) in ['stl.scad', 'dxf.scad', 'svf.scad', 'png.scad', 'target.scad']:
if not os.path.basename(dep) in ['stl.scad', 'dxf.scad', 'svg.scad', 'png.scad', 'target.scad']:
deps.append(dep)
return deps

View File

@@ -39,7 +39,7 @@ def bom_to_parts(bom_dir, part_type, assembly = None):
#
part_files = []
bom = assembly + '.txt' if assembly else "bom.txt"
suffix = ".dxf" if part_type == 'svg' else '.' + part_type
suffix = '.' + part_type
with open(bom_dir + '/' + bom, "rt") as f:
for line in f.readlines():
words = line.split()
@@ -106,7 +106,7 @@ def make_parts(target, part_type, parts = None):
#
# Find all the scad files
#
module_suffix = '_dxf' if part_type == 'svg' else '_' + part_type
module_suffix = '_' + part_type
for dir in source_dirs(bom_dir):
if targets and os.path.isdir(dir):
for filename in os.listdir(dir):

View File

@@ -39,7 +39,7 @@ if __name__ == '__main__':
target = None if len(sys.argv) == 1 else sys.argv[1]
set_config(target, usage)
boms(target)
for part in ['stl', 'dxf']:
for part in ['stl', 'dxf', 'svg']:
make_parts(target, part)
render(target, part)
plateup(target, part)

View File

@@ -31,8 +31,8 @@ import re
import time
import times
source_dirs = { "stl" : "platters", "dxf" : "panels" }
target_dirs = { "stl" : "printed", "dxf" : "routed" }
source_dirs = { "stl" : "platters", "dxf" : "panels", "svg" : "panels" }
target_dirs = { "stl" : "printed", "dxf" : "routed", "svg" : "routed" }
def plateup(target, part_type, usage = None):
#

View File

@@ -33,7 +33,7 @@ import json
from tmpdir import *
def usage():
print("\nusage:\n\trender [target_config] - Render images of the stl and dxf files.");
print("\nusage:\n\trender [target_config] - Render images of the stl, dxf and svg files.");
sys.exit(1)
def render(target, type):
@@ -57,7 +57,7 @@ def render(target, type):
with open(bom_file) as json_file:
flat_bom = json.load(json_file)
things = { 'stl' : 'printed', 'dxf' : 'routed' }[type]
things = { 'stl' : 'printed', 'dxf' : 'routed', 'svg' : 'routed' }[type]
colours = {}
for ass in flat_bom:
for part in ass[things]:
@@ -112,3 +112,4 @@ if __name__ == '__main__':
target = sys.argv[1] if len(sys.argv) > 1 else None
render(target, 'stl')
render(target, 'dxf')
render(target, 'svg')

View File

@@ -374,7 +374,12 @@ def views(target, do_assemblies = None):
print('\n|%s' % ('---|' * n), file = doc_file)
for j in range(n):
part = keys[i - n + j + 1]
print('| ![%s](dxfs/%s) %s' % (part, part.replace('.dxf','.png'), '|\n' if j == j - 1 else ''), end = '', file = doc_file)
if (part[-4:] == ".dxf"):
print('| ![%s](dxfs/%s) %s' % (part, part.replace('.dxf','.png'), '|\n' if j == j - 1 else ''), end = '', file = doc_file)
elif (part[-4:] == ".svg"):
print('| ![%s](svgs/%s) %s' % (part, part.replace('.svg','.png'), '|\n' if j == j - 1 else ''), end = '', file = doc_file)
else:
print("Unkown file type ", part[-4:], " for file ", part)
print('\n', file = doc_file)
print('\n', file = doc_file)