Psets and qtos can be selected from a list instead of typed

This commit is contained in:
Dion Moult
2020-04-08 14:15:36 +10:00
parent 44b49f4ce9
commit f6db62c758
2 changed files with 37 additions and 2 deletions
@@ -1,6 +1,7 @@
import json
import os
import csv
import ifcopenshell
from pathlib import Path
from . import export_ifc
from . import schema
@@ -33,6 +34,8 @@ psetfiles_enum = []
classification_enum = []
reference_enum = []
attributes_enum = []
overridepsetnames_enum = []
qtonames_enum = []
materialattributes_enum = []
documents_enum = []
materialtypes_enum = []
@@ -260,6 +263,32 @@ def getReferences(self, context):
return reference_enum
def getOverridePsetNames(self, context):
global overridepsetnames_enum
overridepsetnames_enum.clear()
if '/' in context.active_object.name \
and context.active_object.name.split('/')[0] in schema.ifc.elements:
empty = ifcopenshell.file()
element = empty.create_entity(context.active_object.name.split('/')[0])
for ifc_class, pset_names in schema.ifc.applicable_psets.items():
if element.is_a(ifc_class):
overridepsetnames_enum.extend([(p, p, '') for p in pset_names])
return overridepsetnames_enum
def getQtoNames(self, context):
global qtonames_enum
qtonames_enum.clear()
if '/' in context.active_object.name \
and context.active_object.name.split('/')[0] in schema.ifc.elements:
empty = ifcopenshell.file()
element = empty.create_entity(context.active_object.name.split('/')[0])
for ifc_class, qto_names in schema.ifc.applicable_qtos.items():
if element.is_a(ifc_class):
qtonames_enum.extend([(q, q, '') for q in qto_names])
return qtonames_enum
def getApplicableAttributes(self, context):
global attributes_enum
attributes_enum.clear()
@@ -718,8 +747,8 @@ class BIMObjectProperties(PropertyGroup):
classifications: CollectionProperty(name="Classifications", type=Classification)
material_type: EnumProperty(items=getMaterialTypes, name="Material Type")
override_psets: CollectionProperty(name="Override Psets", type=PsetQto)
override_pset_name: StringProperty(name="Override Pset Name")
qto_name: StringProperty(name="Qto Name")
override_pset_name: EnumProperty(items=getOverridePsetNames, name='Override Pset Name')
qto_name: EnumProperty(items=getQtoNames, name='Qto Name')
has_boundary_condition: BoolProperty(name='Has Boundary Condition')
boundary_condition: PointerProperty(name='Boundary Condition', type=BoundaryCondition)
structural_member_connection: PointerProperty(name='Structural Member Connection', type=bpy.types.Object)
@@ -26,6 +26,8 @@ class IfcSchema():
self.property_files.append(ifcopenshell.open(path))
self.psets = {}
self.qtos = {}
self.applicable_psets = {}
self.applicable_qtos = {}
self.load()
def load(self):
@@ -42,8 +44,12 @@ class IfcSchema():
if prop.Name[0:4] == 'Qto_':
self.qtos[prop.Name] = {
'HasPropertyTemplates': {p.Name: p for p in prop.HasPropertyTemplates}}
entity = prop.ApplicableEntity if prop.ApplicableEntity else 'IfcRoot'
self.applicable_qtos.setdefault(entity, []).append(prop.Name)
else:
self.psets[prop.Name] = {
'HasPropertyTemplates': {p.Name: p for p in prop.HasPropertyTemplates}}
entity = prop.ApplicableEntity if prop.ApplicableEntity else 'IfcRoot'
self.applicable_psets.setdefault(entity, []).append(prop.Name)
ifc = IfcSchema()