write_file node updated

This commit is contained in:
martinaCodes
2022-10-23 21:51:26 +02:00
committed by Dion Moult
parent ab218b842a
commit b5133f1c41
2 changed files with 36 additions and 19 deletions
+1 -9
View File
@@ -56,7 +56,7 @@ class SvIfcCreateShape(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.
self.process()
self.refresh_local = False
refresh_local: BoolProperty(name="Update Node", description="Update Node", update=refresh_node)
refresh_local: BoolProperty(name="Create shape(s)", description="Update Node", update=refresh_node)
bl_idname = "SvIfcCreateShape"
bl_label = "IFC Create Blender Shape"
@@ -68,26 +68,19 @@ class SvIfcCreateShape(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.
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")
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):
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)]
@@ -96,7 +89,6 @@ class SvIfcCreateShape(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.
def create(self):
blender_objects = []
for entity in self.entities:
print("entity: ", entity)
try:
if not entity.is_a("IfcProduct"):
return
+35 -10
View File
@@ -17,30 +17,55 @@
# You should have received a copy of the GNU General Public License
# along with IfcSverchok. If not, see <http://www.gnu.org/licenses/>.
from os.path import abspath, splitext
import bpy
import ifcopenshell
import ifcsverchok.helper
from bpy.props import StringProperty
from ifcsverchok.ifcstore import SvIfcStore
from bpy.props import StringProperty, BoolProperty
from sverchok.node_tree import SverchCustomTreeNode
from sverchok.data_structure import updateNode
from sverchok.data_structure import updateNode, flatten_data
class SvIfcWriteFile(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.SvIfcCore):
"""
Triggers: Ifc write to file
Tooltip: Write active Sverchok Ifc file to path
"""
def refresh_node_local(self, context):
if self.refresh_local:
self.process()
self.refresh_local = False
# out = ""
refresh_local: BoolProperty(name="Write", description="Write to file", update=refresh_node_local)
bl_idname = "SvIfcWriteFile"
bl_label = "IFC Write File"
file: StringProperty(name="file", update=updateNode)
path: StringProperty(name="path", update=updateNode)
path: StringProperty(name="path", description="File path to write to. Can be relative.", update=updateNode)
def sv_init(self, context):
self.inputs.new("SvStringsSocket", "file").prop_name = "file"
self.inputs.new("SvStringsSocket", "path").prop_name = "path"
self.outputs.new("SvStringsSocket", "output")
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.prop(self, 'refresh_local', icon='FILE_REFRESH')
def process(self):
self.sv_input_names = ["file", "path"]
super().process()
def process_ifc(self, file, path):
file.write(path)
path = flatten_data(self.inputs["path"].sv_get(), target_level = 1)[0]
if not path:
return
path = abspath(path)
file = SvIfcStore.get_file()
_, ext = splitext(path)
if not ext:
raise Exception("Bad path. Provide a path to a file.")
if self.refresh_local and ext:
file.write(path)
self.outputs["output"].sv_set(f"File written successfully to: {path}.")
def register():