Jump to content

456.py Setting variables with Python


LaidlawFX

Recommended Posts

I'm trying to use python to parse $HIP and define variables in houdini. Each Variable Project_Code, Sequence, Shot, and Task can be indeterminant length, so I only really know by the / what each value means. Since I can only use set -g in hscript how would I set these variables?

 

For instance version is based on hipname, but I need to do somethign like:

hou.hscript('set -g PROJECTCODE' = `pythonexprs("hipSplit[1]")` )

Which doesn't work in context.

 

$HIP = P:\projects\Project_Code\Sequence\Shot\Task\

--------------------------------------------------------------------

import hou

path = hou.hscriptExpression('$HIP')
hipSplit = path.rsplit('/')[1:]
## hipSplit example ['projects', 'Project_Code', 'Sequence', 'Shot', 'Task']

 

## Sets houdini variable $PROJECTCODE
## PROJECTCODE = hipSplit[1]

## hipSplit[1] is Project_Code

 

etc...

 

## Sets houdini variable $VERSION
hou.hscript('set -g VERSION = `evals(substr($HIPNAME,0,evals(strlen($HIPNAME)-4)))`')

 

----------------------------------------------------------------------

 

Thanks

-Ben

 

 

 

 

Link to comment
Share on other sites

Can you just use os.environ?

 

>>> import os

>>> hip = '/projects/Project_Code/Sequence/Shot/Task/blah.hip'
>>> tokens = hip.split('/')
>>> os.environ['PROJECT'] = tokens[2]
>>> hou.expandString('$PROJECT')

'Project_Code'

 

It also evaluates properly as a global variable for me.

 

Cheers,

koen

Link to comment
Share on other sites

  • 1 year later...

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