AutoCorrect File Path

   2222   5   1
User Avatar
Member
209 posts
Joined: Jan. 2013
Offline
Hi!

Is it possible in a Houdini to make sure that predefined variables in the environment are automatically replaced when they see a specific template in the path to some file on the disk?

For example, there is an external environment variable TEST=/home/lib, I start writing or indicating the path to the geometry in the file node /home/lib/geo/pig.bgeo.sc and knowing well that there is such a variable that will automatically change this part to variable $TEST/geo/pig.bgeo.sc

This situation may look artificial, but in fact people very often use absolute paths to files on disk, forgetting that some people can work in another operating system where the direction of slashes and where the source file lies plays a role.
If you give any clue how this can be done technically, I will be glad to help.
User Avatar
Member
191 posts
Joined: Oct. 2018
Offline
Someone may know a better way, but the thing I can think of is a script that's run during an event. It could be on file save or load and iterate over all the node types you want, or on something like on node loaded which would happen on file load or copy/paste.

Something like this could be used for file nodes on loaded:
node = kwargs["node"]

job = hou.getenv("JOB")
file = node.evalParm("file")

if job.lower() in file.lower() :
    newFile = file.replace(job, "$JOB")

node.parm("file").set(newFile)

Some more info on node python events:
http://www.sidefx.com/docs/houdini/hom/locations.html#event-types [www.sidefx.com]
User Avatar
Member
209 posts
Joined: Jan. 2013
Offline
Thanks for the reply, mkps. I will try to implement one of these.
User Avatar
Member
27 posts
Joined: Feb. 2017
Offline
https://www.sidefx.com/docs/houdini/hom/hou/text#collapseCommonVars [www.sidefx.com]
English is not my native language, sorry in advance for any misunderstanding
User Avatar
Member
387 posts
Joined: Nov. 2008
Offline
Or with hscript:
opchange -p / $HIP \$HIP

This will change any (/ starting from root) occurence of expanded $HIP into unexpanded (\$HIP) variable in any parameter.
User Avatar
Member
209 posts
Joined: Jan. 2013
Offline
pezetko
pezetko

Awesome! This is just what you need. Thank you very much, pezetko!
  • Quick Links