-
Notifications
You must be signed in to change notification settings - Fork 228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiline exec node #1056
Comments
(sadly editing isn't obvious with the box/non emboss version..) you have to leftclick and drag on the text to be able to select it for editing.. (or ctrl + left double click) def draw_buttons(self, context, layout):
b = layout.box()
col = b.column(align=True)
col.prop(self, "str1", text="", emboss=False)
col.prop(self, "str2", text="", emboss=False)
col.prop(self, "str3", text="", emboss=False) |
@Kosvor2 maybe make def process(self):
v1,v2,v3 = self.inputs
V1, V2, V3 = v1.sv_get(0), v2.sv_get(0), v3.sv_get(0)
out = []
extend = out.extend # make these available (and makes the code faster )
append = out.append
exec(self.str1+"\n"+self.str2+"\n"+self.str3)
self.outputs[0].sv_set(out) |
def draw_buttons(self, context, layout):
if not context.active_node == self:
b = layout.box()
col = b.column(align=True)
col.prop(self, "str1", text="", emboss=False)
col.prop(self, "str2", text="", emboss=False)
col.prop(self, "str3", text="", emboss=False)
else:
col = layout.column(align=True)
col.prop(self, "str1", text="")
col.prop(self, "str2", text="")
col.prop(self, "str3", text="") |
also i'm using a slightly older version of blender for windows, because of a bug in the windows ID / objects code.. that's why the X isn't there i think? |
Would be neat to make the string variables dynamically created, starting out with 3 -- and if user needs more then press but that's low priority.. |
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program 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 2
# of the License, or (at your option) any later version.
#
# This program 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 this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
import bpy
from bpy.props import StringProperty
import sverchok
from sverchok.node_tree import SverchCustomTreeNode
from sverchok.data_structure import updateNode
lines = """\
for i, i2 in zip(V1, V2):
out.append(i + i2)
""".strip().split('\n')
def update_wrapper(self, context):
try:
updateNode(context.node, context)
except:
...
# Assign a collection
class SvExecNodeDynaStringItem(bpy.types.PropertyGroup):
line = bpy.props.StringProperty(name="line to eval", default="", update=update_wrapper)
class SvExecNodeModCallback(bpy.types.Operator):
bl_idname = "node.callback_execnodemod"
bl_label = "generic callback"
cmd = bpy.props.StringProperty(default='')
def execute(self, context):
getattr(context.node, self.cmd)(self)
return {'FINISHED'}
class SvExecNodeMod(bpy.types.Node, SverchCustomTreeNode):
''' Objects Input Lite'''
bl_idname = 'SvExecNodeMod'
bl_label = 'Exec Node Mod'
bl_icon = 'OUTLINER_OB_EMPTY'
dynamic_strings = bpy.props.CollectionProperty(type=SvExecNodeDynaStringItem)
def draw_buttons(self, context, layout):
if len(self.dynamic_strings) == 0:
return
if not context.active_node == self:
b = layout.box()
col = b.column(align=True)
for idx, line in enumerate(self.dynamic_strings):
col.prop(self.dynamic_strings[idx], "line", text="", emboss=False)
else:
for idx, line in enumerate(self.dynamic_strings):
layout.prop(self.dynamic_strings[idx], "line", text="")
row = layout.row(align=True)
# add() remove() clear() move()
row.operator('node.callback_execnodemod', text='', icon='ZOOMIN').cmd = 'add_new_line'
row.operator('node.callback_execnodemod', text='', icon='ZOOMOUT').cmd = 'remove_last_line'
def add_new_line(self, context):
self.dynamic_strings.add().line = ""
def remove_last_line(self, context):
if len(self.dynamic_strings) > 1:
self.dynamic_strings.remove(len(self.dynamic_strings)-1)
def sv_init(self, context):
self.inputs.new('StringsSocket', 'V1')
self.inputs.new('StringsSocket', 'V2')
self.inputs.new('StringsSocket', 'V3')
self.outputs.new('StringsSocket', 'out')
# add default strings
self.dynamic_strings.add().line = lines[0]
self.dynamic_strings.add().line = lines[1]
self.dynamic_strings.add().line = ""
def process(self):
v1,v2,v3 = self.inputs
V1, V2, V3 = v1.sv_get(0), v2.sv_get(0), v3.sv_get(0)
out = []
extend = out.extend
append = out.append
exec('\n'.join([j.line for j in self.dynamic_strings]))
self.outputs[0].sv_set(out)
def register():
bpy.utils.register_class(SvExecNodeDynaStringItem)
bpy.utils.register_class(SvExecNodeMod)
bpy.utils.register_class(SvExecNodeModCallback)
def unregister():
bpy.utils.unregister_class(SvExecNodeModCallback)
bpy.utils.unregister_class(SvExecNodeMod)
bpy.utils.unregister_class(SvExecNodeDynaStringItem) |
not sure the nesting is working right there.. but that's all for now. |
fixed update wrapper, issue with nesting remains.. |
You mean like this:
|
yeah :) |
i quite like this form of exec node, the multi line solution is something that might replace the simpler node-scripts.. |
might have to include a variety of imports too , some of the math module perhaps |
with the dynamic strings I think the iojson code probably needs a dedicated encode/decode part.. iojson doesn't know about propertygroups../ collectionproperty |
iojson support added now #1064 |
@zeffii do you find it's worth to add this as mode? |
|
The second method avoids IF-ELSE statement within a Process that would make the node slower, so i will use it. |
A single if-else statement wouldn't contribute to significant speed fluctuation inside the can add a listener to text editors ctrl+enter operator, to update a current ExecNodeMod straight from text editor too.. |
Just wondering, with this Multi-Exec, what is the convenient or the special Sverchok functions in the node that allows for wrapping and putting list inside list inside list and stay sane? We have Script Node already and this one also can be super useful, but not sure where to start? @Kosvor2 Maybe Video tutorial? |
@zeffii I like the SN Lite for example and at some point you said it can do "vectorization" and although excited, but I was scared: is this going to be difficult? |
@enzyme69 snlite can already to vectorization, the snlite thread has examples.
jimmy, its difficulty is going to be directly proportional to your level of python-fu. But as it stands I think it's about as simple as it gets for snlite, maybe as it will ever get for code-based vectorization. |
Ok, interesting, in that case I'll do. Feels motivated! |
before you go nuts on snlite, it's still beta. consider it broken ( but it works for my needs ) . *reloading a .blend still doesn't pick up 'current' param values, * but this thread is not the place to talk about snlite. |
The text was updated successfully, but these errors were encountered: