forked from youen/assembly_handbook
Improved part metadata system
This commit is contained in:
parent
f92482eb46
commit
dfe5d329b3
@ -5,13 +5,15 @@ import ahb_utils
|
|||||||
from ahb_material import Material
|
from ahb_material import Material
|
||||||
|
|
||||||
class PartInfo:
|
class PartInfo:
|
||||||
def __init__(self, document, obj):
|
def __init__(self, workbench, document, obj):
|
||||||
self.document = document
|
self.document = document
|
||||||
self.reference = obj.Label
|
self.reference = obj.Label
|
||||||
|
|
||||||
if len(self.reference) == 3 and self.reference[0:1] in ['L', 'M', 'T', 'R', 'E']:
|
if len(self.reference) == 3 and self.reference[0:1] in ['L', 'M', 'T', 'R', 'E']:
|
||||||
self.reference = 'TB_' + self.reference
|
self.reference = 'TB_' + self.reference
|
||||||
|
|
||||||
|
workbench.techDrawExtensions.initPartMetadata(obj)
|
||||||
|
|
||||||
self.material = 'Unknown'
|
self.material = 'Unknown'
|
||||||
try:
|
try:
|
||||||
self.material = obj.Assembly_handbook_Material
|
self.material = obj.Assembly_handbook_Material
|
||||||
@ -52,13 +54,14 @@ class AHB_ExportPartsList:
|
|||||||
all_parts = {}
|
all_parts = {}
|
||||||
|
|
||||||
rootAssembly = Gui.Selection.getSelection()[0]
|
rootAssembly = Gui.Selection.getSelection()[0]
|
||||||
|
workbench = Gui.getWorkbench("AssemblyHandbookWorkbench") #: :type workbench: AssemblyHandbookWorkbench
|
||||||
|
|
||||||
def add_part(part):
|
def add_part(part):
|
||||||
#print(part.Label + " (" + part.LinkedObject.Label + ")")
|
#print(part.Label + " (" + part.LinkedObject.Label + ")")
|
||||||
try:
|
try:
|
||||||
info = all_parts[part.LinkedObject]
|
info = all_parts[part.LinkedObject]
|
||||||
except:
|
except:
|
||||||
info = PartInfo(part.LinkedObject.Document.Name, part.LinkedObject)
|
info = PartInfo(workbench, part.LinkedObject.Document.Name, part.LinkedObject)
|
||||||
all_parts[part.LinkedObject] = info
|
all_parts[part.LinkedObject] = info
|
||||||
|
|
||||||
info.count += 1
|
info.count += 1
|
||||||
|
@ -20,3 +20,5 @@ class Material:
|
|||||||
|
|
||||||
Material.DB.append(Material('Stainless steel', density = 8.00))
|
Material.DB.append(Material('Stainless steel', density = 8.00))
|
||||||
Material.DB.append(Material('Aluminium', density = 2.71))
|
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))
|
||||||
|
@ -807,20 +807,23 @@ class TechDrawExtensions:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
if main_part is not None:
|
if main_part is not None:
|
||||||
current_material = 'Unknown'
|
self.initPartMetadata(main_part)
|
||||||
if 'Assembly_handbook_Material' in main_part.PropertiesList:
|
|
||||||
current_material = main_part.Assembly_handbook_Material
|
|
||||||
else:
|
|
||||||
main_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
|
|
||||||
|
|
||||||
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)
|
QTimer.singleShot(0, doInit)
|
||||||
|
|
||||||
|
def initPartMetadata(self, part):
|
||||||
|
current_material = 'Unknown'
|
||||||
|
if 'Assembly_handbook_Material' in part.PropertiesList:
|
||||||
|
current_material = part.Assembly_handbook_Material
|
||||||
|
else:
|
||||||
|
part.addProperty("App::PropertyEnumeration", "Assembly_handbook_Material", "Assembly_handbook")
|
||||||
|
material_list = ['Unknown'] + Material.GetMaterialIDs()
|
||||||
|
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 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):
|
def onPageLoaded(self, page):
|
||||||
self.refreshOverlays(page)
|
self.refreshOverlays(page)
|
||||||
|
Loading…
Reference in New Issue
Block a user