Jump to content
Outlawed

Python getting a node name vs getting an instance?

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?

Share this post


Link to post
Share on other sites
print "Node to copy is " + repr(nodeToCopy)

will return 

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

if that's what you are after

  • Like 1

Share this post


Link to post
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)

 

Share this post


Link to post
Share on other sites

Looks like I need to somehow convert the nodeToCopy to a tuple.  Is that correct?

Share this post


Link to post
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)

 

Share this post


Link to post
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)

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×