Initialize houdini and maya via CMD
Hi All,
One of my friend asked me to show him how we can initialize houdini and maya via cmd mode and how he can parse some argument using optparse. So made some quick python scripts for him , then i thought oke lets share with others also ๐
So here is the Houdini Version
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
import hou import traceback from optparse import OptionParser as optparse def houdini_query(filename, node_name): if filename: try: hou.hipFile.load(filename) geo_node = hou.node("/obj/geo1/") geo_node.createNode(node_name) print "Trying to create %s in %s " % (node_name, filename) hou.hipFile.save() print "%s created and %s saved !" % (node_name, filename) except: print traceback.print_exc() def main(): usage = "usage: houdini_opt.py [options] arg1 arg2" parser = optparse(description = "Test OPT ", prog = "houdiniCreateNode", usage = usage, version = "Version 0.0.1") parser.add_option("-f", "--file", action = "store", type = "string", help = "File to open") parser.add_option("-n", "--node", action = "store", type = "string", help = "Node To Add") (options, args) = parser.parse_args() filename = options.file node_name = options.node if not filename or not node_name: parser.print_help() parser.error ("Insufficient arguments.") houdini_query(filename, node_name) if __name__ == "__main__": main() |
And the usage is :
1 |
hython ~/python_scripts/houdini_opt.py -f "/tmp/test.hip" -n "box" |
Mayaย standalone Initialize
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
import maya.standalone import maya.cmds as cmds from optparse import OptionParser as optparse def maya_query(filename, node_name): if filename: init_maya() file_open = cmds.file(filename, o = True, f = True) set_all_sel = cmds.select(all=True) get_sel = cmds.ls(sl=True) for each in get_sel: if each.find(node_name) != -1: print "Found %s in %s " % (node_name, filename) break def init_maya(): try: maya.standalone.initialize( name='python' ) except: sys.stderr.write( "Failed in initialize standalone application" ) raise def main(): usage = "usage: maya_opt.py [options] arg1 arg2" parser = optparse(description = "Test OPT ", prog = "mayNodeCheck", usage = usage, version = "Version 0.0.1") parser.add_option("-f", "--file", action = "store", type = "string", help = "File to open") parser.add_option("-n", "--node", action = "store", type = "string", help = "Node To Find") (options, args) = parser.parse_args() filename = options.file node_name = options.node if not filename or not node_name: parser.print_help() parser.error ("Insufficient arguments.") maya_query(filename, node_name) if __name__ == "__main__": main() |
And the usage is :
1 |
mayapy ~/python_scripts/maya_opt.py -f "/tmp/test.ma" -n "hello" |