Browse Source

Improved part metadata system

master
Youen 7 months ago
parent
commit
dfe5d329b3
  1. 7
      ahb_cmd_export_parts_list.py
  2. 2
      ahb_material.py
  3. 23
      ahb_techdraw_extensions.py

7
ahb_cmd_export_parts_list.py

@ -5,13 +5,15 @@ import ahb_utils
from ahb_material import Material
class PartInfo:
def __init__(self, document, obj):
def __init__(self, workbench, document, obj):
self.document = document
self.reference = obj.Label
if len(self.reference) == 3 and self.reference[0:1] in ['L', 'M', 'T', 'R', 'E']:
self.reference = 'TB_' + self.reference
workbench.techDrawExtensions.initPartMetadata(obj)
self.material = 'Unknown'
try:
self.material = obj.Assembly_handbook_Material
@ -52,13 +54,14 @@ class AHB_ExportPartsList:
all_parts = {}
rootAssembly = Gui.Selection.getSelection()[0]
workbench = Gui.getWorkbench("AssemblyHandbookWorkbench") #: :type workbench: AssemblyHandbookWorkbench
def add_part(part):
#print(part.Label + " (" + part.LinkedObject.Label + ")")
try:
info = all_parts[part.LinkedObject]
except:
info = PartInfo(part.LinkedObject.Document.Name, part.LinkedObject)
info = PartInfo(workbench, part.LinkedObject.Document.Name, part.LinkedObject)
all_parts[part.LinkedObject] = info
info.count += 1

2
ahb_material.py

@ -20,3 +20,5 @@ class Material:
Material.DB.append(Material('Stainless steel', density = 8.00))
Material.DB.append(Material('Aluminium', density = 2.71))
Material.DB.append(Material('Wood (pine)', density = 0.55))
Material.DB.append(Material('Plywood', density = 0.6))

23
ahb_techdraw_extensions.py

@ -807,20 +807,23 @@ class TechDrawExtensions:
pass
if main_part is not None:
self.initPartMetadata(main_part)
QTimer.singleShot(0, doInit)
def initPartMetadata(self, part):
current_material = 'Unknown'
if 'Assembly_handbook_Material' in main_part.PropertiesList:
current_material = main_part.Assembly_handbook_Material
if 'Assembly_handbook_Material' in part.PropertiesList:
current_material = part.Assembly_handbook_Material
else:
main_part.addProperty("App::PropertyEnumeration", "Assembly_handbook_Material", "Assembly_handbook")
part.addProperty("App::PropertyEnumeration", "Assembly_handbook_Material", "Assembly_handbook")
material_list = ['Unknown'] + Material.GetMaterialIDs()
main_part.Assembly_handbook_Material = material_list
main_part.Assembly_handbook_Material = material_list.index(current_material) if current_material in material_list else 0
part.Assembly_handbook_Material = material_list
part.Assembly_handbook_Material = material_list.index(current_material) if current_material in material_list else 0
if 'Assembly_handbook_Weight' not in main_part.PropertiesList:
main_part.addProperty("App::PropertyFloat", "Assembly_handbook_Weight", "Assembly_handbook", 'Part weight in grams. Set a negative number if weight is unknown.')
main_part.Assembly_handbook_Weight = -1
QTimer.singleShot(0, doInit)
if 'Assembly_handbook_Weight' not in part.PropertiesList:
part.addProperty("App::PropertyFloat", "Assembly_handbook_Weight", "Assembly_handbook", 'Part weight in grams. Set a negative number if weight is unknown.')
part.Assembly_handbook_Weight = -1
def onPageLoaded(self, page):
self.refreshOverlays(page)

Loading…
Cancel
Save