forked from youen/assembly_handbook
added individual part rendering to images
This commit is contained in:
parent
c59bfba1d1
commit
8812a6cf86
@ -156,6 +156,10 @@ class AHB_Render:
|
||||
import shutil
|
||||
from PIL import Image, ImageFilter
|
||||
|
||||
render_main = False
|
||||
render_stages = False
|
||||
render_parts = True
|
||||
|
||||
workbench = Gui.getWorkbench("AssemblyHandbookWorkbench")
|
||||
doc = App.activeDocument()
|
||||
doc_file_name: str = doc.FileName
|
||||
@ -165,6 +169,7 @@ class AHB_Render:
|
||||
filename = os.path.splitext(doc_file_name)[0] + ".png"
|
||||
dir = os.path.dirname(filename)
|
||||
|
||||
if render_main:
|
||||
resolution = (2000,2000)
|
||||
workbench.context.setAllStagesVisible(True)
|
||||
self.render(resolution, filename)
|
||||
@ -173,7 +178,6 @@ class AHB_Render:
|
||||
img_full.paste(img, None, img.getchannel('A'))
|
||||
img_full.save(filename)
|
||||
|
||||
render_stages = True
|
||||
if render_stages:
|
||||
shutil.rmtree(dir + "/stages", ignore_errors=True)
|
||||
os.makedirs(dir + "/stages", exist_ok=True)
|
||||
@ -206,6 +210,38 @@ class AHB_Render:
|
||||
pass
|
||||
prev_stage_id = stage_id
|
||||
|
||||
if render_parts:
|
||||
rendered_references = []
|
||||
resolution = (500, 500)
|
||||
shutil.rmtree(dir + "/parts", ignore_errors=True)
|
||||
os.makedirs(dir + "/parts", exist_ok=True)
|
||||
count = 0
|
||||
for part_to_render in doc.Objects:
|
||||
if part_to_render.TypeId == 'Part::Feature' and 'AssemblyHandbook_Stage' in part_to_render.PropertiesList:
|
||||
if 'Base_Reference' not in part_to_render.PropertiesList or part_to_render.Base_Reference == "" or part_to_render.Base_Reference in rendered_references:
|
||||
continue
|
||||
|
||||
rendered_references.append(part_to_render.Base_Reference)
|
||||
|
||||
for part_to_hide in doc.Objects:
|
||||
if part_to_hide.TypeId == 'Part::Feature':
|
||||
part_to_hide.ViewObject.Visibility = False
|
||||
part_to_render.ViewObject.Visibility = True
|
||||
|
||||
Gui.ActiveDocument.ActiveView.fitAll()
|
||||
|
||||
part_filename = dir + "/parts/" + part_to_render.Base_Reference.upper().replace(' ', '-') + ".png"
|
||||
self.render(resolution, part_filename)
|
||||
|
||||
bg = Image.new('RGB', resolution, (255, 255, 255))
|
||||
fg = Image.open(part_filename)
|
||||
bg.paste(fg, None, fg.getchannel('A'))
|
||||
bg.save(part_filename)
|
||||
|
||||
count = count + 1
|
||||
if count == 10:
|
||||
pass
|
||||
|
||||
workbench.context.setAllStagesVisible(True)
|
||||
|
||||
from ahb_command import AHB_CommandWrapper
|
||||
|
Loading…
Reference in New Issue
Block a user