mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-11 10:06:47 +00:00
updated by_type to current workflow + added sv_to_ifc
This commit is contained in:
@@ -69,6 +69,7 @@ def nodes_index():
|
||||
("ifc.api", "SvIfcApi"),
|
||||
("ifc.api_WIP", "SvIfcApiWIP"),
|
||||
("ifc.bmesh_to_ifc", "SvIfcBMeshToIfcGeo"),
|
||||
("ifc.sverchok_to_ifc", "SvIfcSverchokToIfc"),
|
||||
("ifc.create_project", "SvIfcCreateProject"),
|
||||
("ifc.quick_project_setup", "SvIfcQuickProjectSetup")
|
||||
|
||||
|
||||
@@ -40,7 +40,6 @@ class SvIfcById(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.SvIfcCo
|
||||
|
||||
def process(self):
|
||||
self.ids = self.inputs["id"].sv_get()
|
||||
print(self.ids)
|
||||
self.file = SvIfcStore.get_file()
|
||||
self.entities = [self.file.by_id(step_id) for step_id in self.ids]
|
||||
self.outputs["Entities"].sv_set(self.entities)
|
||||
|
||||
@@ -21,13 +21,14 @@ import bpy
|
||||
import ifcopenshell
|
||||
import ifcsverchok.helper
|
||||
from bpy.props import StringProperty, EnumProperty
|
||||
from ifcsverchok.ifcstore import SvIfcStore
|
||||
from sverchok.node_tree import SverchCustomTreeNode
|
||||
from sverchok.data_structure import updateNode
|
||||
|
||||
|
||||
def get_ifc_products(self, context):
|
||||
ifc_products = getattr(self, "ifc_products", [])
|
||||
file = self.inputs["file"].sv_get()[0][0]
|
||||
file = SvIfcStore.get_file()
|
||||
if not file:
|
||||
return []
|
||||
if ifc_products and file:
|
||||
@@ -61,7 +62,7 @@ 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]
|
||||
file = SvIfcStore.get_file()
|
||||
if not file:
|
||||
return []
|
||||
schema = ifcopenshell.ifcopenshell_wrapper.schema_by_name(file.schema)
|
||||
@@ -83,31 +84,35 @@ def get_ifc_classes(self, context):
|
||||
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=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)
|
||||
ifc_product: EnumProperty(items=get_ifc_products, name="IfcProduct", description="Pick an IfcProduct from drop-down.", update=update_ifc_products)
|
||||
ifc_class: EnumProperty(items=get_ifc_classes, name="IfcClass", description="Pick an IfcClass from drop-down.", update=updateNode)
|
||||
custom_ifc_class: StringProperty(name="Custom IfcClass", description="Give the name of your custom IfcClass.", update=updateNode)
|
||||
|
||||
def sv_init(self, context):
|
||||
self.inputs.new("SvStringsSocket", "file").prop_name = "file"
|
||||
self.inputs.new("SvStringsSocket", "ifc_product").prop_name = "ifc_product"
|
||||
self.inputs.new("SvStringsSocket", "ifc_class").prop_name = "ifc_class"
|
||||
self.inputs.new("SvStringsSocket", "custom_ifc_class").prop_name = "custom_ifc_class"
|
||||
self.outputs.new("SvStringsSocket", "entity")
|
||||
self.outputs.new("SvStringsSocket", "Entity")
|
||||
self.width = 200
|
||||
|
||||
def draw_buttons(self, context, layout):
|
||||
layout.operator("node.sv_ifc_tooltip", text="", icon="QUESTION", emboss=False).tooltip = "Get IFC element(s) in file by type. \nPick an IfcProduct and an IfcClass or give a custom IfcClass."
|
||||
|
||||
def process(self):
|
||||
file = self.inputs["file"].sv_get()[0][0]
|
||||
if file:
|
||||
self.file = SvIfcStore.get_file()
|
||||
if self.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"]
|
||||
self.sv_input_names = ["ifc_product", "ifc_class", "custom_ifc_class"]
|
||||
super().process()
|
||||
|
||||
def process_ifc(self, file, ifc_product, ifc_class, custom_ifc_class):
|
||||
def process_ifc(self, ifc_product, ifc_class, custom_ifc_class):
|
||||
if custom_ifc_class:
|
||||
self.outputs["entity"].sv_set([file.by_type(custom_ifc_class)])
|
||||
self.outputs["Entity"].sv_set([self.file.by_type(custom_ifc_class)])
|
||||
elif ifc_class:
|
||||
self.outputs["Entity"].sv_set([self.file.by_type(ifc_class)])
|
||||
else:
|
||||
self.outputs["entity"].sv_set([file.by_type(ifc_class)])
|
||||
self.outputs["Entity"].sv_set([])
|
||||
|
||||
|
||||
def register():
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
# IfcSverchok - IFC Sverchok extension
|
||||
# Copyright (C) 2022 Dion Moult <dion@thinkmoult.com>
|
||||
#
|
||||
# This file is part of IfcSverchok.
|
||||
#
|
||||
# IfcSverchok is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# IfcSverchok is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with IfcSverchok. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import bpy
|
||||
import ifcopenshell
|
||||
import ifcsverchok.helper
|
||||
import ifcopenshell.api
|
||||
from ifcsverchok.ifcstore import SvIfcStore
|
||||
import blenderbim.tool as tool
|
||||
import blenderbim.core.geometry as core
|
||||
from bpy.props import StringProperty, EnumProperty, IntProperty
|
||||
from sverchok.node_tree import SverchCustomTreeNode
|
||||
from sverchok.data_structure import updateNode
|
||||
|
||||
|
||||
class SvIfcSverchokToIfc(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.SvIfcCore):
|
||||
bl_idname = "SvIfcSverchokToIfc"
|
||||
bl_label = "IFC Sverchok to IFC"
|
||||
|
||||
context_types = [
|
||||
('Model', 'Model', 'Context type: Model', 0),
|
||||
('Plan', 'Plan', 'Context type: Plan', 1),
|
||||
]
|
||||
|
||||
context_identifiers = [
|
||||
('Body', 'Body', 'Context identifier: Body', 0),
|
||||
('Annotation', 'Annotation', 'Context identifier: Annotation', 1),
|
||||
('Box', 'Box', 'Context identifier: Box', 2),
|
||||
('Axis', 'Axis', 'Context identifier: Axis', 3),
|
||||
]
|
||||
target_views = [
|
||||
('MODEL_VIEW', 'MODEL_VIEW', 'Target View: MODEL_VIEW', 0),
|
||||
('PLAN_VIEW', 'PLAN_VIEW', 'Target View: PLAN_VIEW', 1),
|
||||
('GRAPH_VIEW', 'GRAPH_VIEW', 'Target View: GRAPH_VIEW', 2),
|
||||
('SKETCH_VIEW', 'SKETCH_VIEW', 'Target View: SKETCH_VIEW', 3),
|
||||
]
|
||||
|
||||
context_type: EnumProperty(name="Context Type", description="Default: Model", default="Model",items=context_types,update=updateNode)
|
||||
context_identifier: EnumProperty(name="Context Identifier", description="Default: Body", default="Body", items=context_identifiers, update=updateNode)
|
||||
target_view: EnumProperty(name="Target View", description="Default: MODEL VIEW", default="MODEL_VIEW",items=target_views, update=updateNode)
|
||||
|
||||
def sv_init(self, context):
|
||||
self.inputs.new("SvVerticesSocket", "Vertices")
|
||||
self.inputs.new("SvStringsSocket", "Edges")
|
||||
self.inputs.new("SvStringsSocket", "Faces")
|
||||
self.inputs.new("SvStringsSocket", "context_type").prop_name = "context_type"
|
||||
self.inputs.new("SvStringsSocket", "context_identifier").prop_name = "context_identifier"
|
||||
self.inputs.new("SvStringsSocket", "target_view").prop_name = "target_view"
|
||||
|
||||
self.outputs.new("SvVerticesSocket", "Representation")
|
||||
self.outputs.new("SvVerticesSocket", "File")
|
||||
|
||||
def draw_buttons(self, context, layout):
|
||||
op = layout.operator(
|
||||
"node.sv_ifc_tooltip", text="", icon="QUESTION", emboss=False
|
||||
).tooltip = "Blender mesh to Ifc Shape Representation"
|
||||
|
||||
def process(self):
|
||||
self.file = SvIfcStore.get_file()
|
||||
|
||||
self.sv_input_names = [i.name for i in self.inputs]
|
||||
|
||||
if self.node_id in SvIfcStore.id_map:
|
||||
for step_id in SvIfcStore.id_map[self.node_id]:
|
||||
ifcopenshell.api.run(
|
||||
"geometry.remove_representation", self.file, representation=self.file.by_id(step_id)
|
||||
)
|
||||
del SvIfcStore.id_map[self.node_id]
|
||||
|
||||
results = []
|
||||
|
||||
representation = ifcopenshell.api.run(
|
||||
"geometry.add_sverchok_representation",
|
||||
self.file,
|
||||
should_run_listeners=False,
|
||||
context=self.get_context(),
|
||||
vertices=self.inputs["Vertices"].sv_get(),
|
||||
faces=self.inputs["Faces"].sv_get(),
|
||||
)
|
||||
results.append(representation)
|
||||
SvIfcStore.id_map.setdefault(self.node_id, []).append(representation.id())
|
||||
|
||||
SvIfcStore.file = self.file
|
||||
|
||||
self.outputs["File"].sv_set([[self.file]]) # only for testing
|
||||
self.outputs["Representation"].sv_set([results])
|
||||
|
||||
def get_context(self):
|
||||
context = ifcopenshell.util.representation.get_context(
|
||||
self.file, self.context_type, self.context_identifier, self.target_view
|
||||
)
|
||||
if not context:
|
||||
parent = ifcopenshell.util.representation.get_context(self.file, self.context_type)
|
||||
if not parent:
|
||||
parent = ifcopenshell.api.run("context.add_context", self.file, context_type=self.context_type)
|
||||
context = ifcopenshell.api.run(
|
||||
"context.add_context",
|
||||
self.file,
|
||||
context_type=self.context_type,
|
||||
context_identifier=self.context_identifier,
|
||||
target_view=self.target_view,
|
||||
parent=model,
|
||||
)
|
||||
return context
|
||||
|
||||
def sv_free(self):
|
||||
print("it was deleted")
|
||||
try:
|
||||
pass
|
||||
# SvIfcStore.id_map.pop(self.representation.id())
|
||||
# SvIfcStore.id_map.pop(self.context.id())
|
||||
except KeyError or AttributeError:
|
||||
pass
|
||||
|
||||
|
||||
def register():
|
||||
bpy.utils.register_class(SvIfcSverchokToIfc)
|
||||
|
||||
|
||||
def unregister():
|
||||
bpy.utils.unregister_class(SvIfcSverchokToIfc)
|
||||
Reference in New Issue
Block a user