underscoreus Posted May 18, 2020 Share Posted May 18, 2020 (edited) Hey guys (and gals)! I'm working on a small project to simulate max style auto backups for Houdini wrapped up in an HDA. For this HDA I have a few functions in the python module that need to be able to read the values of the parameters of the HDA, like a string field where the user can say where to place the auto backups, determine the auto save intervals etc. However I am having some issues reading the parm values. So far I've been trying the normal method of first getting a referance to the node itself and then running: node = hou.node('.') node.parm('parmname').eval() However this is proving to be very unreliable, whenever I save and match definition the hda this approach no longer seems to work and I immediately get errors indicating that the first line trying to get a reference to the node returns none/NoneType. I have even tried to define it with a full path to the node like such: node = hou.node('/obj/autosaver1') But it still seems to encounter the same issue. I have seen some mentions of other methods but I am not really sure I fully get how they work. Any advice on the best and most reliable approach to getting the values from the different parameters of an HDA from within the python module? Thanks for the read! Stay safe out there! Edited May 18, 2020 by underscoreus Quote Link to comment Share on other sites More sharing options...
sant0s81 Posted May 18, 2020 Share Posted May 18, 2020 I am not 100% sure, but it sounds quite similar to my question. Check here: 1 Quote Link to comment Share on other sites More sharing options...
underscoreus Posted May 18, 2020 Author Share Posted May 18, 2020 10 hours ago, sant0s81 said: I am not 100% sure, but it sounds quite similar to my question. Check here: Hey, thanks for the post! I skimmed that topic before making this post, but had a more thorough read of it now. This kind of has the same issue as with my previous examples, just using a different syntax. I got the same errors when trying this solution unfortunately. For some reason it seems like Houdini is not able to correctly evaluate hou.node calls when made from inside an HDA's python module. Thanks for the tip though! Quote Link to comment Share on other sites More sharing options...
Atom Posted May 19, 2020 Share Posted May 19, 2020 (edited) The safest way is to check that the value you fetch is valid before you attempt to evaluate the parameter. node = hou.node('/obj/autosaver1') if node != None: # Success in obtaining a reference to the node. p = node.parm("my_parm") if p != None: # Success in obtaining a reference to parm. my_value = p.eval() else: print "parm not found" else: print "node not found" Edited May 19, 2020 by Atom 1 Quote Link to comment Share on other sites More sharing options...
anim Posted May 19, 2020 Share Posted May 19, 2020 (edited) it's usually either node = hou.pwd() to get the current node, like your HDA or maybe more reliable may be to pass kwargs dictionary from let's say your callback script and use node = kwargs['node'] to get the hda node, then node.parm("parmname") should be fine Edited May 19, 2020 by anim 1 Quote Link to comment Share on other sites More sharing options...
underscoreus Posted May 19, 2020 Author Share Posted May 19, 2020 4 hours ago, anim said: it's usually either node = hou.pwd() to get the current node, like your HDA or maybe more reliable may be to pass kwargs dictionary from let's say your callback script and use node = kwargs['node'] to get the hda node, then node.parm("parmname") should be fine Hmm, I've never quiet understood what or how the kwargs work. However I am already calling a python function in my callback script. Is the kwargs a variable that can be added to any function/definition? i.e:"def my_test_def(kwargs):" ? 5 hours ago, Atom said: The safest way is to check that the value you fetch is valid before you attempt to evaluate the parameter. node = hou.node('/obj/autosaver1') if node != None: # Success in obtaining a reference to the node. p = node.parm("my_parm") if p != None: # Success in obtaining a reference to parm. my_value = p.eval() else: print "parm not found" else: print "node not found" Oh yeah! I should really be making my tools "safer" in that regard, either using that syntax or the "try: except:" way to prevent straight up errors. For now I've just been deving/been lazy and not made any safety nets for that kind of stuff. Also, I won't jinx it since it's started to work before and then stopped but I think I found my issue. A very clear user error on the most basic level which has me a little embarrassed. I made the node variable at the top of the script outside any of the definitions I call from the callback script tabs of my parameters... So it was as if the variable was kind of never created to begin with... ... ... so, yeah. Wish I had thought of that sooner. Thanks both of you for replying and bringing up very good points I should improve on stuff though! Quote Link to comment Share on other sites More sharing options...
anim Posted May 19, 2020 Share Posted May 19, 2020 31 minutes ago, underscoreus said: Hmm, I've never quiet understood what or how the kwargs work when callback script is executed, houdini passed kwargs dictionary with specific keys to it, you can directly use it there or pass further to a function you are calling from hdaModule, and whenever possible I'd prefer that over hou.pwd() and of course over hardcoded hackery here is an example callback_parm_kwargs_hda_node.hip 1 1 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.