Jump to content
mrWolf

hbatch executing python script and ui error

Recommended Posts

I'm using a small python script to open a hip file, "do something" , save, and press the button "render" on the proprietary node that sends the job on the farm.

Of course this all happens without ui, so my script errors out cause somewhere there is some python code that uses  hou.ui.setStatusMessage, and I guess hbatch doesn't load the ui module.

 

This is the error I get:

 

hou.ui.setStatusMessage( "Creating the render data", hou.severityType.Message)
AttributeError: 'module' object has no attribute 'ui'
 
This the script:
 
 
import hou

hou.hipFile.load("myfile.hip",True)

<change parameters and do interesting stuff>

print ("submitting job on the farm\n")
farmrender=hou.node("/out/farm_render")
farmrender.parm("FarmRender").pressButton()

print ("done\n")
hou.exit()

and this is the error message

...
    hou.ui.setStatusMessage( "Creating the render data", hou.severityType.Message)
AttributeError: 'module' object has no attribute 'ui'

I already tried to execute the actual code contained in the button, but I get the same exact error.

 

Is there any way to suppress any call to hou.ui when a script is executed via hbatch ?

 

Share this post


Link to post
Share on other sites

You need to put the hou.ui call inside an if statement that checks if the ui is available:

if hou.isUIAvailable():
    hou.ui.setStatusMessage(.....)

Share this post


Link to post
Share on other sites

 

You need to put the hou.ui call inside an if statement that checks if the ui is available:

if hou.isUIAvailable():
    hou.ui.setStatusMessage(.....)

thank you for your reply Graham,

unfortunately I cannot access the content of whatever script executes the call to hou.ui cause it's a pipeline script.

I was wondering if there is any way to catch any call to ui, and ignore it.

I tried  with a try: except: structure but it doesn't work.

Share this post


Link to post
Share on other sites

If you can't have someone change the bad code you could probably just monkeypatch hou in your script and generate a dummy hou.ui.displayMessage function that does nothing and won't error.

Share this post


Link to post
Share on other sites

If you can't have someone change the bad code you could probably just monkeypatch hou in your script and generate a dummy hou.ui.displayMessage function that does nothing and won't error.

ehi Graham ! this seems very interesting !

I am not the most expert python coder out there at all, I am trying to figure out the syntax for this to work but I am struggling a bit with the syntax :)

 

I tried this code:

import hou

def setStatusMessage(message, severity=hou.severityType.Message):
    print (message)

hou.ui.setStatusMessage=setStatusMessage

But I get this message:

 

 

hbatch Version 13.0.447 (Compiled on 06/17/14)
Traceback (most recent call last):
  File "actor001.py", line 18, in <module>
    hou.ui.setStatusMessage=setStatusMessage
AttributeError: 'module' object has no attribute 'ui'
 
Can you give me a hint on what I am doing wrong ?

Share this post


Link to post
Share on other sites

You can probably do something like this to fake it:

def setStatusMessage(message, severity=hou.severityType.Message):
    print (message)
 
hou.ui = lambda: None
setattr(hou.ui, "setStatusMessage", setStatusMessage)

Share this post


Link to post
Share on other sites

 

You can probably do something like this to fake it:

def setStatusMessage(message, severity=hou.severityType.Message):
    print (message)
 
hou.ui = lambda: None
setattr(hou.ui, "setStatusMessage", setStatusMessage)

Graham, it works great.

Thank you a lot man

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×