(novice) help with Python script

   1287   1   1
User Avatar
Member
350 posts
Joined: June 2016
Offline
Using the following in a Python script node to globally enable OpenCl in my scene

n = hou.pwd()

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/sim'), 1);



but get the following error
Attribute error: ‘module’ object has no attribute ‘set_opencl’
User Avatar
Staff
4443 posts
Joined: July 2005
Offline
I assume you entered the code for that function directly into a Python Shell window? If so, that function is not defined in the hou.session module, it is defined as a global in the context of that python shell. So you should be able to run:

set_opencl(hou.node('/obj/sim'), 1)

But I presume you actually want this function defined in the hou.session module so that it gets saved to the hip file and is available the next time you load this hip file. To do this, go to Windows -> Python Source Editor. Make sure the “Source File” is set to “hou.session module”, and enter your function in that window. Then you'll be able to run:

hou.session.set_opencl(hou.node('/obj/sim'), 1)
  • Quick Links