hyperforce Posted October 7, 2012 Share Posted October 7, 2012 (edited) Ok so i'm pretty new to python scripting. I have created a button on my HDA that should, when pressed: - Cause a file node to save all geometry into a bgeo file. - Create a new digital asset of the type "importFile" OR if this DHA type already exists in the scene, it just needs to store its name. - It then needs to tell the target "importFile" HDA to import the .bgeo file. - And finally deselect the original HDA and purge its cache from memory. I have this script running inside my digital assets : def onTransfer(node):c = hou.pwd()p = hou.parent()i = p.createNode("importFile")#Triggers a callback script that saves the current nodes output to a bgeo file.c.node(".").parm("save").pressButton()#Triggers a callback script that loads saved bdeo file on the target node.i.node(".").parm("load").pressButton()i.moveToGoodPosition()#Triggers a callback script that deselects and unloads this node from memory though hscript.c.node(".").parm("unloadButton").pressButton()i.node(".").setCurrent(i,"on")[/CODE]My first question: However I get the following error for this last line:[CODE]Error running callback:Traceback (most recent call last):File "<stdin>", line 1, in <module>File "opdef:/Sop/exportFile?PythonModule", line 21, in onTransferFile "C:/PROGRA~1/SIDEEF~1/HOUDIN~1.33/houdini/python2.6libs\hou.py", line 5132, in setCurrentreturn _hou.Node_setCurrent(*args, **kwargs)TypeError: in method 'Node_setCurrent', argument 2 of type 'bool'[/CODE]According to the Help I need to use:[color=#000000][font=monospace][b]hou.Node setSelected[/b][/font][/color][color=#000000][font=monospace][b]([/b][/font][/color][color=#AA22FF][font=monospace][b][i]self[/i][/b][/font][/color][color=#000000][font=monospace][b],[/b][/font][/color][color=#000000][font=monospace][b] [/b][/font][/color][color=#000000][font=monospace][b]on[/b][/font][/color][color=#000000][font=monospace][b],[/b][/font][/color][color=#000000][font=monospace][b] [/b][/font][/color][color=#000000][font=monospace][b]clear_all_selected[/b][/font][/color][color=#009900][font=monospace][b]=[/b][/font][/color][color=#AA22FF][font=monospace][b][i]False[/i][/b][/font][/color][color=#000000][font=monospace][b],[/b][/font][/color][color=#000000][font=monospace][b] [/b][/font][/color][color=#000000][font=monospace][b]show_asset_if_selected[/b][/font][/color][color=#009900][font=monospace][b]=[/b][/font][/color][color=#AA22FF][font=monospace][b][i]False[/i][/b][/font][/color][color=#000000][font=monospace][b])[/b][/font][/color]How do I use this correctly and what does SELF mean in this context?And my second question:How do I detect if a node of a certain type is inside the current active directory?I want to create an if statement that creates a new digital asset as shown above called "importFile", but only if it does not exist yet. If it does exist it needs to store it as variable " i "So if I have "geo1" as my current directoryAnd I have a digital asset of type "importFile" with a random name inside "geo1".Then how do I detect if this node exists to do an IF check on it?If anyone knows one or both of the answers to these questions, it would be greatly appreciated. Edited October 7, 2012 by hyperforce Quote Link to comment Share on other sites More sharing options...
TomRaynor Posted October 7, 2012 Share Posted October 7, 2012 "self" is referring to the node object that you are running the "setSelected()" function on. So if you were calling i.setSelected() then self would be the python object stored in the variable "i". You don't need to include it when you call the function though as python takes care of that for you so just leave it out when you run the function. To check if a certain node type exists at a particular level, you need to get a list of all nodes at that level, then running through all items in the list and checking what type as shown below. topLevelNode = hou.node('/obj/geo1') children = topLevelNode.children() for child in children: if child.type() == "blah": DO SOMETHING Hope this helps, sorry for any typos or syntax errors, I'm not at my PC... Quote Link to comment Share on other sites More sharing options...
hyperforce Posted October 8, 2012 Author Share Posted October 8, 2012 Thanks for the help. You are right, I only needed to type setSelected(True) to make it work (not ON) or self. The for loop method should work as well. Thanks a lot. Quote Link to comment Share on other sites More sharing options...
hyperforce Posted October 8, 2012 Author Share Posted October 8, 2012 (edited) Well the good news is, the for loop works, but the type() section doesn't seem to detect the the node. This is the script I have running: nodes = p.children()exist = 0for child in nodes: if child.type() == "importFile": # (it never seems to executes this part) print "The node exists" i = child exist = 1 breakif exist == 0: i = p.createNode("importFile")[/CODE]Even if I try to use a stand alone "if" statement that checks if the node exists right after is has been created, it can't find it.[CODE]i = p.createNode("importFile")if i.type() == "importFile": print "The node exists"[/CODE]Is the script correct (i'm not getting errors) or am I doing something wrong? Edited October 8, 2012 by hyperforce Quote Link to comment Share on other sites More sharing options...
graham Posted October 8, 2012 Share Posted October 8, 2012 hou.Node.type() returns a hou.NodeType object, not a string name. Try i.type().name() instead. 1 Quote Link to comment Share on other sites More sharing options...
hyperforce Posted October 8, 2012 Author Share Posted October 8, 2012 hou.Node.type() returns a hou.NodeType object, not a string name. Try i.type().name() instead. Thanks, that worked Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.