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

[Python]

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()

[/Python]

And the usage is :

[Python]

hython ~/python_scripts/houdini_opt.py -f “/tmp/test.hip” -n “box”

[/Python]

Maya  standalone Initialize

[Python]

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()

[/Python]

And the usage is :

[Python]

mayapy ~/python_scripts/maya_opt.py -f “/tmp/test.ma” -n “hello”

[/Python]

  1. No comments yet.

  1. No trackbacks yet.

Error thrown

Undefined constant "cs_print_smilies"