Jump to content
phCharles

python IDE & houdini

Recommended Posts

Hi

Just wondering what the ideal workflow is for developing a pyScript within Houdini 11.

Using the python shell is great in many respects, but it seems problematic for longer scripts: The copy/paste doesn't seem to work really well, especially with nested "for" loops... if I make a typo in a long multi-line script, it can be problematic to fix what should be a very quick & simple fix. I'm also surprised it doesn't seem possible to open more than the one shell at a time.

This leads me to wonder: what is the best workflow for developing python scripts within houdini? Is there an IDE that can be integrated into the workflow smoothly?

Any feedback you may have would be appreciated

thanks

Edited by phCharles

Share this post


Link to post
Share on other sites

Use pretty much whatever IDE you want and then you can import the Python scripts from disk as modules in Houdini, then call whatever you want from that module. I'm using Eclipse currently to edit the Python outside of Houdini (with PyDev plugin). Trying to keep everything inside of Houdini is cumbersome, as you've discovered.

Share this post


Link to post
Share on other sites

Use pretty much whatever IDE you want and then you can import the Python scripts from disk as modules in Houdini, then call whatever you want from that module. I'm using Eclipse currently to edit the Python outside of Houdini (with PyDev plugin). Trying to keep everything inside of Houdini is cumbersome, as you've discovered.

Are you able to debug Python in Eclipse while it's running in Houdini?

Share this post


Link to post
Share on other sites

Use pretty much whatever IDE you want and then you can import the Python scripts from disk as modules in Houdini, then call whatever you want from that module. I'm using Eclipse currently to edit the Python outside of Houdini (with PyDev plugin). Trying to keep everything inside of Houdini is cumbersome, as you've discovered.

Thanks for the prompt reply.

I had hoped for a more integrated solution, at least like the editor found in nuke, which allows for text manipulation and for executing isolated lines, etc. I had high expectations of Houdini being a dream for use with python, so I'm a little surprised that it's not there quite yet, at least in terms of having a basic integrated editor.

So my understanding is that the workflow to adopt is :

1) use the shell editor for testing/developing short snippets of code (taking advantage of auto-completion etc)

2) For longer scripts, write the script out in Eclipse - outside of Houdini - and then copy/paste the script back into the Houdini shell once ready for final execution/testing (or rather than copy/paste, one can import the python script from disk as a module, as you describe).

Thanks

Edited by phCharles

Share this post


Link to post
Share on other sites

2) For longer scripts, write the script out in Eclipse - outside of Houdini - and then copy/paste the script back into the Houdini shell once ready for final execution/testing.

Copy and paste is one option, or you can import it back in as a module. Imagine this script called foo.py in /home/luke/scripts or somewhere else.

def addNumbers(num1,num2):
    return num1 + num2

In Houdini add the path to the script to Python's path in Houdini. If all of the scripts live in one place then you can have Houdini do this automatically.

import sys
sys.path.append("/home/luke/scripts")

Now in Houdini you can import that script as a module and use it. This can happen on an expression, in the session module, on an OTL, or even just the interactive Python shell.

import foo
bar = foo.addNumbers(10,20)
print str(bar)

Share this post


Link to post
Share on other sites

Are you able to debug Python in Eclipse while it's running in Houdini?

No, Eclipse is just a place to author the scripts for the most part. Though you could import the hou module into scripts outside of Houdini and test things that way still in Eclipse (but uses a Houdini license when loading the hou module).

Edited by lukeiamyourfather

Share this post


Link to post
Share on other sites

Copy and paste is one option, or you can import it back in as a module. Imagine this script called foo.py in /home/luke/scripts or somewhere else.

def addNumbers(num1,num2):
    return num1 + num2

In Houdini add the path to the script to Python's path in Houdini. If all of the scripts live in one place then you can have Houdini do this automatically.

import sys
sys.path.append("/home/luke/scripts")

Now in Houdini you can import that script as a module and use it. This can happen on an expression, in the session module, on an OTL, or even just the interactive Python shell.

import foo
bar = foo.addNumbers(10,20)
print str(bar)

This is very helpful

Many thanks!

Share this post


Link to post
Share on other sites

I would add to this that it strongly depends on what exactly you are trying to do. This defines the way you should add a script to Houdini.

For a temporary script you could also use the python session module which you can find under Window>Python Source Editor. You can then access functions with hou.session.foo(). Beware however that this is really what it is called - temporary functions for the current Houdini sessions which are not stored with your scene.

Edit: As lukeiamyourfather pointed out the session module IS saved with the Houdini file.

Another way could be to add the script to the shelf which would be a little more persistent and easy to access. Just right click on the shelf and choose "New Tool".

For the integrated script editors in Houdini you can also define an external editor with (I think) the $EDITOR or $VISUAL environment variable. By pressing alt-e in Houdini's integrated editor you can bring it up, edit your script and just save it to bring it back to Houdini.

