intro to python in H11 ()
https://www.youtube.com/watch?v=GubmnSEyKS8
#when should we use python ?...when you cant do it in Houdini with HScript or nodes
# comments prefixed with a hash (#) can be appended to the end of a line of code)
ie
2+2 # use python like a calculator
will return 4
#baby steps : drag a node into the python interpreter/window
>>> hou.node('/obj/geo1')
(shelf tools and pane TABS can also be dragged into Houdini)
'dotting in'
>>> n = hou.node('/obj/geo1') # assigning to 'n'
>>> n. gives us the operators for n
>>> n
# assign the object a variable to work with it
>>> n.name() # call its name
'geo1'
# Children at SOP level
# Looping through the children and print the name
# parms
help(n.parm)
# check out the HOM (Houdini Object Model) section of the Houdini help files
ie HOM cookbook and tips and tricks
# Build a function
wrap up a snipped of code so we can call it on a whim
# note this recursive (the definition of recursion is recursion)
def childrenOfNode(node):
result = [] # a list in python
for c in node.children():
result append (c)
result += childrenOfNode(c) # this is where the recursion happens - we are calling the very function # we have defined
return result
# recall indentation is key in python
# saving to a sessional window allows custom functions to be called with the hou.session prefix
# add your code to the shelf as a shelf tool
right click somewhere on the shelf - choose new tool
in the scripting window - add your python code ie
print 'hello world'
hou.ui.displayMessage('hello')
#CTRL-TAB will do your auto-complete for you
# set the pos of a node in a Network editor pane
n = hou.node('/obj/box1')
n.setPosition([.5, .5])
# to see more look in HFS/scripts/python
# adding python into object parameters
ie in HScript - $F/10
in python: (be sure that Houdini knows it is a python expression
and not HScript - Right Click - change expression language to python)
hou.frame()/10
the parm window changes to pink to show the language is not the default language
if the defualt is set to Python then the HScript expression would be in pink
note in parm windows - the hou prefix can be dropped
time() = $T
lvar("PT") = $PT
ie point SOP
lvar("TX") is equivalent to $TX
pwd().curPoint().position() is equivalent to
lvar("PT")
ALT-E gives us a little editor to help write our python
in this context - if there is more than one line the code is treated as a function
(with breaks shown in the parm window)
point = pwd().curPoint()
if point.number() ==0;
return 2
return point.position()
kwargs - used through-out houdini
describes a bunch of variables associated with the shelf tool
ie whehere or not you have ALT-clicked the tool or SHIFT-clicked the tool etc
whether or not he tool was invoked from the viewport or not
use sys.exit() to exit from a python shelf tool
shelf tools can be bound to Hot Keys - and they can be invisible form the shelves or viewport pane
in a font SOP (as a python expression):
"Frame $F %s" % int(frame())
will give you the frame number evaluated from the python expression
"%02d:%03d, 1f" % (time()/60, time() % 60)
with string parameters - add a keyframe - then change to python to edit it
you cant add a python expression as a string expression until you have a true keyframe
hou.expressionGlobals()['foo'] = foo
now foo can be called from a python expression
so if you have a lib of your own expressions
you can inject them in to expressions
make a timecode HDA's
make it a HDA - Shift-C
from the subnet create a DA
'ch' can be used just as we would in HScript
use CTRL-g to jump to a specific line in a python scripting window
code in an asset is more global - it lives with the asset
python in a shelf tool may only live on a specific desktop and python in a session may only live in that
session
https://www.youtube.com/watch?v=5lVpCmadM-Y
Boolean operators ordered by ascending priority:
Operation | Result | Notes |
---|---|---|
x or y | if x is false, then y, else x | (1) |
x and y | if x is false, then x, else y | (2) |
not x | if x is false, then True , else False | (3) |
Notes:
- This is a short-circuit operator, so it only evaluates the second argument if the first one is
False
. - This is a short-circuit operator, so it only evaluates the second argument if the first one is
True
. not
has a lower priority than non-Boolean operators, sonot a == b
is interpreted asnot (a == b)
, anda == not b
is a syntax error.
it has been said that unambiguous code is good, so I imagine writing 'not (a==b)' is preferable to 'not a == b'
inequalities
use of <> is obsolete but backward compatible to the standard !=
No comments:
Post a Comment