Jump to content
nemsi

help with scripting

Recommended Posts

Hi guys,

i would like to make a simple script that add/creat a hbatch *.cmd file with this inside :

mread $JOB/render/$HIPNAME.hip
Redshift_setGPU -s 11
Redshift_setLogLevel -L 5
render /out/Redshift_ROP1

Then it would automatize my process.

Thank you for your help.

 

Share this post


Link to post
Share on other sites
Posted (edited)

Hi, do you want to use python to create the .cmd file? If it is so, than this might work for you:

import os

path_hip     = hou.expandString('$HIP')
path_scripts = path_hip + '/scripts/'

if not os.path.exists(path_scripts):
    os.makedirs(path_scripts)

script   = 'some text'
path_cmd = path_scripts + 'filename.cmd'
file_cmd = open( path_cmd, "w")
file_cmd.write(script)

I use similar script, but I am no python guru unfortunately, so there may be a better way to do it.

Edited by ikoon
EDIT: btw I am on Windows 10

Share this post


Link to post
Share on other sites

Thank you Ikoon!!

the main is there. Do you know how to :

- get a "retur to the next line" for my script variable?

- translate a $JOB to its value when writing in the file (again for script variable)

Thank you for your valuable help!

 

Share this post


Link to post
Share on other sites
Posted (edited)

Hi,
as regards evaluating the $JOB as a string, this should work

hou.expandString('$JOB')


For multiline string in python, you can see few methods here (scroll down to answers)
https://stackoverflow.com/questions/10660435/pythonic-way-to-create-a-long-multi-line-string

I use \n and multiple += when I am building the script, for me it is most readable:

        variable    = 'some_filename.hip'
  
        script_rop  = '# commented first line\n'
        script_rop += 'hou.hipFile.load("' + variable + '")\n'
        script_rop += '# another line\n'
        script_rop += '# last line, without backslash n'

 

Edited by ikoon

Share this post


Link to post
Share on other sites

Ikoon, you rock guy!!!!

Thank you very much! ;)

 

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×