-
-
Save zeffii/11067619 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# prognose | |
def sv_main(num_poly=20, skip=5): | |
# in boilerplate, could be | |
in_sockets = [[type(v), k, v] for k, v in vars().items()] | |
# arbitrary user code | |
p = [(i, i+1, i+7, i+6) for i in range(num_poly) if (i-skip) % (skip+1)] | |
# out boilerplate | |
out_sockets = [ | |
[str, p, 'Polygons'] | |
] | |
return in_sockets, out_sockets | |
if __name__ == "__main__": | |
prognose = sv_main({0},{1}) | |
################ | |
import bpy | |
import ast | |
# get script from choice | |
script = 'prognose' | |
script_str = bpy.data.texts[script].as_string() | |
def find_variables(script_str): | |
lines = script_str.split('\n') | |
lines_a = [i for i in lines if script in i] | |
import re | |
if len(lines_a) == 1: | |
pattern = '\{(\d+?)\}' | |
f = re.findall(pattern, lines_a[0]) | |
num_params = len(f) | |
else: | |
return False, False | |
lines_b = [i for i in lines if ('def sv_main') in i] | |
if len(lines_b) == 1: | |
pattern2 = '=(.+?)[,\)]' | |
f2 = re.findall(pattern2, lines_b[0]) | |
# cast here | |
param_values = f2 | |
else: | |
return False, False | |
return num_params, param_values | |
nparams, params = find_variables(script_str) | |
print(nparams, params) | |
if all([nparams, params]): | |
params = list(map(ast.literal_eval, params)) | |
print(params) | |
exec(script_str.format(30, 5)) | |
f = vars() | |
print('-----') | |
print(f['prognose']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment