LaidlawFX Posted December 20, 2013 Share Posted December 20, 2013 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 houpath = 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 $VERSIONhou.hscript('set -g VERSION = `evals(substr($HIPNAME,0,evals(strlen($HIPNAME)-4)))`') ---------------------------------------------------------------------- Thanks -Ben Quote Link to comment Share on other sites More sharing options...
koen Posted December 20, 2013 Share Posted December 20, 2013 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 Quote Link to comment Share on other sites More sharing options...
LaidlawFX Posted December 20, 2013 Author Share Posted December 20, 2013 Thanks! Unfortunately I will have to check tomorrow(need houdini for android today, lol), but does it work when multiple houdini sessions are open? I don't think it should conflict because of when it is run, but never used os.environ before. Quote Link to comment Share on other sites More sharing options...
LaidlawFX Posted February 6, 2015 Author Share Posted February 6, 2015 Funny I self loop to this. But found out for os.environ[HIP] can possibly evaluate differently than hou.hscriptExpression('$HIP') yeah random chance! Quote Link to comment Share on other sites More sharing options...
ayidi Posted February 6, 2015 Share Posted February 6, 2015 I recommend using: hou.getenv('VAR') hou.putenv('VAR', 'value') Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.