Edited by dennis.weil

Share this post


Link to post
Share on other sites

Thanks for this reply. I'll definitely explore some of the ideas you presented here.

For the integrated script editors in Houdini you can also define an external editor with (I think) the $EDITOR or $VISUAL environment variable. By pressing alt-e in Houdini's integrated editor you can bring it up, edit your script and just save it to bring it back to Houdini.

Can you please elaborate on this?

I'm not clear on what you mean.

thanks!

Share this post


Link to post
Share on other sites

Can you please elaborate on this?

I'm not clear on what you mean.

thanks!

Just tried using the session module and the external editor via the session module.

Very cool and helpful

thanks again!

Share this post


Link to post
Share on other sites

Beware however that this is really what it is called - temporary functions for the current Houdini sessions which are not stored with your scene.

The session module is saved with the scene. So you can continue to use it after closing and opening the scene again.

Share this post


Link to post
Share on other sites

The session module is saved with the scene. So you can continue to use it after closing and opening the scene again.

You are right. I tried it before and it didn't save my session module but now I tried it again and it worked. Seems like I was doing something wrong before. Thanks for the clarification.

Share this post


Link to post
Share on other sites

You are right. I tried it before and it didn't save my session module but now I tried it again and it worked. Seems like I was doing something wrong before. Thanks for the clarification.

Is there a trick to this?

I just tried this out as a test, and the code within the session module was _not_ saved with the scene.

thanks

C

  • Like 1

Share this post


Link to post
Share on other sites

Seems it only saves the code if the code has been applied.

Any changes/additions to the code within the session module will be discarded when the file is saved unless the code has been applied.

thanks

C

Share this post


Link to post
Share on other sites

Not really following the thread, but you could create a digital asset and save the python code in there.

Share this post


Link to post
Share on other sites

Not really following the thread, but you could create a digital asset and save the python code in there.

Hi

Thanks for your comment.

This actually all began when I was watching the cmivfx tutorial on creating/enhancing digital assets using python. While following the tutorial (which uses the python shell exclusively for the first few chapters), I found it awkward to edit text within the shell. A few nested "for" loops quickly became a mild drag to correct if I had even one typo... Having used python elsewhere, I found this seemed arguably more tedious than it needed to be.

While wishing for an integrated editor, I turned to this forum to get the scoop. I'm now better acquainted with the three options houdini has to offer on the python front (shells, session module and digiAssets). With a few more hours of playful tinkering, I'll develop a deeper appreciation for when is best to use each.

I think that about covers it. Many thanks to all for your helpful feedback.

Please let me know if there are any other interesting houdini-python workflows not yet covered here.

C

Share this post


Link to post
Share on other sites

You forgot about the shelf tools which I mentioned earlier. Just right click on the shelf and choose "New Tool". You can write your Python Tool inside the scripts tab.

You can also embed Python code into your Menus by editing MainMenuCommon for example. On a Mac this file is located here:

/Library/Frameworks/Houdini.framework/Versions/11.0.735/MainMenuCommon

-dennis

Share this post


Link to post
Share on other sites

Seems it only saves the code if the code has been applied.

Any changes/additions to the code within the session module will be discarded when the file is saved unless the code has been applied.

thanks

C

Other dialogs are similar in Houdini. For example an OTL type properties dialog. If you don't click apply or accept then it won't save the changes. Think of the apply and accept buttons as save buttons. :blink:

Share this post


Link to post
Share on other sites

possible alternatives?

you could probably also run 'live' from another python session (running in eclipse) by using the socket module to tap into houdini. essentially you open a socket server in houdini, and a client in eclipse - then write some tricky code to format all the text in a way it can go down the pipe. Eclipse has an 'external tools' configuration which allows you to set it up , basically you send all the code into houdini as text via the socket- although this does take some time to set up correctly! in this way the python code gets run in houdini immediately without having to be saved etc.... I haven't set this up for houdini, only maya and nuke(so not sure if there are any socket/threading pitfalls in houdini)... you really need to know your way around the socket/thread python modules to get this going....

you could also look at the rpc modules - so rather than sending all the code down a pipe, you run all the code in the external editor. The trick here being that the hou module being used in the external editor links to the open houdini session - this is great for development as it saves copying and pasting, and if you later want to put that code into a HDA, button or other script that runs from within houdini- you can just replace the calls to the hou module...

http://www.sidefx.com/docs/houdini9.5/hom/rpc - which i have played with and it works

http://www.sidefx.com/docs/houdini11.0/hom/rpc - which i haven't played with...

again, i'm fairly new to houdini - so there could be some big pitfalls with these methods that i can't see....

what's great about these methods is the code can all be neatly kept in eclipse or whatever IDE you use....

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

×