Jump to content

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


ah-fx

Recommended Posts

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.

 

Link to comment
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

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...