Edit HDA in Unreal with Python

   2848   5   1
User Avatar
Member
37 posts
Joined: Dec. 2016
Offline
Hey everyone!

I'm working on a level building tool for unreal engine where you create a wall from a spline and can then boolean in doors and windows (or whatever). I'm using python from within a script on my HDA and using a callback script on a button to run the code.
Here's my code:

import hou

boolList = []
scene = hou.node('/obj/wall_generator/')

def main(kwargs):
    scene.allowEditingOfContents()
    node = kwargs['node']
    
    def createNodes():
        wallBase = hou.node('/obj/wall_generator/wallBase')
        frameMerge = hou.node('/obj/wall_generator/frame_merge')
        blast = hou.node('/obj/wall_generator/wallSideDel')
    
        bool = scene.createNode('frame_bool_setup')
        
        boolList.append(bool)
        print boolList
        
        if len(boolList) == 1:
            boolPrev = boolList[0]
            bool.setInput(0, wallBase)
        else:
            boolPrev = boolList[-2]
            bool.setInput(0, boolPrev)
        
        print boolPrev
        blast.setInput(0, bool, 0)
        frameMerge.setNextInput(bool, 1)    
        
    def createUI():
        i = int(hou.getenv('i'))
        
        ui = scene.parmTemplateGroup()
        folder = ui.findFolder('Boolean Controls')
        testParm = hou.StringParmTemplate('frame{}'.format(i), 'Frame{}'.format(i), 1,
        naming_scheme=hou.parmNamingScheme.Base1, string_type=hou.stringParmType.NodeReference)
        ui.appendToFolder(folder, testParm)
        scene.type().definition().setParmTemplateGroup(ui)
        
        i += 1
        hou.putenv('i', str(i))
    
    createNodes()
    createUI()
    
    scene.type().definition().updateFromNode(scene)
    scene.matchCurrentDefinition()
    
def deleteNodes(kwargs):
    node = kwargs['node']
    num = len(boolList)
    boolLast = hou.node('/obj/wall_generator/frame_bool_setup{}'.format(num))
    boolLast.destroy()

So far all my code works within Houdini (apart from that I need to re-work my code so that instead of boolList I use an environment variable because defining the node definition resets the list variable - I know this doesn't work at the moment). A lot of this is temp right now as I'm just diving into the Houdini Python API and learning on my feet (and am still learning more advanced Python).

I tried throwing my HDA into Unreal and I couldn't get anything to update. It wouldn't create the new nodes or update the parameter interface. Is there something that I need to do to get this to work in Unreal or is it not possible at this point in time…?

Thanks so much!

Ryan
User Avatar
Member
45 posts
Joined: Feb. 2014
Offline
Are you assuming Houdini Engine is placing your asset at “/obj/wall_generator”? Try using kwargs to get the node, instead of hard coding the path.
User Avatar
Member
37 posts
Joined: Dec. 2016
Offline
Ah that makes sense! Thank you! Would I also need to use kwargs to reference the nodes inside my network or just the main hda node? I need to learn more about kwargs as I don't fully understand what it's doing/how to use it yet
Edited by canonball900 - Oct. 24, 2018 09:46:42
User Avatar
Member
45 posts
Joined: Feb. 2014
Offline
kwargs is a dictionary implicitly(Houdini adds its to the python environment before it calls your code) passed into virtually every python callback(things like parm callbacks, onInstall, onLastDeleted but not the HDA's python module as that's not a callback). It gives you the context you need to work within the scene, so you'll have things like the node the callback is called for or the previous and current parm values. I usually print it out first to see what I have to work with.

In order to reference the nodes inside your HDA you would use relative paths.
HDA = kwargs['node']
frameMerge = node.node("frameMerge")
nodeInFrameMerge = node.node("frameMerge/nodeInFrameMerge")
#or
nodeInFrameMerge = frameMerge.node("nodeInFrameMerge")
User Avatar
Member
37 posts
Joined: Dec. 2016
Offline
Okay cool, that makes more sense now. Thanks so much for your help!
User Avatar
Member
37 posts
Joined: Dec. 2016
Offline
How would you reference a node in an above network using the Kwargs dictionary?
Edited by canonball900 - Nov. 1, 2018 00:29:46
  • Quick Links