Tyfx567 Posted February 19, 2016 Share Posted February 19, 2016 I want to create a tool that will later have a callback script on a button that will select the transform node that is inside the tool so that I can say move points around without having to dive inside the tool to select the transform node. Is there any python script that actually selects nodes? I can't find anything. Thanks guys Quote Link to comment Share on other sites More sharing options...
Tyfx567 Posted February 19, 2016 Author Share Posted February 19, 2016 (edited) Ok so I found out how to select: make a variable for the node path, then say exnode.setSelected(1, 1) But now I can't figure how out how to use this in my callback script? Any ideas? I eventually want to get to where I can say transformnode = hou.node('../uniquetransform') transformnode.setSelected(1,1) in my callbackscript since it would be inside a tool it has to be a relative reference Any ideas? I'm getting an error saying whenever I type hou.node('obj/box_object1/uniquetransform').setSelected(1,1) in my callbackscript Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'setSelected' UPDATE: So somehow it is correct when I actually changed it to the relative path so now it is hou.node("../uniquetransform").setSelected(1,1) Edited February 19, 2016 by Tyfx567 Quote Link to comment Share on other sites More sharing options...
dennis.albus Posted February 19, 2016 Share Posted February 19, 2016 (edited) If you are running the script as a button callback script and your function is located in your hdaModule this should work. hou.phm().selectnode() In the hdaModule you can then do this: def selectnode(): hou.node("{0}/uniquetransform".format(hou.pwd().path())).setSelected(1,1) EDIT: Sorry I did not see that you already solved it with the relative path (however there is a dot too much, it should be "./uniquetransform"). I hope this is still helpful. Edited February 19, 2016 by dennis.albus Quote Link to comment Share on other sites More sharing options...
michael Posted February 19, 2016 Share Posted February 19, 2016 the reason for the error was that your path was missing a "/" hou.node('obj/box_object1/uniquetransform').setSelected(1,1) should have been hou.node('/obj/box_object1/uniquetransform').setSelected(1,1) Quote Link to comment Share on other sites More sharing options...
Tyfx567 Posted February 22, 2016 Author Share Posted February 22, 2016 (edited) Oh thank you Michael and Dennis I didn't know those things. Ok I have been trying to get this to work all day today and am just confused a little about how to implement this. I am realizing that I must do a callback script for what I want to do: I am building a tool that involves me wanting to show the user a template of an object when they select a certain menu item called templatedObject. It's a lot more involved than just that obviously. Anyway Here is essentially what I want to do: Whenever I hit templated object in the menu selection. I want this callback script to run. viewer = hou.pwd().parm("Viewer") myObject = hou.node("./null2") if viewer.evalAsString() == "TemplatedObject": for i in hou.pwd().children(): i.setTemplateFlag(0) myObject.setTemplateFlag(1) so I am clearing all templated objects in the scene just in case there was one already made. Then assigning a template on one specific object. However I am thinking I will have to read this in as a file since I am doing a more complicated for loop in the callback which is really long and I keep getting an error in the callback. So that said I thought of reading in a file using this in the callback section: eval(hou.readFile("Path to file")) To test to see if the file evaluates first before putting it in the callback section I tested it in the python shell reformatting the script to use not local but absolute paths to objects in the scene. But it doesn't work. It says the viewer = hou.node("") part is an invalid syntax. Any ideas guys? Edited February 22, 2016 by Tyfx567 Quote Link to comment Share on other sites More sharing options...
dennis.albus Posted February 22, 2016 Share Posted February 22, 2016 (edited) I would not use hou.readFile() or execfile() (or anything along those lines) for this. You should get used to using proper python modules. Create you scriptfile (let's call it template.py) in your $HOME/houdinixx.x/python2.7libs folder (or any folder that is in your PYTHONPATH). Now you should be able to import it into the hdamodule of your digital asset or use it in the button callback directly. import template; template.my_template() The contents of template.py could be like this. import hou def my_template(): viewer = hou.pwd().parm("Viewer") myObject = hou.node("./null2") if viewer.evalAsString() == "TemplatedObject": for i in hou.pwd().children(): i.setTemplateFlag(0) myObject.setTemplateFlag(1) You might have to pass your current node as an argument as I seem to remember that an external module cannot access the current node via hou.pwd().But I am not 100% sure about this. Edited February 23, 2016 by dennis.albus Quote Link to comment Share on other sites More sharing options...
Tyfx567 Posted February 23, 2016 Author Share Posted February 23, 2016 That worked thanks Dennis. I also realized it is execfile("file path") and that works as well. 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.