Jump to content

Session module > AttributeError: 'NoneType' object has no attribute foo


Recommended Posts

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'

 

 

 

Link to comment
Share on other sites

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 by f1480187
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...