Jump to content

HOM questions: Self & How do I check if a node of Type X exists


hyperforce

Recommended Posts

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 onTransfer
File "C:/PROGRA~1/SIDEEF~1/HOUDIN~1.33/houdini/python2.6libs\hou.py", line 5132, in setCurrent
return _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 directory

And 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 by hyperforce
Link to comment
Share on other sites

"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...

Link to comment
Share on other sites

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 = 0

for child in nodes:
if child.type() == "importFile":
# (it never seems to executes this part)
print "The node exists"
i = child
exist = 1
break

if 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 by hyperforce
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...