Skip to content

Commit

Permalink
IfcSverchok by_type node now updates to be schema dependent on the in…
Browse files Browse the repository at this point in the history
…put file
  • Loading branch information
Moult committed Jul 3, 2021
1 parent e0048f7 commit b7cfa53
Showing 1 changed file with 61 additions and 3 deletions.
64 changes: 61 additions & 3 deletions src/ifcsverchok/nodes/ifc/by_type.py
Expand Up @@ -4,15 +4,69 @@
from bpy.props import StringProperty, EnumProperty
from sverchok.node_tree import SverchCustomTreeNode
from sverchok.data_structure import updateNode
from blenderbim.bim.module.root.prop import getIfcClasses, getIfcProducts, refreshClasses, refreshPredefinedTypes


def get_ifc_products(self, context):
ifc_products = getattr(self, "ifc_products", [])
file = self.inputs["file"].sv_get()[0][0]
if not file:
return []
if ifc_products and file:
return ifc_products
ifc_products = []
ifc_products.extend(
[
(e, e, "")
for e in [
"IfcElement",
"IfcElementType",
"IfcSpatialElement",
"IfcGroup",
"IfcStructuralItem",
"IfcContext",
"IfcAnnotation",
]
]
)
if file.schema == "IFC2X3":
ifc_products[2] = ("IfcSpatialStructureElement", "IfcSpatialStructureElement", "")
return ifc_products


def update_ifc_products(self, context):
if hasattr(self, "ifc_classes"):
self.ifc_classes.clear()


def get_ifc_classes(self, context):
ifc_classes = getattr(self, "ifc_classes", [])
if ifc_classes:
return self.ifc_classes
file = self.inputs["file"].sv_get()[0][0]
if not file:
return []
schema = ifcopenshell.ifcopenshell_wrapper.schema_by_name(file.schema)
declaration = schema.declaration_by_name(self.ifc_product)

def get_classes(declaration):
results = []
if not declaration.is_abstract():
results.append(declaration.name())
for subtype in declaration.subtypes():
results.extend(get_classes(subtype))
return results

classes = get_classes(declaration)
ifc_classes.extend([(c, c, "") for c in sorted(classes)])
return ifc_classes


class SvIfcByType(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.SvIfcCore):
bl_idname = "SvIfcByType"
bl_label = "IFC By Type"
file: StringProperty(name="file", update=updateNode)
ifc_product: EnumProperty(items=getIfcProducts, name="Products", update=refreshClasses)
ifc_class: EnumProperty(items=getIfcClasses, name="Class", update=refreshPredefinedTypes)
ifc_product: EnumProperty(items=get_ifc_products, name="Products", update=update_ifc_products)
ifc_class: EnumProperty(items=get_ifc_classes, name="Class", update=updateNode)
custom_ifc_class: StringProperty(name="Custom Ifc Class", update=updateNode)

def sv_init(self, context):
Expand All @@ -23,6 +77,10 @@ def sv_init(self, context):
self.outputs.new("SvStringsSocket", "entity")

def process(self):
file = self.inputs["file"].sv_get()[0][0]
if file:
self.ifc_products = get_ifc_products(self, bpy.context)
self.ifc_classes = get_ifc_classes(self, bpy.context)
self.sv_input_names = ["file", "ifc_product", "ifc_class", "custom_ifc_class"]
super().process()

Expand Down

0 comments on commit b7cfa53

Please sign in to comment.