custom variables on the fly based from $HIP

   2297   4   0
User Avatar
Member
18 posts
Joined: Oct. 2017
Offline
Hello everyone,

I have made a little script which create correctly named folders and sub-folders.
I have added a line which create an empty hip file (pretty dummy way to do it: Houdini warns me that it's not a correct scene but nicely launch it anyway and complete it).

My problem is that I would like to set some variables on the fly:
Example:

my script is launched in C:/PROJECTS/ and create a folder "MYSHOT", inside there is a sub folder named "3D", inside it there is another subfolder named "WIP" and inside it (finally) there is my hip file "myshot_v001.hip". so basically:
C:/PROJECTS/MYSHOT/3D/WIP/myshot_v001.hip
At the same level of WIP, there is another folder named "CACHE".
and I would like add a variable called CACHE and pointing in that specific folder:
C:/PROJECTS/MYSHOT/3D/CACHE

I know that the command to do it is "set -g CACHE = 'C:/PROJECTS/MYSHOT/3D/CACHE' " and I guess a way to do it is to use the $HIP variable.
I tried to write a script in a 456.py file put in C:\Program Files\Side Effects Software\Houdini 18.####\python27\Scripts

#python
import os
import sys
#houdini
import hou
ROOT = str(hou.expandString('$HIP'))
size = len(ROOT)
BROOT = ROOT[:size-4]
hou.hscript("set -g CACHE = "+BROOT+"CACHE")

I was expecting that the variable would be created at the opening of the hip file, but my first try was a failure.
However it works fine in the shelf

Would someone have any idea how to do it?

Thanks in advance
Edited by balthou1703 - April 12, 2021 02:24:15
User Avatar
Member
106 posts
Joined: June 2011
Offline
Hi there!

I just did a quick test and it seems to work as expected. The variable got created on file open. How are you opening your hip files ?
Is it through your script ?

-J
User Avatar
Member
18 posts
Joined: Oct. 2017
Offline
I open my hip file simply by double-clicking on it :/

Maybe my 456.py is in the wrong location?

I put it in :

C:\Program Files\Side Effects Software\Houdini 18.5.408\python27\Scripts

Inside, there is just:

#python
import os
import sys
#houdini
import hou

ROOT = str(hou.expandString('$HIP'))
size = len(ROOT)
BROOT = ROOT[:size-6]
hou.hscript("set -g CACHE = "+BROOT+"CACHE")

my hip file is in this location:

C:\MYPROJECT\3D\3DWORK
User Avatar
Member
106 posts
Joined: June 2011
Offline
Ah! I see. Could you please put your 456.py script under "C:\Program Files\Side Effects Software\Houdini 18.#.###\houdini\scripts" directory and see if it works ?

-J
Edited by jjayakumar - April 13, 2021 07:01:59
User Avatar
Member
18 posts
Joined: Oct. 2017
Offline
I works, thank you!
  • Quick Links