create_shape node updated + minor changes

This commit is contained in:
martinaCodes
2022-10-23 20:25:36 +02:00
committed by Dion Moult
parent 37aa17fcf3
commit ab218b842a
3 changed files with 89 additions and 50 deletions
+7 -4
View File
@@ -23,13 +23,13 @@ import ifcsverchok.helper
from ifcsverchok.ifcstore import SvIfcStore
from bpy.props import StringProperty
from sverchok.node_tree import SverchCustomTreeNode
from sverchok.data_structure import updateNode
from sverchok.data_structure import updateNode, flatten_data
class SvIfcById(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.SvIfcCore):
bl_idname = "SvIfcById"
bl_label = "IFC By Id"
id: StringProperty(name="Id(s)", update=updateNode)
id: StringProperty(name="Id(s)", update=updateNode, )
def sv_init(self, context):
self.inputs.new("SvStringsSocket", "id").prop_name = "id"
@@ -39,9 +39,12 @@ class SvIfcById(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.SvIfcCo
layout.operator("node.sv_ifc_tooltip", text="", icon="QUESTION", emboss=False).tooltip = "Get IFC element by step id. Takes one or multiple step ids."
def process(self):
self.ids = self.inputs["id"].sv_get()
self.ids = flatten_data(self.inputs["id"].sv_get(), target_level=1)
print(self.ids)
if not self.ids[0]:
return
self.file = SvIfcStore.get_file()
self.entities = [self.file.by_id(step_id) for step_id in self.ids]
self.entities = [self.file.by_id(int(step_id)) for step_id in self.ids]
self.outputs["Entities"].sv_set(self.entities)
def register():
+77 -40
View File
@@ -21,67 +21,104 @@ import bpy
import logging
import ifcopenshell
import ifcsverchok.helper
from ifcsverchok.ifcstore import SvIfcStore
import blenderbim.bim.import_ifc
from bpy.props import StringProperty
from bpy.props import StringProperty, PointerProperty, BoolProperty
from sverchok.node_tree import SverchCustomTreeNode
from sverchok.data_structure import updateNode
from sverchok.data_structure import zip_long_repeat
from sverchok.data_structure import updateNode, flatten_data
class SvIfcCreateShapeRefresh(bpy.types.Operator):
bl_idname = "node.sv_ifc_create_shape_refresh"
bl_label = "IFC Create Shape Refresh"
bl_options = {"UNDO"}
# class SvIfcCreateShapeRefresh(bpy.types.Operator):
# bl_idname = "node.sv_ifc_create_shape_refresh"
# bl_label = "IFC Create Shape Refresh"
# bl_options = {"UNDO"}
tree_name: StringProperty(default="")
node_name: StringProperty(default="")
def execute(self, context):
node = bpy.data.node_groups[self.tree_name].nodes[self.node_name]
node.process()
return {"FINISHED"}
# tree_name: StringProperty(default="")
# node_name: StringProperty(default="")
# def execute(self, context):
# node = bpy.data.node_groups[self.tree_name].nodes[self.node_name]
# node.process()
# return {"FINISHED"}
class SvIfcCreateShape(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.SvIfcCore):
"""
Triggers: Ifc create shape by entity
Tooltip: Create Blender shape by Ifc Entity
"""
is_scene_dependent = True
is_interactive = False
node_dict = {}
def refresh_node(self, context):
if self.refresh_local:
self.process()
self.refresh_local = False
refresh_local: BoolProperty(name="Update Node", description="Update Node", update=refresh_node)
bl_idname = "SvIfcCreateShape"
bl_label = "IFC Create Shape"
file: StringProperty(name="file", update=updateNode)
entity: StringProperty(name="entity", update=updateNode)
bl_label = "IFC Create Blender Shape"
entity: StringProperty(name="Entities", update=updateNode)
def sv_init(self, context):
self.inputs.new("SvStringsSocket", "file").prop_name = "file"
self.inputs.new("SvStringsSocket", "entity").prop_name = "entity"
self.inputs.new("SvStringsSocket", "Entities").prop_name = "entity"
self.outputs.new('SvStringsSocket', "Object(s)")
def draw_buttons(self, context, layout):
self.wrapper_tracked_ui_draw_op(layout, "node.sv_ifc_create_shape_refresh", icon="FILE_REFRESH", text="Refresh")
# self.wrapper_tracked_ui_draw_op(layout, "node.sv_ifc_create_shape_refresh", icon="FILE_REFRESH", text="Refresh")
row = layout.row(align=True)
row.operator("node.sv_ifc_tooltip", text="", icon="QUESTION", emboss=False).tooltip = "Create Blender shape from Ifc Entity. Takes one or multiple Ifc Entities."
# row.prop(self, 'is_interactive', icon='SCENE_DATA', icon_only=True)
row.prop(self, 'refresh_local', icon='FILE_REFRESH')
def process(self):
self.sv_input_names = ["file", "entity"]
super().process()
def process_ifc(self, file, entity):
try:
if not entity.is_a("IfcProduct"):
return
logger = logging.getLogger("ImportIFC")
self.ifc_import_settings = blenderbim.bim.import_ifc.IfcImportSettings.factory(bpy.context, "", logger)
settings = ifcopenshell.geom.settings()
shape = ifcopenshell.geom.create_shape(settings, entity)
ifc_importer = blenderbim.bim.import_ifc.IfcImporter(self.ifc_import_settings)
ifc_importer.file = file
mesh = ifc_importer.create_mesh(entity, shape)
obj = bpy.data.objects.new("IFC Element", mesh)
bpy.context.scene.collection.objects.link(obj)
except:
raise Exception("Entity could not be converted into a shape. Entity: {}".format(entity))
print("#"*20, "\n running create_entity3 PROCESS()... \n", "#"*20,)
print("#"*20, "\n hash(self):", hash(self), "\n", "#"*20,)
print("node_dict: ", self.node_dict)
self.entities = flatten_data(self.inputs["Entities"].sv_get(), target_level = 1)
if not self.entities[0]:
return
if self.refresh_local or hash(self) not in self.node_dict:
print("grr")
self.file = SvIfcStore.get_file()
blender_objects = self.create()
self.node_dict[hash(self)] = blender_objects
print("blender_objects: ", blender_objects)
else:
blender_objects = self.node_dict[hash(self)]
self.outputs["Object(s)"].sv_set(blender_objects)
def create(self):
blender_objects = []
for entity in self.entities:
print("entity: ", entity)
try:
if not entity.is_a("IfcProduct"):
return
logger = logging.getLogger("ImportIFC")
self.ifc_import_settings = blenderbim.bim.import_ifc.IfcImportSettings.factory(bpy.context, "", logger)
settings = ifcopenshell.geom.settings()
shape = ifcopenshell.geom.create_shape(settings, entity)
ifc_importer = blenderbim.bim.import_ifc.IfcImporter(self.ifc_import_settings)
ifc_importer.file = self.file
mesh = ifc_importer.create_mesh(entity, shape)
obj = bpy.data.objects.new("IFC Element", mesh)
blender_objects.append(obj)
bpy.context.scene.collection.objects.link(obj)
except:
raise Exception("Entity could not be converted into a shape. Entity: {}".format(entity))
return blender_objects
def register():
bpy.utils.register_class(SvIfcCreateShapeRefresh)
# bpy.utils.register_class(SvIfcCreateShapeRefresh)
bpy.utils.register_class(SvIfcCreateShape)
def unregister():
bpy.utils.unregister_class(SvIfcCreateShape)
bpy.utils.unregister_class(SvIfcCreateShapeRefresh)
# bpy.utils.unregister_class(SvIfcCreateShapeRefresh)
+5 -6
View File
@@ -69,7 +69,6 @@ class SvIfcSverchokToIfcRepr(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.h
self.inputs.new("SvStringsSocket", "Edges")
self.inputs.new("SvStringsSocket", "Faces")
self.outputs.new("SvVerticesSocket", "Representation(s)")
self.outputs.new("SvVerticesSocket", "File")
self.width = 210
self.node_dict[hash(self)] = {}
@@ -102,26 +101,26 @@ class SvIfcSverchokToIfcRepr(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.h
self.vertices = self.inputs["Vertices"].sv_get(deepcopy=False)
self.edges = self.inputs["Edges"].sv_get(deepcopy=False)
self.faces = self.inputs["Faces"].sv_get(deepcopy=False)
data = list(zip(self.vertices, self.edges, self.faces))
geo_data = list(zip(self.vertices, self.edges, self.faces))
if self.node_id not in SvIfcStore.id_map:
representations = self.create(data)
representations = self.create(geo_data)
else:
print("edit: ", edit)
if edit is True:
self.edit()
representations = self.create(data)
representations = self.create(geo_data)
else:
# representations = self.get_existing_element()
representations = SvIfcStore.id_map[self.node_id]["Representations"]
self.outputs["Representation(s)"].sv_set(representations)
def create(self, data):
def create(self, geo_data):
representations_ids = []
self.context = self.get_context()
for item in data:
for item in geo_data:
representation = ifcopenshell.api.run(
"geometry.add_sverchok_representation",
self.file,