Jump to content

Python getting a node name vs getting an instance?


Outlawed

Recommended Posts

Ok, this is a simple question, but I've been out of python for so long, I've lost touch.

I have a node called geo1.  When I run the following script, i'd like the "Node to copy is" to give the same result of "Selected is"  ( I think one is called 'getting an instance', and the other is just returning the node name).  Noob question I know.

if(hou.selectedNodes()):
    selected = hou.selectedNodes()
    nodeToCopy = hou.node('/obj/geo1')
    print "Selected is " + str(selected)
    print "Node to copy is " + str(nodeToCopy)

Instead it returns:

Selected is (<hou.ObjNode of type geo at /obj/geo1>,)
Node to copy is geo1

How do I get the same return when giving an explicit node path?

Link to comment
Share on other sites

That is EXACTLY what I was after!  Thanks Tomas!

Although one returns a tuple, and the other returns a single instance

Taking it the next step however, gives an error:

if(hou.selectedNodes()):
    selected = hou.selectedNodes()
    nodeToCopy = repr(hou.node('/obj/geo1'))
    print "Selected is " + str(selected)
    print "Node to copy is " + str(nodeToCopy)
    
    objlevel = hou.node("/obj")
    low = hou.copyNodesTo(nodeToCopy, objlevel)

 

Link to comment
Share on other sites

Okay, I converted it to a tuple, but it still throws an error.  you can see that when it prints the type, they both say <type 'tuple'> but mytup has quotation marks when it prints - is this what's causing it to not successfully run the hou.copyNodesTo command?

if(hou.selectedNodes()):
    selected = hou.selectedNodes()
    nodeToCopy = repr(hou.node('/obj/geo1'))
    a = [nodeToCopy]
    mytup = tuple(a, )
    
    w = type(selected)
    x = type(mytup)
    
    print selected
    print w
    print mytup
    print x
    #print "Selected is " + str(selected)
    #print "Node to copy is " + str(mytup)
    
    objlevel = hou.node("/obj")
    low = hou.copyNodesTo(mytup, objlevel)

 

Link to comment
Share on other sites

in that case don't convert it to string using repr() just keep it as an object

and yes, copyNodesTo requires a tuple 

objlevel = hou.node("/obj")
nodesToCopy = (hou.node('/obj/geo1'), )
low = hou.copyNodesTo(nodesToCopy, objlevel)

 

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