Jump to content

[novice] getting python scripts working


Recommended Posts

In my attempt at solving a pull focus issue I sourced the following script here on odforce.

 

I then paste into a Python Script digital asset node. But how to get it to run/compile? Should it run automatically?

#!/usr/bin/env hython
_version = 0.11
'''
Inital Author: "SYmek" from od[force] community.
Edited by: Farsheed Ashouri
Thanks to everyone who have helped.
For more information: http://forums.odforce.net/index.php?/topic/9725-creating-a-new-python-script-for-automating-camera-dof-setup-solved/
'''
import hou
def computeFocus():
    if hou.selectedNodes():
        for node in hou.selectedNodes():
#            print node.path()
            if node.type().name() == "cam":
                camera = node
#               else: target = node
                target = hou.node("/obj").createNode("null","DOF_Controler")
                theExp='vlength(vtorigin("%s", "%s"))'
        
                try:
                    camera.parm("focus").setExpression(theExp % (camera.path(),target.path()))
#                   cT = camera.worldTransform().extractTranslates()
#                   tT = target.worldTransform().extractTranslates()
#                   try: camera.parm("focus").set(cT.distanceTo(tT))
                    print "Done."
                except: print "Did you actually select any camera?"     

            else:
                print "Please select a camera and a target."
#if __name__ == "__main__":
computeFocus()

 

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