Atom Posted December 8, 2014 Share Posted December 8, 2014 I have NULL with a python script inside with a single print statement. At the object level of the NULL I have add a Button to the parameter interface. How do I link the code to the button? What do I put in the callback script field? Thanks Quote Link to comment Share on other sites More sharing options...
mightcouldb1 Posted December 8, 2014 Share Posted December 8, 2014 https://www.sidefx.com/index.php?option=com_forum&Itemid=172&page=viewtopic&t=12725&highlight= https://www.sidefx.com/docs/houdini13.0/hom/hou/ButtonParmTemplate Quote Link to comment Share on other sites More sharing options...
Atom Posted December 8, 2014 Author Share Posted December 8, 2014 (edited) Hmm... thank you for the link from 2008 but I think things have changed. That looks like spoofing python using Hscript. But now we have the full option of running Python natively. I mentioned a simple print statement in the first post to simplify the problem but I do need to import and run and entire module from a button click. The path to my python module looks like this: /obj/null1/python1/python I drop that into the callback field, switch from Hscript to Python and when I click the button I get an error. SyntaxError: ('invalid syntax', ('<stdin>', 1, 1, '/obj/null1/python1/python\n')) edit . . . If I change the statement in the callback field to an exec() I get a little further. exec("import python1") Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<string>", line 1, in <module> ImportError: No module named python1 However if I use the full path to the node I get. exec("import /obj/null1/python1") Traceback (most recent call last): File "<stdin>", line 1, in <module> SyntaxError: ('invalid syntax', ('<string>', 1, 8, 'import /obj/null1/python1\n')) How the heck do I supply a path to my python module for inclusion..? Edited December 8, 2014 by Atom Quote Link to comment Share on other sites More sharing options...
fathom Posted December 19, 2014 Share Posted December 19, 2014 so you added a python module called "python1" to your null object with the button, yeah? honestly, i'm not sure how you'd reference custom python module. however, if you just create the normal "python module", then it's very easy to call functions out of that. if you have a function defined in your python module called, say, "foo()" you could call that by putting this in your callback script (setting the language to python): hou.phm().foo() that should do it. phm() is a shortcut to retrieve the python module from the current node. long form would be "hou.pwd().hdaModule()" which does the same thing. Quote Link to comment Share on other sites More sharing options...
Stalkerx777 Posted December 19, 2014 Share Posted December 19, 2014 (edited) On 12/8/2014 at 3:17 AM, Atom said: I have NULL with a python script inside with a single print statement. For me it sound like:" I have a c++ source code somewhere in my car". Where exactly did you put your script and why? Quote The path to my python module looks like this: /obj/null1/python1/python How is that?. There is no such thing in houdini as "Python Module SOP". Python SOP can contain python code, but it shouldn't be considered for storing python code unrelated to geometry, this operator belongs to. I think you misunderstood python in houdini completely. For storing python code in hip file, use hou.session module (Windows -> Python Source Editor). For storing python in operator, make HDA and put python there. Edited December 19, 2014 by Stalkerx777 Quote Link to comment Share on other sites More sharing options...
Atom Posted December 19, 2014 Author Share Posted December 19, 2014 (edited) I don't think I misunderstand python completely. I already have a scene generator working in the Python Source Editor. Perhaps HDA is the way to go, but what I am trying to accomplish is to simply add some interface controls to my existing script. I thought if I could just place it in a NULL and then add a button that would work. Then I could I add some parameters to the interface to route to my existing variables in the script. NOTE: My code is not generating geometry within the node, it is creating an entire scene. For example I expect to be able to issue a hou.createNode() anywhere within Houdini. Even if it is considered a poor practice, it should work, correct? So within the example image shown below I could put a line of code that created a subnet at the /obj level. That, of course, has nothing to do with the SOP level of the NULL where the code is executing. I am just looking for a container with a button and some parameters. The Source Editor Window does not offer that ASFAIK. My Steps So Far: Create a NULL. Dive Inside. Delete what is there. Add a Python Node. So the button sits one level up, and so would the parameters. The script sits inside. Why is this asking for the moon? Houdini clearly supports this setup because I can create it. I just need a way to call my main() and reference external parameters. @fathom Quote if you just create the normal "python module", then it's very easy to call functions out of that. I thought I was creating a normal python module using the steps I mentioned above? What do you call a normal python module and where does it reside within the Houdini scene? I already have code within the Python Source Editor is that what you mean? Edited December 19, 2014 by Atom Quote Link to comment Share on other sites More sharing options...
Stalkerx777 Posted December 19, 2014 Share Posted December 19, 2014 Quote I thought I was creating a normal python module using the steps I mentioned above? What do you call a normal python module and where does it reside within the Houdini scene? I already have code within the Python Source Editor is that what you mean? That's what i mean when i say you misunderstood python in houdini. Read what python module is: http://www.sidefx.com/docs/houdini13.0/hom/assetscripts Just create digital asset out of your null, add python module section, and make any magic you want. Quote Link to comment Share on other sites More sharing options...
Atom Posted December 20, 2014 Author Share Posted December 20, 2014 So what good is the callback script? I still don't get it. If I can only put one line in the callback field what good is it? Quote Link to comment Share on other sites More sharing options...
pezetko Posted December 20, 2014 Share Posted December 20, 2014 You can run it from callback script, but it's quite ugly solution.Look at this, it's really good intro to Python in Houdini http://www.digitaltutors.com/tutorial/1855-Scripting-with-Python-in-Houdini Quote Link to comment Share on other sites More sharing options...
fathom Posted December 24, 2014 Share Posted December 24, 2014 @fathom I thought I was creating a normal python module using the steps I mentioned above? What do you call a normal python module and where does it reside within the Houdini scene? I already have code within the Python Source Editor is that what you mean? i misunderstood what you had done. i thought you had created a python module inside of a digital asset but had given it a custom name (not the generic "python module" name). now i understand that you created a python sop. a digital asset is really the way to go here. 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.