Maya C++ API Programming Tips

How to get the value of the attribute at the specified time

int frame = 101;
MPlug plg( thisMObject(), "abc" );
MDGContext ctx( MTime( frame, MTime.uiUnit() ) );
double value = 0.0;
plg.getValue( value, ctx );

How to get the data block outside compute() member function

MDataBlock block = forceCache();

How to get playback time interval

const double dt = AnimControl::playbackBy();

How to update DG node every frame without the input connection from time1

class MyNode{
private:
  MCallbackId timeChangeCallbackId;
public:
  void addedToModelCB();
  void removedFromModelCB();
  void update();
  ...
};
 
MyNode::MyNode{
  ...
  timeChangeCallbackId = 0;
  ...
}
 
static void TimeChangeCallback( MTime& time, void* clientData ){
  reinterpret_cast<ZShape*>(clientData)->update();
}
 
static void NodeAddedToModel( MObject& nodeObj, void* clientData ){
  MFnDependencyNode nodeFn( nodeObj );
 
  MyNode* nodePtr = (MyNode*)nodeFn.userNode();
  if( !nodePtr ) { return; }
 
  nodePtr->addedToModelCB();
}
 
static void NodeRemovedFromModel( MObject& nodeObj, void* clientData ){
  MFnDependencyNode nodeFn( nodeObj );
 
  MyNode* nodePtr = (MyNode*)nodeFn.userNode();
  if( !nodePtr ) { return; }
 
  nodePtr->removedFromModelCB();
}
 
void MyNode::postConstructor(){
  MModelMessage::addNodeAddedToModelCallback( thisMObject(), NodeAddedToModel );
  MModelMessage::addNodeRemovedFromModelCallback( thisMObject(), NodeRemovedFromModel );
}
 
void MyNode::addedToModelCB(){
  timeChangeCallbackId = MDGMessage::addTimeChangeCallback( TimeChangeCallback, this );
}
 
void MyNode::removedFromModelCB(){
  if( timeChangeCallbackId ){
    MDGMessage::removeCallback( timeChangeCallbackId );
    timeChangeCallbackId = 0;
  }
}

How to handle the multiple outputs of a DG node

How to capture the current viewport as an image file

How to save the current frame buffer to a JPG file

How to set the names of a custom DG node and its parent node

How to compile my source code conditionally according to the Maya API version

How to get the current Maya version

How to avoid the conflict with Cuda

How to set the MFloatPoint from a MPoint

How to get the pixel values of an image

How to get the DAG path from a node name

How to get the DG node object from a node name

How to get the DAG path from a DAG node object

How to get the node name from a node object

How to get the parent DAG node object

How to get the shape node DAG path from a transform DAG path

How to get the DAG paths of selected mesh shape nodes

How to get the all of NURBS curve node objects in the current scene

How to get the list of a selected mesh polygons

How to get the all of fields in the current scene

How to get the local transformation matrix of the current shape node

How to get the world matrix of the current shape node

How to connect the output plug to the parent automatically when a custom locator node is created

How to make a custom locator node un-selectable

How to detect which input attribute is changed

Note) It doesn’t work when inputObj is array type.

How to detect whether the current state is batch mode

How to detect whether the current viewport is Viewport 2.0

How not to draw a custom locator node while mouse interactions (>=2015)

How to draw a text in draw() of a custom locator node

How to copy the input mesh to the output mesh in compute() of a custom node

How to deform the input mesh in compute() of a custom node like such a deformer

How to handle array attribute

How to get the value of an attribute anywhere in a custom node

How to get the pointer of the other connected node

How to restore GL states in draw() of a custom locator node

How to call compute() of a custom locator without output connection

How to get the normal vector of a current camera

How to create attributes in initialize() of a custom node

Last updated