nemsi Posted March 22, 2019 Share Posted March 22, 2019 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. Quote Link to comment Share on other sites More sharing options...
ikoon Posted March 22, 2019 Share Posted March 22, 2019 (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 March 22, 2019 by ikoon EDIT: btw I am on Windows 10 Quote Link to comment Share on other sites More sharing options...
nemsi Posted March 22, 2019 Author Share Posted March 22, 2019 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! Quote Link to comment Share on other sites More sharing options...
ikoon Posted March 22, 2019 Share Posted March 22, 2019 (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 March 22, 2019 by ikoon Quote Link to comment Share on other sites More sharing options...
nemsi Posted March 22, 2019 Author Share Posted March 22, 2019 Ikoon, you rock guy!!!! Thank you very much! 1 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.