{"id":602,"date":"2011-10-24T10:18:48","date_gmt":"2011-10-24T10:18:48","guid":{"rendered":"http:\/\/www.kurianos.com\/wordpress\/?p=602"},"modified":"2011-10-24T10:24:22","modified_gmt":"2011-10-24T10:24:22","slug":"initialize-houdini-and-maya-via-cmd","status":"publish","type":"post","link":"https:\/\/www.kurianos.com\/wordpress\/?p=602","title":{"rendered":"Initialize houdini and maya via CMD"},"content":{"rendered":"<p>Hi All,<\/p>\n<p>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 \ud83d\ude42<\/p>\n<p>So here is the Houdini Version<\/p>\n<p>[Python]<\/p>\n<p>import hou<br \/>\nimport traceback<br \/>\nfrom optparse import OptionParser as optparse<\/p>\n<p>def houdini_query(filename, node_name):<\/p>\n<p>\tif filename:<br \/>\n\t\ttry:<br \/>\n\t\t\thou.hipFile.load(filename)<br \/>\n\t\t\tgeo_node = hou.node(&#8220;\/obj\/geo1\/&#8221;)<br \/>\n\t\t\tgeo_node.createNode(node_name)<br \/>\n\t\t\tprint &#8220;Trying to create %s in %s &#8221; % (node_name, filename)<br \/>\n\t\t\thou.hipFile.save()<br \/>\n\t\t\tprint &#8220;%s created and %s saved !&#8221; % (node_name, filename)<br \/>\n\t\texcept:<br \/>\n\t\t\tprint traceback.print_exc()<\/p>\n<p>def main():<br \/>\n\tusage = &#8220;usage: houdini_opt.py [options] arg1 arg2&#8221;<br \/>\n\tparser = optparse(description = &#8220;Test OPT &#8220;, prog = &#8220;houdiniCreateNode&#8221;, usage = usage, version = &#8220;Version 0.0.1&#8221;)<br \/>\n\tparser.add_option(&#8220;-f&#8221;, &#8220;&#8211;file&#8221;, action = &#8220;store&#8221;, type = &#8220;string&#8221;,\thelp = &#8220;File to open&#8221;)<br \/>\n\tparser.add_option(&#8220;-n&#8221;, &#8220;&#8211;node&#8221;, action = &#8220;store&#8221;, type = &#8220;string&#8221;, \thelp = &#8220;Node To Add&#8221;)<\/p>\n<p>\t(options,  args) =  parser.parse_args()<\/p>\n<p>\tfilename = options.file<br \/>\n\tnode_name = options.node<\/p>\n<p>\tif not filename or not node_name:<br \/>\n\t\tparser.print_help()<br \/>\n\t\tparser.error (&#8220;Insufficient arguments.&#8221;)<\/p>\n<p>\thoudini_query(filename, node_name)<\/p>\n<p>if __name__ == &#8220;__main__&#8221;:<\/p>\n<p>\tmain()<\/p>\n<p>[\/Python]<\/p>\n<p>And the usage is :<\/p>\n<p>[Python]<\/p>\n<p>hython ~\/python_scripts\/houdini_opt.py -f &#8220;\/tmp\/test.hip&#8221; -n &#8220;box&#8221;<\/p>\n<p>[\/Python]<\/p>\n<p>Maya\u00a0 standalone Initialize<\/p>\n<p>[Python]<\/p>\n<p>import maya.standalone<br \/>\nimport maya.cmds as cmds<br \/>\nfrom optparse import OptionParser as optparse<\/p>\n<p>def maya_query(filename, node_name):<\/p>\n<p>\tif filename:<br \/>\n\t\tinit_maya()<\/p>\n<p>\t\tfile_open = cmds.file(filename, o = True, f = True)<\/p>\n<p>\t\tset_all_sel = cmds.select(all=True)<br \/>\n\t\tget_sel = cmds.ls(sl=True)<br \/>\n\t\tfor each in get_sel:<br \/>\n\t\t\tif each.find(node_name) != -1:<br \/>\n\t\t\t\tprint &#8220;Found %s in %s &#8221; % (node_name, filename)<br \/>\n\t\t\t\tbreak<\/p>\n<p>def init_maya():<br \/>\n\ttry:<br \/>\n\t\tmaya.standalone.initialize( name=&#8217;python&#8217; )<br \/>\n\texcept:<br \/>\n\t\tsys.stderr.write( &#8220;Failed in initialize standalone application&#8221; )<br \/>\n\t\traise<\/p>\n<p>def main():<br \/>\n\tusage = &#8220;usage: maya_opt.py [options] arg1 arg2&#8221;<br \/>\n\tparser = optparse(description = &#8220;Test OPT &#8220;, prog = &#8220;mayNodeCheck&#8221;, usage = usage, version = &#8220;Version 0.0.1&#8221;)<br \/>\n\tparser.add_option(&#8220;-f&#8221;, &#8220;&#8211;file&#8221;, action = &#8220;store&#8221;, type = &#8220;string&#8221;,\thelp = &#8220;File to open&#8221;)<br \/>\n\tparser.add_option(&#8220;-n&#8221;, &#8220;&#8211;node&#8221;, action = &#8220;store&#8221;, type = &#8220;string&#8221;, \thelp = &#8220;Node To Find&#8221;)<\/p>\n<p>\t(options,  args) =  parser.parse_args()<\/p>\n<p>\tfilename = options.file<br \/>\n\tnode_name = options.node<\/p>\n<p>\tif not filename or not node_name:<br \/>\n\t\tparser.print_help()<br \/>\n\t\tparser.error (&#8220;Insufficient arguments.&#8221;)<\/p>\n<p>\tmaya_query(filename, node_name)<\/p>\n<p>if __name__ == &#8220;__main__&#8221;:<\/p>\n<p>\tmain()<\/p>\n<p>[\/Python]<\/p>\n<p>And the usage is :<\/p>\n<p>[Python]<\/p>\n<p>mayapy ~\/python_scripts\/maya_opt.py -f &#8220;\/tmp\/test.ma&#8221; -n &#8220;hello&#8221;<\/p>\n<p>[\/Python]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 \ud83d\ude42 So here is the Houdini Version [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[13,15,11,14],"tags":[],"class_list":["post-602","post","type-post","status-publish","format-standard","hentry","category-houdini","category-linux","category-maya","category-python"],"_links":{"self":[{"href":"https:\/\/www.kurianos.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/602","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kurianos.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kurianos.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kurianos.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kurianos.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=602"}],"version-history":[{"count":6,"href":"https:\/\/www.kurianos.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/602\/revisions"}],"predecessor-version":[{"id":606,"href":"https:\/\/www.kurianos.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/602\/revisions\/606"}],"wp:attachment":[{"href":"https:\/\/www.kurianos.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=602"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kurianos.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=602"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kurianos.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=602"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}