Browse Source

wip

pull/1/head
Youen Toupin 2 years ago
parent
commit
eeb2515e2a
  1. 12
      ahb_cmd_export_csv.py
  2. 3
      ahb_cmd_parse_step.py
  3. 67
      ahb_cmd_render.py

12
ahb_cmd_export_csv.py

@ -33,7 +33,17 @@ class AHB_ExportCsv:
parts = []
obj: App.DocumentObject
for obj in doc.Objects:
if obj.TypeId == 'Part::Feature':
if obj.TypeId in ['Part::Feature', 'App::Part']:
if obj.TypeId == 'App::Part' and ('Base_Reference' not in obj.PropertiesList or obj.Base_Reference == ''):
continue
parent = obj.Parents[0][0] if len(obj.Parents) > 0 else None
if parent is not None and parent.TypeId != 'App::Part':
parent = None
if parent is not None and 'Base_Reference' in parent.PropertiesList and parent.Base_Reference != "":
continue
parts.append((readProp(obj, 'Base_Layer', '').replace(',', '-') + "," + readProp(obj, 'Base_Reference', '').replace(',', '-'), obj.Label.replace(',', '-')))
parts.sort()

3
ahb_cmd_parse_step.py

@ -43,8 +43,9 @@ class AHB_ParseStep:
if override_names:
object_idx = feature_idx + 1
else:
fixed_name = step_parser.process_name(obj.Label)[0]
for idx in range(len(step_info.objects)):
if step_info.objects[idx].name == obj.Label:
if step_info.objects[idx].name == fixed_name:
object_idx = idx
break

67
ahb_cmd_render.py

@ -155,11 +155,16 @@ class AHB_Render:
def Activated(self):
import shutil
from PIL import Image, ImageFilter
import math
from pivy import coin
render_main = False
render_stages = False
render_parts = True
Gui.Selection.clearSelection()
Gui.activeDocument().activeView().setCameraType("Orthographic")
workbench = Gui.getWorkbench("AssemblyHandbookWorkbench")
doc = App.activeDocument()
doc_file_name: str = doc.FileName
@ -212,24 +217,80 @@ class AHB_Render:
if render_parts:
rendered_references = []
resolution = (500, 500)
max_resolution = 1500
max_length = 2000
min_resolution = 250
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 part_to_render.TypeId in ['Part::Feature', 'App::Part']:
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
parent = part_to_render.Parents[0][0] if len(part_to_render.Parents) > 0 else None
if parent is not None and parent.TypeId != 'App::Part':
parent = None
if parent is not None and 'Base_Reference' in parent.PropertiesList and parent.Base_Reference != "":
continue
#if not part_to_render.Label.startswith("L") and not part_to_render.Label.startswith("M") and not part_to_render.Label.startswith("T") and not part_to_render.Label.startswith("R"):
# 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
part_to_render.ViewObject.Visibility = True
if part_to_render.TypeId == 'App::Part':
for feature in part_to_render.Group:
feature.ViewObject.Visibility = True
dimensions = [part_to_render.Shape.BoundBox.XLength, part_to_render.Shape.BoundBox.YLength, part_to_render.Shape.BoundBox.ZLength]
main_axis: int = 0;
main_length: float = part_to_render.Shape.BoundBox.XLength
if part_to_render.Shape.BoundBox.YLength > main_length:
main_axis = 1
main_length = part_to_render.Shape.BoundBox.YLength
if part_to_render.Shape.BoundBox.ZLength > main_length:
main_axis = 2
main_length = part_to_render.Shape.BoundBox.ZLength
center = coin.SbVec3f(part_to_render.Shape.BoundBox.Center)
offset = coin.SbVec3f(800, -2000, 800)
up = coin.SbVec3f(0, 0, 1)
if main_axis == 1:
offset[0], offset[1] = -offset[1], offset[0]
elif main_axis == 2:
offset[0], offset[2] = -offset[2], offset[0]
up = coin.SbVec3f(-1, 0, 0)
cam = Gui.ActiveDocument.ActiveView.getCameraNode()
cam.position = center + offset
cam.pointAt(center, up)
Gui.ActiveDocument.ActiveView.fitAll()
cross_length = 0
if main_axis == 0:
cross_length = max(dimensions[1] * 0.5, dimensions[2])
elif main_axis == 1:
cross_length = max(dimensions[0] * 0.5, dimensions[2])
elif main_axis == 2:
cross_length = max(dimensions[0], dimensions[1] * 0.5)
cross_length = max(cross_length, main_length * 0.25 + cross_length * 0.8)
main_length_pixels = max(min_resolution, int(math.sqrt(min(1.0, main_length / max_length)) * max_resolution))
cross_length_pixels = int(cross_length * main_length_pixels / main_length)
cam.scaleHeight(0.05 + 0.95 * cross_length_pixels / main_length_pixels)
resolution = (main_length_pixels, cross_length_pixels)
part_filename = dir + "/parts/" + part_to_render.Base_Reference.upper().replace(' ', '-') + ".png"
self.render(resolution, part_filename)

Loading…
Cancel
Save