1
0
mirror of https://github.com/nophead/NopSCADlib.git synced 2025-07-30 20:30:09 +02:00

Added pose_stl() module because pose() only works for assembly views.

This commit is contained in:
Chris Palmer
2025-04-09 23:29:00 +01:00
parent 6a58d37f77
commit 33ac3820b0
4 changed files with 26 additions and 7 deletions

View File

@@ -69,7 +69,10 @@ class Part:
self.count = 1
for arg in args:
arg = arg.replace('true', 'True').replace('false', 'False').replace('undef', 'None')
exec('self.' + arg)
try:
exec('self.' + arg)
except:
print(arg)
def data(self):
return self.__dict__
@@ -107,7 +110,7 @@ class BOM:
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)]
args = match.group(2).split('|')
if s[-4:] == ".stl":
parts = self.printed
else:

View File

@@ -61,11 +61,14 @@ def render(target, type):
things = { 'stl' : 'printed', 'dxf' : 'routed', 'svg' : 'routed' }[type]
colours = {}
cameras = {}
for ass in flat_bom:
for part in ass[things]:
obj = ass[things][part]
if "colour" in obj:
colours[part] = obj["colour"]
if "camera" in obj:
cameras[part] = obj["camera"]
#
# Remove unused png files
#
@@ -87,17 +90,20 @@ def render(target, type):
png_maker_name = tmp_dir + "/png.scad"
pp1 = [0, 146/255, 0]
colour = pp1
camera = "0,0,0,70,0,315,500"
if part in cameras:
camera = cameras[part]
if part in colours:
colour = colours[part]
if not '[' in colour:
colour = '"' + colour + '"'
with open(png_maker_name, "w") as f:
f.write('color(%s) import("%s");\n' % (colour, reltmp(part_file, target)))
cam = "--camera=0,0,0,70,0,315,500" if type == 'stl' else "--camera=0,0,0,0,0,0,500"
cam = "--camera=" + camera if type == 'stl' else "--camera=0,0,0,0,0,0,500"
render = "--preview" if type == 'stl' or colour != pp1 else "--render"
tmp_name = tmp_dir + '/' + part[:-4] + '.png'
dummy_deps_name = tmp_dir + '/tmp.deps' # work around for OpenSCAD issue #3879
openscad.run("-o", tmp_name, png_maker_name, colour_scheme, "--projection=p", image_size, cam, render, "-D$pose=1", "-D$explode=0", "--autocenter", "--viewall", "-d", dummy_deps_name)
openscad.run("-o", tmp_name, png_maker_name, colour_scheme, "--projection=p", image_size, cam, render, "--autocenter", "--viewall", "-d", dummy_deps_name)
do_cmd(("magick "+ tmp_name + " -trim -resize 280x280 -background %s -gravity Center -extent 280x280 -bordercolor %s -border 10 %s"
% (background, background, tmp_name)).split())
update_image(tmp_name, png_name)