Skip to content

Instantly share code, notes, and snippets.

@zeffii
Forked from anonymous/node_Script.py
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeffii/aa1097273419f3aa7730 to your computer and use it in GitHub Desktop.
Save zeffii/aa1097273419f3aa7730 to your computer and use it in GitHub Desktop.
def update_py(self):
'''
triggered when update is called, ideally this
- runs script with default values for those in_sockets not connected
- does nothing if input is unchanged.
'''
node_function = self.node_dict[hash(self)].get('node_function', None)
if not node_function:
return
defaults = node_function.__defaults__
input_names = [i.name for i in self.inputs]
fparams = []
for param_idx, name in enumerate(input_names):
links = self.inputs[name].links
this_val = defaults[param_idx]
if links:
# for now it is necessary type check these, it's a bit more code
# but allows for nested lists.
if isinstance(this_val, (int, float)):
k = str(SvGetSocketAnyType(self, self.inputs[param_idx]))
kfree = k[2:-2]
this_val = ast.literal_eval(kfree)
elif isinstance(this_val, list):
this_val = self.inputs[param_idx].sv_get()[0]
fparams.append(this_val)
if node_function and (len(fparams) == len(input_names)):
fn_return_values = node_function(*fparams)
out_sockets = fn_return_values[1]
for socket_type, name, data in out_sockets:
SvSetSocketAnyType(self, name, data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment