Jump to content
ah-fx

Use Python or Hscript to give me the session's context (mantra, hython, houdini)

Recommended Posts

Hey everyone,

Is it possible to use python or hscript to tell me which context houdini is running in. For example, mantra, hython, or interactive / native houdini?

Adam

Share this post


Link to post
Share on other sites
4 hours ago, ah-fx said:

Hey everyone,

Is it possible to use python or hscript to tell me which context houdini is running in. For example, mantra, hython, or interactive / native houdini?

Adam

Houdini and hython/hbatch/engine is simple:

hou.isUIAvailable()  // spots the difference

For python in Mantra filtering, check if you can import mantra module, and handle exception properly

is_this_mantra_filter = False
try: 
  import mantra
  is_this_mantra_filter = True
except:
  pass
  

For python running inside HDA instanced by Mantra afaik it is less obvious. I can deduce it from a details like content of sys.argv. From what I see in Mantra case it's empty:

import sys
if not sys.argv[0]:
  # this seems to be Engine running inside Mantra
  pass 

highly unreliable.

 

hth,

skk.

 

Share this post


Link to post
Share on other sites
On 1/12/2018 at 7:45 PM, symek said:

Houdini and hython/hbatch/engine is simple:


hou.isUIAvailable()  // spots the difference

For python in Mantra filtering, check if you can import mantra module, and handle exception properly


is_this_mantra_filter = False
try: 
  import mantra
  is_this_mantra_filter = True
except:
  pass
  

For python running inside HDA instanced by Mantra afaik it is less obvious. I can deduce it from a details like content of sys.argv. From what I see in Mantra case it's empty:


import sys
if not sys.argv[0]:
  # this seems to be Engine running inside Mantra
  pass 

highly unreliable.

 

hth,

skk.

 

 

This is perfect, thanks symek

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

×