Assign user parameter values to variables

   817   1   2
User Avatar
Member
6 posts
Joined: Nov. 2016
Offline
Hey guys,
Super new to Houdini Python scripting and I've come across a bit of a roadblock.
I'm trying to build an asset to find named textures in a folder to automatically build materials with one click.

What I've got so far works great. I have a button parameter on the HDA which runs the code in the PythonModule, with the following callback script:
kwargs['node'].hdaModule().onButtonPress(kwargs['node'], kwargs['parm'])
I'm using regular expressions to parse the file names and find the correct textures. I want to add exposed parameters on the HDA so that the user can change what string regex uses for matching if needed (i.e. ‘albedo’ vs ‘diffuse’), and other settings (i.e. whether to load in certain textures or not, what level of detail to use if present)

I've managed to read in the parameter values using hou.pwd().evalParm(). However, it seems as if the changes to the parameters are only read in when I'm applying the changes from the Type Properties panel. I can't seem to be able to assign parameter values to existing variables with a button press. This is what I'd ideally like to accomplish:

regex_albedo = "Albedo"
regex_bump = "Bump"

def onButtonPress(me, parm):
  
    extractInfo()
    updateSettings()

def updateSettings()
    regex_albedo = hou.pwd().evalParm("regex_albedo")

def extractInfo():
   [REGEX MATCHING CODE]

I want the user to be able to click on the Create Material button on my HDA and for the script to parse the current parameter values, THEN execute the code to actually do regex matching and everything else that's supposed to happen. Ideally, if the parameters are empty, the script should fallback to default ‘hardcoded’ values.

Can someone enlighten me?


Thanks a bunch!!
User Avatar
Member
191 posts
Joined: Oct. 2018
Offline
The regex_albedo in your updateSettings module doesn't update the regex_albedo variable anywhere else. I think you'd probably have to return the values from the updateSettings module so you can read them into the onButtonPress module.

def onButtonPress():
    albedoString = "albedo"
    settings = updateSettings()
    if settings[0] != "" : albedoString = settings[0]
    print albedoString
    
def updateSettings():
    albedoString = hou.node('.').parm("input").eval()
    return [albedoString]
Edited by krueger - Feb. 14, 2019 17:09:44
  • Quick Links