art3mis Posted April 23, 2017 Share Posted April 23, 2017 Came across the above solution when trying to enable OpenCL globally. This is my exact implementation import hou; def set_opencl(parent_node, parm_value): for node in parent_node.allSubChildren(): for p in node.parms(): if p.name()=='opencl': try: p.set(parm_value) except hou.PermissionError: #this handles the case that the parm is inside of a locked .otl pass hou.session.set_opencl(hou.node('/obj/dopnet1'), 1); But get the following error message. have googled but no solution so far. Can any Python experts help? Quote The attempted operation failed. Traceback (most recent call last): File "hou.session", line 10, in <module> File "hou.session", line 2, in set_opencl AttributeError: 'NoneType' object has no attribute 'allSubChildren' Quote Link to comment Share on other sites More sharing options...
f1480187 Posted April 23, 2017 Share Posted April 23, 2017 (edited) 1. If you make a shelf tool containing Python script, try to change the last line to something like this: set_opencl(hou.selectedNodes()[0], True) It will try to set parm called "opencl" to True for selected node's children recursively. 2. If you don't need shelf tool and want to use this script in one scene, open Windows > Python Source Editor, paste only function into it and accept. It will store this script into hip and will run it every time you open the scene. All functions and variables defined there will be added to the hou.session module. When you want to use the function, open Windows > Python Shell and execute any of this: >>> hou.session.set_opencl(hou.node('/obj/dopnet1'), True) >>> hou.session.set_opencl(hou.node('/obj/dopnet1'), False) Arrows indicate Python Shell input, do not include them. Obviously, you need to provide correct path to target dopnet node. Easiest way is to erase first argument and drag&drop target node from Network View right here. It will paste hou.node('path_to_node') expression. 3. To add anything to hou.session module, make a new attribute within hou.session: def foo(s): print(s) hou.session.printer = foo After that, you can use it from any python field inside current Houdini session: hou.session.printer('bar') If you didn't add new attribute, it will output error telling you that hou.session module has no such attribute. Here is example made in Python Shell: >>> hou.session.foo = 123 >>> hou.session.foo 123 >>> hou.session.bar Traceback (most recent call last): File "<console>", line 1, in <module> AttributeError: 'module' object has no attribute 'bar' Edited April 23, 2017 by f1480187 Quote Link to comment Share on other sites More sharing options...
art3mis Posted April 23, 2017 Author Share Posted April 23, 2017 Thanks! Lots to digest. So in terms of editing my original script, do I need to somehow first define parent_node (which equates to NoneType)? Quote Link to comment Share on other sites More sharing options...
f1480187 Posted April 23, 2017 Share Posted April 23, 2017 hou.node('/obj/dopnet1') Yes, that function returns hou.Node instance required by the function body. If the node doesn't exist at this location, it will evaluate to None. 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.