Jump to content

Python Save Event Callback


MrScienceOfficer

Recommended Posts

EDIT : I figured I would change the title so it will be possible to find this later...

 

..........................................................................................................................

 

Yea...  Whats up with that? 

 

I thought 123.py is supposed to run every time one launches Houdini, but it only runs when I launch Houdini into an empty file).

 

 I.e. C:\Program Files\Side Effects Software\Houdini 15.0.298\bin\houdinifx.exe without command args runs 123.py but with say I run it with $HIP\pythonToolsTesting.hip as a command arg it doesn't run 123.py.

 

Is that right?  If so how can I append a path to look for a python module then?

 

 

....EDIT: Okay Nevermind :)   So just use 456.py right?

Edited by MrScienceOfficer
Link to comment
Share on other sites

123.py runs on empty, 456.py runs when you load with a script or load a new script into houdini.  i'd love to see a 789.py run when you save... altho, really these should all be handled via some kind of event system.  houdini 16 maybe?

Link to comment
Share on other sites

you can get the current hipfile name via python calls, so that's not an issue.  the only problem is knowing when you need to do that.  you can kind of hack together something by hooking into other events that fire more frequently, then checking the hipfile name to see if it's changed every time.  but that kind of stuff makes me feel dirty.

Link to comment
Share on other sites

That is really dirty, I'd almost say it's filthy...

 

 

I got it to work ;)


#include <UT/UT_DSOVersion.h>
#include <CMD/CMD_Args.h>
#include <CMD/CMD_Manager.h>

#include <OP/OP_Director.h>


static OP_ERROR mySaveCall(std::ostream&, void* save)
{
	const char* pythonfile = "C:/.../789.py";

	OPgetDirector()->runPython(CMDgetManager(), pythonfile);

	return OP_ERROR::UT_ERROR_NONE;
}

static void
cmd_args(CMD_Args &args)
{
	OPgetDirector()->setSaveCallback(mySaveCall, NULL);
}

void
CMDextendLibrary(CMD_Manager *cman)
{
    cman->installCommand("installMySaveHook", "", cmd_args);
}
 

All you need to do is run installMySaveHook from 456.cmd

Edited by MrScienceOfficer
  • Like 1
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...