added entity locations

This commit is contained in:
martinaCodes
2022-10-24 00:08:59 +02:00
committed by Dion Moult
parent b5133f1c41
commit 039727cb19
3 changed files with 35 additions and 12 deletions
+17 -5
View File
@@ -54,6 +54,9 @@ class SvIfcBMeshToIfcRepr(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.help
refresh_local: BoolProperty(name="Update Node", description="Update Node", update=refresh_node)
n_id: StringProperty()
flat_output: BoolProperty(
name="Flat output", description="Flatten output by list-joining level 1",
default=True, update=updateNode)
context_types = [
('Model', 'Model', 'Context type: Model', 0),
('Plan', 'Plan', 'Context type: Plan', 1),
@@ -90,9 +93,8 @@ class SvIfcBMeshToIfcRepr(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.help
self.inputs.new("SvStringsSocket", "paradigm").prop_name = "paradigm"
self.inputs.new("SvObjectSocket", "blender_objects").prop_name = "blender_objects" #no prop for now
self.outputs.new("SvVerticesSocket", "Representations")
self.outputs.new("SvMatrixSocket", "Locations")
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."
@@ -127,28 +129,37 @@ class SvIfcBMeshToIfcRepr(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.help
if self.refresh_local:
edit = True
if self.node_id not in SvIfcStore.id_map:
representations = self.create(blender_objects)
representations, locations = self.create(blender_objects)
else:
if edit is True:
self.edit()
representations = self.create(blender_objects)
representations, locations = self.create(blender_objects)
else:
# representations = self.get_existing_element()
representations = SvIfcStore.id_map[self.node_id]["Representations"]
locations = SvIfcStore.id_map[self.node_id]["Locations"]
print("representations: ", representations)
print("locations: ", locations)
self.outputs["Representations"].sv_set(representations)
self.outputs["Locations"].sv_set(locations)
def create(self, blender_objects):
representations_ids = []
locations = []
add_matrix = locations.extend if self.flat_output else locations.append
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())
if not representation:
raise Exception("Couldn't create representation. Possibly wrong context.")
representations_ids.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):
# 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'):
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]["Locations"]
return
def get_existing_element(self):
+17 -6
View File
@@ -13,7 +13,7 @@ from ifcsverchok.ifcstore import SvIfcStore
import bpy
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.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)
IfcClass: StringProperty(name="IfcClass", update=updateNode)
Representations: StringProperty(name="Representations", default="", update=updateNode)
# Locations: FloatVectorProperty(name="Locations", default="", update=updateNode)
Properties: StringProperty(name="properties", update=updateNode)
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", "IfcClass").prop_name = "IfcClass"
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.outputs.new("SvStringsSocket", "Entities")
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, 'refresh_local', icon='FILE_REFRESH')
def process(self):
print("#"*20, "\n running create_entity3 PROCESS()... \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.ifc_class = self.inputs["IfcClass"].sv_get()[0][0]
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()
@@ -84,7 +84,9 @@ class SvIfcCreateEntity(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper
edit = False
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("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]:
@@ -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])
except IndexError:
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())
SvIfcStore.id_map.setdefault(self.node_id, []).append(entity.id())
except Exception as e:
@@ -164,7 +171,11 @@ class SvIfcCreateEntity(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper
entity.Representation = self.representations[i]
except IndexError:
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:
SvIfcStore.id_map[self.node_id].remove(step_id)
entity = ifcopenshell.util.schema.reassign_class(self.file, entity, self.ifc_class)
+1 -1
View File
@@ -50,7 +50,7 @@ class SvIfcWriteFile(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.Sv
def draw_buttons(self, context, layout):
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')
def process(self):