c++ - Event in Maya Api to capture currentTime / frame change -
developing maya plugin. how can set-up callback gets fired each time frame number / current time changed in scene ?
had @ mscenemessage class, doesn't seem contain looking for.
thanks.
you can use meventmessage
setup callback every time frame/current time changes. code speaks louder words, here's code comments interspersed illustrate how set up: (tldr impatient first, full code excerpt follow in next section)
tldr:
a code summary impatient:
// ... // our callback id array // store ids of our callbacks // later removal mcallbackidarray mycallbackids; // actual adding callback happens // register our callback "timechanged" event mcallbackid callbackid = meventmessage::addeventcallback("timechanged", (mmessage::mbasicfunction) mysamplecmd::usercb); // ... if(mycallbackids.length() != 0) // make sure remove callbacks added stat = meventmessage::removecallbacks(mycallbackids);
- reference meventmessage docs.
- the events listed here (in
scriptjob
command) can usedmeventmessage
.
full(ish) code comments:
mysamplecommand.h
class mysamplecmd : public mpxcommand { public: mysamplecmd(); virtual ~mysamplecmd(); // our callback - implemented static method static void usercb(void* clientdata); mstatus doit( const marglist& ); mstatus redoit(); mstatus undoit(); bool isundoable() const; static void* creator(); public: // our callback id array // store ids of our callbacks // later removal mcallbackidarray mycallbackids; };
mysamplecommand.cpp (excerpt)
// constructor mysamplecmd::mysamplecmd() { // clearing our callback id array // housekeeping mycallbackids.clear(); } // destructor mysamplecmd::~mysamplecmd() { // make sure remove callbacks added // failing result in fatal error if(mycallbackids.length() != 0) // remove meventmessage callback meventmessage::removecallbacks(mycallbackids); } mstatus mysamplecmd::redoit() { // actual adding callback happens // register our callback "timechanged" event mcallbackid callbackid = meventmessage::addeventcallback("timechanged", (mmessage::mbasicfunction) mysamplecmd::usercb); // append newly added callback's id our list of callback ids // future removal mycallbackids.append(callbackid); return ms::ksuccess; } mstatus mysamplecmd::undoit() { mstatus stat; if(mycallbackids.length() != 0) // make sure remove callbacks added stat = meventmessage::removecallbacks(mycallbackids); return stat; } // our callback function void safeselect::usercb(void* clientdata) { mglobal::displayinfo( "callback usercb called!\n" ); return; }
Comments
Post a Comment