menu script fail to work. please help

   2933   4   1
User Avatar
Member
6 posts
Joined: July 2009
Offline
I am a newbie and am trying the tutorial by Dan Letart, building a HDA with python.

Here is the tutorial.

http://203.208.39.132/search?q=cache:3hlSuBlGGp4J:www.danletarte.com/images/letarte_accumulatorTutorial.doc+letarte_accumulatorTutorial&cd=1&hl=zh-CN&ct=clnk&gl=cn&st_usg=ALhdy2853gPG69dyQPcIN2hJZ0qaKbH9hg [203.208.39.132]

but the menu script for always failed to work. I do not know why.

Here is the menu script according to the tutorial:
echo `strreplace(pythonexprs(“hou.pwd().hdaModule().buildMenu()”), “'”, “\'”)`

it is to be used to output the group list from the input node and display these groups in the parameter box in this HDA.

I really copy the script to the menu script. And I check the python function buildMenu, which is correct.

I am confused. Please help me. Thanks a lot.
User Avatar
Member
130 posts
Joined: April 2009
Offline
Hi,

The problem is caused not by the line you quoted, but by the actual python module. The PDF you used breaks the script across two pages, resulting in incorrect indentation. Here is the corrected code:

“”“##################################################################################################
#
# DEF: buildMenu()
#
# ARGUEMENTS:
# RETURNS: String of null character seperated values
# DESCRIPTION: Provides a method for a dynamically built menu to be echoed back to a
# parameter's menu script.
#
##################################################################################################”“”
def buildMenu():
# This function is called from the hscript menu generation script.
# Import library for checking list length
import shlex
# Set the accumNode for a quick path back to the accumulator node
accumNode = hou.node('.')
pEntity = hou.Node.evalParm(accumNode, “pEntity”)
# There are currently no clean ways to gather geometry group information using strictly python
# Gather the names of the groups through an hscript expression
if pEntity == 1:
groupsList = hou.hscriptExpression(“pointgrouplist(opinputpath(\”.\“, 0))”)
if hou.hscriptExpression(“pointgrouplist(opinputpath(\”.\“, 0))”) == “”:
groupsList = “”
else:
groupsList = hou.hscriptExpression(“primgrouplist(opinputpath(\”.\“, 0))”)
if hou.hscriptExpression(“primgrouplist(opinputpath(\”.\“, 0))”) == “”:
groupsList = “”
names = “”
if groupsList != “”:
# For each group name found, use shlex.split to break them into a list
for names in groupsList:
check = shlex.split(groupsList)
# Find the number of groups in the list by checking its length
numGroups = len(check)
i=0
final = “”
# The menu requires two parameters per line: The label and the value separated by spaces
# This while loop iterates through and formats our list correctly - With label and value equal
while i < numGroups:
final = final + check + “ ” + check + “ ”
i=i+1
# Spit the final string out for the menu generation
try: final
except NameError:
final = “ ”
return final

Cheers,
Greg
User Avatar
Member
130 posts
Joined: April 2009
Offline
Hi again,

Here is the second script (to be appended below the first one in the Python Module), corrected as well:

“”“##################################################################################################
#
# DEF: accumulate()
#
# ARGUEMENTS:
# RETURNS:
# DESCRIPTION: Accumulates user-specified point or primitive geometry groups into a new group
#
#
##################################################################################################”“”
def accumulate():
# Import library for checking list length
import shlex
import __main__
# Set the accumNode for a quick path back to the accumulator node; Likewise for the outGroup node
accumNode = hou.node('..')
outGrpNode = hou.node('../outGrpNode')
# Set the output parameter shortcut
patternParm = hou.parm(“../outGrpNode/pattern”)
pEntity = hou.Node.evalParm(accumNode, “pEntity”)
# Create hasAccumulated to hold the final values. Make it global so it can be appended to
global hasAccumulated
# Reset vars on start frame
pStartFrame = hou.Node.evalParm(accumNode, “pStartFrame”)
if hou.frame() <= pStartFrame:
hasAccumulated =
# SETUP
# Gather the names of the groups through an hscript expression
inGroups = hou.Node.evalParm(accumNode, “pInGroup”)
# If hasAccumulated isn't initialized do so, otherwise leave its value the same
try: hasAccumulated
except NameError:
hasAccumulated =
try: splitGroups
except NameError:
splitGroups =
names = “”
# For each group name found, use shlex.split to break them into a list
for names in inGroups:
splitGroups = shlex.split(inGroups)
# Find the number of groups in the list by checking its length
numGroups = len(splitGroups)
# Set the number of scripts the number of groups requiring calculation
scriptNum = hou.parm('../script1/numscripts')
scriptNum.set(numGroups + 1)
# Set the values of those scripts to the appropriate hscriptExpression
scriptNum = 2
groupNum = 0
# This setup loop actually only needs to run once - at the start of the sim
while scriptNum <= numGroups + 1:
# Set the script language to hscript
scriptLang = hou.parm(“../script1/scriptlang%d” % scriptNum)
scriptLang.set(“hscript”)
# Set the script value to the primitive list per group
scriptValue = hou.parm(“../script1/script%d” % scriptNum)
if pEntity == 1:
scriptValue.set('echo `pointlist(opinputpath(“.”, 0), “%s”)`' % splitGroups)
if hou.hscriptExpression(“pointgrouplist(opinputpath(\”.\“, 0))”) == “”:
print “No point groups found”
break
else:
scriptValue.set('echo `primlist(opinputpath(“.”, 0), “%s”)`' % splitGroups)
if hou.hscriptExpression(“primgrouplist(opinputpath(\”.\“, 0))”) == “”:
print “No prim groups found”
break
scriptNum = scriptNum + 1
groupNum = groupNum + 1
# Reset script number to 2, offsetting for the accumulate() call in the script node
scriptNum = 2
# DO ACCUMULATE
while scriptNum <= numGroups + 1:
scriptValue = hou.parm(“../script1/script%d” % scriptNum)
accumVal = scriptValue.eval()
accumVal = shlex.split(accumVal)
if accumVal not in hasAccumulated:
hasAccumulated.append(accumVal)
scriptNum = scriptNum + 1
# Update the pattern in the output group node
patternParm.set(`hasAccumulated`)
User Avatar
Member
6 posts
Joined: July 2009
Offline
Thanks a lot. I tried and works it out in the end.

Except what you suggested, I made another mistake when modifying the codes by the author.

Here is the corrected code of the buildMenu function:

final =
while i < numGroups:
final += [check,check] // the menu items has to be pair, token and label . but before I modify the codes and just take the token into account.
i = i + 1
try: final
except NameError:
final =
return final


And below is the python menu script:
hou.pwd().hdaModule().buildMenu()

Thank you very much.
User Avatar
Member
6 posts
Joined: July 2009
Offline
But there is another confusion.

Here I am studying the tutorial writen by Dan Letarte( thanks to him) and use the python codes directly. If I write the python functions myself, how could I debug the function and track the execution of the function step by step as the we could in Maya. It is well known that we could debug in the Maya enviroment with Visual Cpp. So how about Python in houdini?

Thanks for your suggestions.
  • Quick Links