Outlawed Posted January 30, 2020 Share Posted January 30, 2020 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? Quote Link to comment Share on other sites More sharing options...
anim Posted January 30, 2020 Share Posted January 30, 2020 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 1 Quote Link to comment Share on other sites More sharing options...
Outlawed Posted January 30, 2020 Author Share Posted January 30, 2020 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) Quote Link to comment Share on other sites More sharing options...
Outlawed Posted January 30, 2020 Author Share Posted January 30, 2020 Looks like I need to somehow convert the nodeToCopy to a tuple. Is that correct? Quote Link to comment Share on other sites More sharing options...
Outlawed Posted January 30, 2020 Author Share Posted January 30, 2020 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) Quote Link to comment Share on other sites More sharing options...
anim Posted January 30, 2020 Share Posted January 30, 2020 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) Quote Link to comment Share on other sites More sharing options...
Outlawed Posted January 30, 2020 Author Share Posted January 30, 2020 Argh so simple. Thanks Tomas! 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.