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
|
import shutil
|
||||||
from PIL import Image, ImageFilter
|
from PIL import Image, ImageFilter
|
||||||
|
|
||||||
|
render_main = False
|
||||||
|
render_stages = False
|
||||||
|
render_parts = True
|
||||||
|
|
||||||
workbench = Gui.getWorkbench("AssemblyHandbookWorkbench")
|
workbench = Gui.getWorkbench("AssemblyHandbookWorkbench")
|
||||||
doc = App.activeDocument()
|
doc = App.activeDocument()
|
||||||
doc_file_name: str = doc.FileName
|
doc_file_name: str = doc.FileName
|
||||||
@ -165,15 +169,15 @@ class AHB_Render:
|
|||||||
filename = os.path.splitext(doc_file_name)[0] + ".png"
|
filename = os.path.splitext(doc_file_name)[0] + ".png"
|
||||||
dir = os.path.dirname(filename)
|
dir = os.path.dirname(filename)
|
||||||
|
|
||||||
resolution = (2000,2000)
|
if render_main:
|
||||||
workbench.context.setAllStagesVisible(True)
|
resolution = (2000,2000)
|
||||||
self.render(resolution, filename)
|
workbench.context.setAllStagesVisible(True)
|
||||||
img_full = Image.new('RGB', resolution, (255, 255, 255))
|
self.render(resolution, filename)
|
||||||
img = Image.open(filename)
|
img_full = Image.new('RGB', resolution, (255, 255, 255))
|
||||||
img_full.paste(img, None, img.getchannel('A'))
|
img = Image.open(filename)
|
||||||
img_full.save(filename)
|
img_full.paste(img, None, img.getchannel('A'))
|
||||||
|
img_full.save(filename)
|
||||||
|
|
||||||
render_stages = True
|
|
||||||
if render_stages:
|
if render_stages:
|
||||||
shutil.rmtree(dir + "/stages", ignore_errors=True)
|
shutil.rmtree(dir + "/stages", ignore_errors=True)
|
||||||
os.makedirs(dir + "/stages", exist_ok=True)
|
os.makedirs(dir + "/stages", exist_ok=True)
|
||||||
@ -206,6 +210,38 @@ class AHB_Render:
|
|||||||
pass
|
pass
|
||||||
prev_stage_id = stage_id
|
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)
|
workbench.context.setAllStagesVisible(True)
|
||||||
|
|
||||||
from ahb_command import AHB_CommandWrapper
|
from ahb_command import AHB_CommandWrapper
|
||||||
|
Loading…
Reference in New Issue
Block a user