Jump to content

Python Shelf Btn Script With Simple UI


John Svensson

Recommended Posts

Hi there!

 

I wrote a couple lines of python code that lets you export Houdini point attributes to an xml file. And then another couple of lines that reads the xml file in Maya. 

Useful for getting Houdini point colors to vertex colors in Maya, and possible other things to.

 

I thought I would create a simple UI for the Houdini part of the script that has a couple of user defined parameters.

But after searching for a while I still don't have a clear idea what's the simplest way to do this.

 

I've attached a image of what the UI could look like. If this was a scripted python Digital Asset then I would get the UI for free, it feel like this shouldn't be that hard either.

To do this in Maya, with Python or Mel isn't that tricky either.

 

If it's possible I would like to avoid using PySide & PyQt.

 

I've been looking the the hou.ui module but I don't really understand, I read somewhere that one approach is to load a UI description from a external file.

 

What is common practice here (for simple UI's & dialogs)?

 

Thanks

/ John

post-9338-0-89046100-1437735344_thumb.pn

Link to comment
Share on other sites

I think this type of tool makes the most sense as a SOP digital asset. So you specify the attributes you want to export from its input and then you have a button that does the export. This is similar to the ROP Output Driver SOP except that it outputs some .xml file format instead.

Link to comment
Share on other sites

What's the reason to avoid PySide if it's bundle with Houdini 14?

Anyway,  take a look at my huilib library. It's pure python and easy to use, although very limited in features.

 

I guess I thought because of the simplicity of what I want it was a simpler way than PySide (or maybe I should just try to learn it instead), I can only compare to maya with Mel & Python where you have PySide as an option but for simple UI stuff its quit easy to accomplish with a couple of lines of Mel or Python.

I came across your library when I was searching this topic, I haven't tried it but it seems to do what I needed. I guess I just wanted to know what was common practice, this Houdini .ui language, is it just for HDK stuff (don't know what i mean) or could it work for this kind of thing?

 

I will check out your library anyway though, thanks for your answer

 

I think this type of tool makes the most sense as a SOP digital asset. So you specify the attributes you want to export from its input and then you have a button that does the export. This is similar to the ROP Output Driver SOP except that it outputs some .xml file format instead.

 

I did look at it that way, I only saw that if I did it like a SOP DA all my UI problems would disappear. For some reason I saw it as a quick fix that didn't made sense, but when you say it like that, I guess you're right! Thanks

Link to comment
Share on other sites

Hi again!

 

So I started to write my tool as a DA node instead of shelf script, and I have a few questions about the "anatomy" of a python node.

 

I started to write my code as I've done before in the Code section of the Edit Operator Type Properties window. The first bump I hit was that I have a "Write" button in my UI that allows the user to run the tool, the node doesn't do anything without it.

 

I found that to be able to call a function from the button I had to create a python module event handler in the script part of the window. Now I can call my "start" function with this callback script on the button

kwargs['node'].hdaModule().cook()

The script checks a few user parameters and have 2 outcomes (for now), "Invalid parameter settings" or call the "write" function. 

 

What I got stuck on was, that I want to raise a error if the parameters aren't valid. What I understand is that there are a few different way to do this in the UI. What I'm after is the regular black & yellow stroke, node error where you can middle mouse button click on the node and there are some description there. This is the code I believe.

raise hou.NodeError("Invalid parameter settings")

But when I run it from my python module, what I get is a pop up window displaying the error, if I instead run it from the code section, it works fine. 

 

Can python functions from the code & the script section talk to each other? 

 

I think it's something about the whole module thing I don't quite grasp.

 

(I found this thread with the exact same question, unanswered) https://www.sidefx.com/index.php?option=com_forum&Itemid=172&page=viewtopic&p=182284&sid=40be76ecbcde29c17d0f2eb50434536f

 

Thanks / John

Edited by John Svensson
Link to comment
Share on other sites

Thanks for your answer edward.
 
I did a fast google on your suggestion but it seemed a bit more complicated than I thought it would be.
 
I attached a screen grab over how my node looks in it current state. I may be off track here but, what I think would solve everything is if I could get a function (cook) from img (3) to call a function in img (2).
 
I get this error message when I try. 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "opdef:/Sop/AttribIO_HToM_Writer?PythonModule", line 24, in cook
NameError: global name 'error_test' is not defined

It really feels like it's some detail I'm missing because there something about these modules I don't understand to how they relate to each other.

 

Is there something like global functions or can I call the function some other way?

mlyijjt.png

 

Thanks again!

 

/ John

Link to comment
Share on other sites

Wouldn't it easier to do basically the opposite?

 

Use the callback to do nothing more then set a variable that allows the SOP to actually write the file, and then cook the SOP.

 

So all the actual code sits in the SOP, and the callback can simply turn a parm that allows the data to be written, cook, turn parm back.

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