mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-17 14:02:27 +00:00
added entity locations
This commit is contained in:
@@ -54,6 +54,9 @@ class SvIfcBMeshToIfcRepr(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.help
|
|||||||
refresh_local: BoolProperty(name="Update Node", description="Update Node", update=refresh_node)
|
refresh_local: BoolProperty(name="Update Node", description="Update Node", update=refresh_node)
|
||||||
|
|
||||||
n_id: StringProperty()
|
n_id: StringProperty()
|
||||||
|
flat_output: BoolProperty(
|
||||||
|
name="Flat output", description="Flatten output by list-joining level 1",
|
||||||
|
default=True, update=updateNode)
|
||||||
context_types = [
|
context_types = [
|
||||||
('Model', 'Model', 'Context type: Model', 0),
|
('Model', 'Model', 'Context type: Model', 0),
|
||||||
('Plan', 'Plan', 'Context type: Plan', 1),
|
('Plan', 'Plan', 'Context type: Plan', 1),
|
||||||
@@ -90,8 +93,7 @@ class SvIfcBMeshToIfcRepr(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.help
|
|||||||
self.inputs.new("SvStringsSocket", "paradigm").prop_name = "paradigm"
|
self.inputs.new("SvStringsSocket", "paradigm").prop_name = "paradigm"
|
||||||
self.inputs.new("SvObjectSocket", "blender_objects").prop_name = "blender_objects" #no prop for now
|
self.inputs.new("SvObjectSocket", "blender_objects").prop_name = "blender_objects" #no prop for now
|
||||||
self.outputs.new("SvVerticesSocket", "Representations")
|
self.outputs.new("SvVerticesSocket", "Representations")
|
||||||
|
self.outputs.new("SvMatrixSocket", "Locations")
|
||||||
|
|
||||||
|
|
||||||
def draw_buttons(self, context, layout):
|
def draw_buttons(self, context, layout):
|
||||||
layout.operator("node.sv_ifc_tooltip", text="", icon="QUESTION", emboss=False).tooltip = "Blender mesh to Ifc Shape Representation. \nTakes one or multiple geometries."
|
layout.operator("node.sv_ifc_tooltip", text="", icon="QUESTION", emboss=False).tooltip = "Blender mesh to Ifc Shape Representation. \nTakes one or multiple geometries."
|
||||||
@@ -127,28 +129,37 @@ class SvIfcBMeshToIfcRepr(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.help
|
|||||||
if self.refresh_local:
|
if self.refresh_local:
|
||||||
edit = True
|
edit = True
|
||||||
if self.node_id not in SvIfcStore.id_map:
|
if self.node_id not in SvIfcStore.id_map:
|
||||||
representations = self.create(blender_objects)
|
representations, locations = self.create(blender_objects)
|
||||||
else:
|
else:
|
||||||
if edit is True:
|
if edit is True:
|
||||||
self.edit()
|
self.edit()
|
||||||
representations = self.create(blender_objects)
|
representations, locations = self.create(blender_objects)
|
||||||
else:
|
else:
|
||||||
# representations = self.get_existing_element()
|
# representations = self.get_existing_element()
|
||||||
representations = SvIfcStore.id_map[self.node_id]["Representations"]
|
representations = SvIfcStore.id_map[self.node_id]["Representations"]
|
||||||
|
locations = SvIfcStore.id_map[self.node_id]["Locations"]
|
||||||
|
|
||||||
print("representations: ", representations)
|
print("representations: ", representations)
|
||||||
|
print("locations: ", locations)
|
||||||
|
|
||||||
self.outputs["Representations"].sv_set(representations)
|
self.outputs["Representations"].sv_set(representations)
|
||||||
|
self.outputs["Locations"].sv_set(locations)
|
||||||
|
|
||||||
def create(self, blender_objects):
|
def create(self, blender_objects):
|
||||||
representations_ids = []
|
representations_ids = []
|
||||||
|
locations = []
|
||||||
|
add_matrix = locations.extend if self.flat_output else locations.append
|
||||||
for blender_object in blender_objects:
|
for blender_object in blender_objects:
|
||||||
representation = ifcopenshell.api.run("geometry.add_representation", self.file, should_run_listeners=False,blender_object = blender_object, geometry=blender_object.data, context = self.get_context())
|
representation = ifcopenshell.api.run("geometry.add_representation", self.file, should_run_listeners=False,blender_object = blender_object, geometry=blender_object.data, context = self.get_context())
|
||||||
if not representation:
|
if not representation:
|
||||||
raise Exception("Couldn't create representation. Possibly wrong context.")
|
raise Exception("Couldn't create representation. Possibly wrong context.")
|
||||||
representations_ids.append(representation.id())
|
representations_ids.append(representation.id())
|
||||||
SvIfcStore.id_map.setdefault(self.node_id, {}).setdefault("Representations", []).append(representation.id())
|
SvIfcStore.id_map.setdefault(self.node_id, {}).setdefault("Representations", []).append(representation.id())
|
||||||
return representations_ids
|
location = blender_object.matrix_world
|
||||||
|
print("\n", "#"*30, "location: ", location)
|
||||||
|
add_matrix(location)
|
||||||
|
SvIfcStore.id_map.setdefault(self.node_id, {}).setdefault("Locations", []).append(location)
|
||||||
|
return representations_ids, locations
|
||||||
|
|
||||||
def edit(self):
|
def edit(self):
|
||||||
# results = self.get_existing_element()
|
# results = self.get_existing_element()
|
||||||
@@ -158,6 +169,7 @@ class SvIfcBMeshToIfcRepr(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.help
|
|||||||
#if self.file.by_id(step_id).is_a('IfcShapeRepresentation'):
|
#if self.file.by_id(step_id).is_a('IfcShapeRepresentation'):
|
||||||
ifcopenshell.api.run("geometry.remove_representation", self.file, representation=self.file.by_id(step_id))
|
ifcopenshell.api.run("geometry.remove_representation", self.file, representation=self.file.by_id(step_id))
|
||||||
del SvIfcStore.id_map[self.node_id]["Representations"]
|
del SvIfcStore.id_map[self.node_id]["Representations"]
|
||||||
|
del SvIfcStore.id_map[self.node_id]["Locations"]
|
||||||
return
|
return
|
||||||
|
|
||||||
def get_existing_element(self):
|
def get_existing_element(self):
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ from ifcsverchok.ifcstore import SvIfcStore
|
|||||||
import bpy
|
import bpy
|
||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
|
|
||||||
from bpy.props import StringProperty, EnumProperty, IntProperty, BoolProperty, PointerProperty
|
from bpy.props import StringProperty, EnumProperty, IntProperty, BoolProperty
|
||||||
from sverchok.node_tree import SverchCustomTreeNode
|
from sverchok.node_tree import SverchCustomTreeNode
|
||||||
from sverchok.data_structure import updateNode, flatten_data, repeat_last_for_length
|
from sverchok.data_structure import updateNode, flatten_data, repeat_last_for_length
|
||||||
|
|
||||||
@@ -38,6 +38,7 @@ class SvIfcCreateEntity(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper
|
|||||||
Descriptions: StringProperty(name="Descriptions", default="", update=updateNode)
|
Descriptions: StringProperty(name="Descriptions", default="", update=updateNode)
|
||||||
IfcClass: StringProperty(name="IfcClass", update=updateNode)
|
IfcClass: StringProperty(name="IfcClass", update=updateNode)
|
||||||
Representations: StringProperty(name="Representations", default="", update=updateNode)
|
Representations: StringProperty(name="Representations", default="", update=updateNode)
|
||||||
|
# Locations: FloatVectorProperty(name="Locations", default="", update=updateNode)
|
||||||
Properties: StringProperty(name="properties", update=updateNode)
|
Properties: StringProperty(name="properties", update=updateNode)
|
||||||
|
|
||||||
def sv_init(self, context):
|
def sv_init(self, context):
|
||||||
@@ -45,6 +46,7 @@ class SvIfcCreateEntity(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper
|
|||||||
self.inputs.new("SvStringsSocket", "Descriptions").prop_name = "Descriptions"
|
self.inputs.new("SvStringsSocket", "Descriptions").prop_name = "Descriptions"
|
||||||
self.inputs.new("SvStringsSocket", "IfcClass").prop_name = "IfcClass"
|
self.inputs.new("SvStringsSocket", "IfcClass").prop_name = "IfcClass"
|
||||||
self.inputs.new("SvStringsSocket", "Representations").prop_name = "Representations"
|
self.inputs.new("SvStringsSocket", "Representations").prop_name = "Representations"
|
||||||
|
self.inputs.new("SvMatrixSocket", "Locations").is_mandatory=False
|
||||||
self.inputs.new("SvStringsSocket", "Properties").prop_name = "Properties"
|
self.inputs.new("SvStringsSocket", "Properties").prop_name = "Properties"
|
||||||
self.outputs.new("SvStringsSocket", "Entities")
|
self.outputs.new("SvStringsSocket", "Entities")
|
||||||
self.outputs.new("SvStringsSocket", "file") # only for testing
|
self.outputs.new("SvStringsSocket", "file") # only for testing
|
||||||
@@ -57,9 +59,6 @@ class SvIfcCreateEntity(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper
|
|||||||
row.prop(self, 'is_interactive', icon='SCENE_DATA', icon_only=True)
|
row.prop(self, 'is_interactive', icon='SCENE_DATA', icon_only=True)
|
||||||
row.prop(self, 'refresh_local', icon='FILE_REFRESH')
|
row.prop(self, 'refresh_local', icon='FILE_REFRESH')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def process(self):
|
def process(self):
|
||||||
print("#"*20, "\n running create_entity3 PROCESS()... \n", "#"*20,)
|
print("#"*20, "\n running create_entity3 PROCESS()... \n", "#"*20,)
|
||||||
print("#"*20, "\n hash(self):", hash(self), "\n", "#"*20,)
|
print("#"*20, "\n hash(self):", hash(self), "\n", "#"*20,)
|
||||||
@@ -68,6 +67,7 @@ class SvIfcCreateEntity(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper
|
|||||||
self.descriptions = flatten_data(self.inputs["Descriptions"].sv_get(), target_level=1)
|
self.descriptions = flatten_data(self.inputs["Descriptions"].sv_get(), target_level=1)
|
||||||
self.ifc_class = self.inputs["IfcClass"].sv_get()[0][0]
|
self.ifc_class = self.inputs["IfcClass"].sv_get()[0][0]
|
||||||
self.representations = flatten_data(self.inputs["Representations"].sv_get(), target_level=1)
|
self.representations = flatten_data(self.inputs["Representations"].sv_get(), target_level=1)
|
||||||
|
self.locations = flatten_data(self.inputs["Locations"].sv_get(default=[]), target_level=1)
|
||||||
self.properties = self.inputs["Properties"].sv_get()
|
self.properties = self.inputs["Properties"].sv_get()
|
||||||
|
|
||||||
|
|
||||||
@@ -84,7 +84,9 @@ class SvIfcCreateEntity(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper
|
|||||||
|
|
||||||
edit = False
|
edit = False
|
||||||
for i in range(len(self.inputs)):
|
for i in range(len(self.inputs)):
|
||||||
input = self.inputs[self.sv_input_names[i]].sv_get(deepcopy=False)
|
# if self.sv_input_names[i] == "Locations":
|
||||||
|
# input = self.inputs[self.sv_input_names[i]].sv_get(deepcopy=False, default = [])
|
||||||
|
input = self.inputs[self.sv_input_names[i]].sv_get(deepcopy=False, default =[])
|
||||||
# print("input: ", input)
|
# print("input: ", input)
|
||||||
# print("self.node_dict[hash(self)][self.inputs[i].name]: ", self.node_dict[hash(self)][self.inputs[i].name])
|
# print("self.node_dict[hash(self)][self.inputs[i].name]: ", self.node_dict[hash(self)][self.inputs[i].name])
|
||||||
if isinstance(self.node_dict[hash(self)][self.inputs[i].name], list) and input != self.node_dict[hash(self)][self.inputs[i].name]:
|
if isinstance(self.node_dict[hash(self)][self.inputs[i].name], list) and input != self.node_dict[hash(self)][self.inputs[i].name]:
|
||||||
@@ -137,6 +139,11 @@ class SvIfcCreateEntity(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper
|
|||||||
ifcopenshell.api.run("geometry.assign_representation", self.file, product=entity, representation=self.representations[i])
|
ifcopenshell.api.run("geometry.assign_representation", self.file, product=entity, representation=self.representations[i])
|
||||||
except IndexError:
|
except IndexError:
|
||||||
pass
|
pass
|
||||||
|
try:
|
||||||
|
print("LOCATION[i]: ", self.locations[i])
|
||||||
|
ifcopenshell.api.run("geometry.edit_object_placement", self.file, product=entity, matrix=self.locations[i])
|
||||||
|
except IndexError:
|
||||||
|
pass
|
||||||
entities_ids.append(entity.id())
|
entities_ids.append(entity.id())
|
||||||
SvIfcStore.id_map.setdefault(self.node_id, []).append(entity.id())
|
SvIfcStore.id_map.setdefault(self.node_id, []).append(entity.id())
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -164,7 +171,11 @@ class SvIfcCreateEntity(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper
|
|||||||
entity.Representation = self.representations[i]
|
entity.Representation = self.representations[i]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
pass
|
pass
|
||||||
|
try:
|
||||||
|
print("LOCATION[i]: ", self.locations[i])
|
||||||
|
ifcopenshell.api.run("geometry.edit_object_placement", self.file, product=entity, matrix=self.locations[i])
|
||||||
|
except IndexError:
|
||||||
|
pass
|
||||||
if entity.is_a() != self.ifc_class:
|
if entity.is_a() != self.ifc_class:
|
||||||
SvIfcStore.id_map[self.node_id].remove(step_id)
|
SvIfcStore.id_map[self.node_id].remove(step_id)
|
||||||
entity = ifcopenshell.util.schema.reassign_class(self.file, entity, self.ifc_class)
|
entity = ifcopenshell.util.schema.reassign_class(self.file, entity, self.ifc_class)
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ class SvIfcWriteFile(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.Sv
|
|||||||
|
|
||||||
def draw_buttons(self, context, layout):
|
def draw_buttons(self, context, layout):
|
||||||
row = layout.row(align=True)
|
row = layout.row(align=True)
|
||||||
layout.operator("node.sv_ifc_tooltip", text="", icon="QUESTION", emboss=False).tooltip = "Writes active Ifc file to path.\n It will overwrite an existing file."
|
row.operator("node.sv_ifc_tooltip", text="", icon="QUESTION", emboss=False).tooltip = "Writes active Ifc file to path.\n It will overwrite an existing file."
|
||||||
row.prop(self, 'refresh_local', icon='FILE_REFRESH')
|
row.prop(self, 'refresh_local', icon='FILE_REFRESH')
|
||||||
|
|
||||||
def process(self):
|
def process(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user