Drughi Posted February 4, 2019 Share Posted February 4, 2019 Hi, I have a string paramter on a node containing some python code and a button wich should execute the code. How do I write a callback script on the button so it executes the code stored as string in the other paramter? Quote Link to comment Share on other sites More sharing options...
Alain2131 Posted February 5, 2019 Share Posted February 5, 2019 (edited) See this The eval() function is what you are looking for stringCode = node.parm("someCodeParm").eval() eval(stringCode) As for calling this code when pressing a button, is this inside an HDA ? Edited February 5, 2019 by Alain2131 Quote Link to comment Share on other sites More sharing options...
Drughi Posted February 5, 2019 Author Share Posted February 5, 2019 (edited) 16 hours ago, Alain2131 said: See this The eval() function is what you are looking for stringCode = node.parm("someCodeParm").eval() eval(stringCode) As for calling this code when pressing a button, is this inside an HDA ? Ok, so now my Buttons callback script is: eval(kwargs['node'].parm('python').eval()) I've set the Python code string Tags to script_callback_language: python and editorlang: python. Just for testing I've just added: print "Yeay, it worked" But I'm getting the error: Traceback (most recent call last): File "<stdin>", line 1, in <module> SyntaxError: ('invalid syntax', ('<string>', 1, 5, 'print "Yeay, it worked"')) What am I doing wrong? Edited February 5, 2019 by Drughi Quote Link to comment Share on other sites More sharing options...
Alain2131 Posted February 5, 2019 Share Posted February 5, 2019 (edited) Okay, I see now My bad, here's the "right-er" info here In fact, it's "exec" that you want exec(kwargs['node'].parm('python').eval()) See below for the test I did Edited February 5, 2019 by Alain2131 1 Quote Link to comment Share on other sites More sharing options...
Drughi Posted February 6, 2019 Author Share Posted February 6, 2019 Cool, it worked! Thank you! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.