Jump to content

help with scripting


nemsi

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.

 

Link to comment
Share on other sites

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
Link to comment
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!

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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