nortikin / sverchok

Sverchok
http://nortikin.github.io/sverchok/
GNU General Public License v3.0
2.26k stars 233 forks source link

Eval Node (nickname, Eval Knieval) #257

Closed zeffii closed 10 years ago

zeffii commented 10 years ago

I'm a little bored with the Arc code, so some light entertainment. The node nickname is a play on the name famous American stunt devil. Doing really stupid things in the hope it will impress people. http://en.wikipedia.org/wiki/Evel_Knievel

Sometimes we want to do stupid or dangerous things, and right now there's just SN which is fine but it's overkill for certain things. For example if I wanted to control the 3d cursor, why not have a Node which can take arbitrary sockets in and assign values to whatever string the user inserts into the string field.

This node is like formula2 node, but it is specifically for scene/data properties. It will be a nice exercise in dynamic sockets and error handling. This will happen even if it doesn't end up in Sverchok ;)

zeffii commented 10 years ago

some demo examples of how to make Eval confused, generously provided by jimmy (https://github.com/nortikin/sverchok/pull/281#issuecomment-48074737, https://github.com/nortikin/sverchok/pull/281#issuecomment-48074788 )

blah = { x }; print(blah);
if ({x}): print("I am inside!")

but this works:

print({x}); blah = {x}

This could be better explained by the code the node uses to establish what it should do.

                t = self.eval_str.split("=")
                right_to_left = len(t[0]) > len(t[1])
                self.mode = 'input' if right_to_left else 'output'

That's crazy right? it's a massive assumption but it keeps the node dynamic

zeffii commented 10 years ago

I could make the node work only if the is is at the end or start of the string

some.variables.to.set=
=some.variables.to.get
# and the convenience functions

so no {x} in either case, but that sort of restricts the capacity a little.

zeffii commented 10 years ago

Another approach which i'm trying hard to resist is to make it determined by a toggle mode. In the back of my mind i get these messages to go this route anyway. These are the kinds of messages I often ignore at first, but more often than not eventually listen to.

enzyme69 commented 10 years ago

Yes, I don't mind the {x}. Kind of.

zeffii commented 10 years ago

the benefit of {x} is that you can have that variable easily in several parts of the eval string

zeffii commented 10 years ago

If i make the toggle mode there will be no automatic determination depended on =. It will not accept =. The mode switches would be Set | Get | Do . It doesn't become a different node but it certainly wont look the same.

zeffii commented 10 years ago

i've started a branch with a mode version, no ETA

zeffii commented 10 years ago

image no more {x}

enzyme69 commented 10 years ago

Ok, I have to update my blog writing about Eval Knieval that I just wrote yesterday.

zeffii commented 10 years ago

Yeah, perhaps wait a while before writing about it, because a few more things will change. Like the Do mode will have a selection of pre-filled function strings or something - i dunno, it's fluid still.

zeffii commented 10 years ago

quantize (animations can be annoying) but i'm not happy about the jump of the Enum property.. maybe put a fake spacer in draw_buttons for Do and Set

ly29 commented 10 years ago

Well, I think a separate input/output would be a good idea, but I guess it best to make input/output dynamic things.

zeffii commented 10 years ago

I'm not opposed to having separate nodes for [input / output] mode, of the nearly 600 lines of code, not much is shared between the modes.

zeffii commented 10 years ago

i'll need to stick some debug traceback the try / except why Blender will accept one matrix on a property, but not on a different property is confusion.

zeffii commented 10 years ago
Traceback (most recent call last):
  File "C:\blender_trunk\2.71\scripts\addons\sverchok\nodes\basic\eval_knieval.py", line 207, i
ss_input_to_bpy
    exec(fxed)
  File "<string>", line 1
    objs['Cube'].matrix_world = <Matrix 4x4 (1.0000, 0.0000, 0.0000, 0.0000)
                                ^
SyntaxError: invalid syntax

haha. w000t.

zeffii commented 10 years ago

at least I know what to fix now

zeffii commented 10 years ago

image

zeffii commented 10 years ago

for now this works: image

zeffii commented 10 years ago

of course the with x appendix is superfluous syntax, but I think it's a nice indicator

zeffii commented 10 years ago

image Works now too

zeffii commented 10 years ago

There's something not very Zen about the current implementation. Why have 3 hyper modes, when there are only 2 modes. in or out. in into bpy, out into Sverchok.

zeffii commented 10 years ago

i'll reopen this if I start working on it again