Showing posts with label Maya API. Show all posts
Showing posts with label Maya API. Show all posts

Maya API : nodeFromName

MStatus pluginCmd::nodeFromName(MString name, MObject & obj)
{
    MSelectionList templist;
    templist.add(name);
    if(templist.length() > 0)
    {
        templist.getDependNode(0,obj);
        return MS::kSuccess;
    }
    return MS::kFailure;
}

Create a new Camera Node

M3dView view;
MObject camera;
MDagPath cameraPath;
// create new camera
view = M3dView::active3dView(&status);
MFnCamera fnCamera;
fnCamera.create(camera,NULL);

Maya Plugin Development Primer

Here are few steps for developing plugins from scratch and not using the wizard, thanks to Rob Bateman for most of the info,

1. Create dll project
2. add a c++ file to it
3. change the output extension to mll
4. change project settings->C/C++->Code generation to Multi-threaded or Multi-threaded-debug
5. add NT_PLUGIN & REQUIRE_IOSTREAM to the C/C++ -> pre-processor defines in the project settings
6. set the library and include paths to the maya API (additional include directories, and additional lib directories (Foundation.lib, OpenMaya.lib)

in the cpp file:
//
#include <maya/MFnPlugin.h>
#include <maya/MPxCommand.h>
//
// link libs under VisualC++/Win32
#ifdef WIN32
#pragma comment(lib,"Foundation.lib")
#pragma comment(lib,"OpenMaya.lib")
#pragma comment(lib,"OpenMayaFx.lib")
#pragma comment(lib,"OpenMayaUi.lib")
#pragma comment(lib,"Image.lib")
#pragma comment(lib,"OpenMayaAnim.lib")
#pragma comment(lib,"OpenGl32.lib")
#pragma comment(lib,"glu32.lib")
#endif

#ifdef WIN32
#define EXPORT __declspec(dllexport)
#else
#define EXPORT
#endif
//--------------------------------------------------------------------------------------------------
class helloCmd : public MPxCommand{
public:
virtual MStatus doIt(const MArgList&);
static void *creator(){
return new helloCmd;
}
};
//--------------------------------------------------------------------------------------------------
MStatus helloCmd::doIt(const MArgList& args){
MStatus status = MS::kSuccess;
MGlobal::displayInfo("Hello\n");
setResult("initialized");
return status;
}
//--------------------------------------------------------------------------------------------------
EXPORT MStatus initializePlugin( MObject obj )
{
MStatus status;
MFnPlugin pluginFn( obj, "Vishang Shah", "1.0");
status = pluginFn.registerCommand("helloCmd",helloCmd::creator);
if(!status)
  status.perror("registerCommand Failed");
return status;
}
EXPORT MStatus uninitializePlugin( MObject obj)
{
MFnPlugin pluginFn( obj );
MStatus status;
status = pluginFn.deregisterCommand("helloCmd");
if(!status)
  status.perror("deregister failed");
return status;
}
//--------------------------------------------------------------------------------------------------

Lord of the Mayas : The Two APIs

From 8.5, Maya introduced Python support for scripts and plug in development,
For people using older versions, they can use this :
http://cgkit.sourceforge.net/

So Maya has Two APIs now , Maya C++ API and Maya Python API,
Plug ins developed using Python API are called Scripted Plugins.

You can find example scripted plug ins at here:
C:\Program Files\Autodesk\Maya8.5\devkit\plug-ins\scripted

Code blocks in Both APIs are very similar,
Both kinds of plug ins need to be initialized and uninitialized,

If you are using Visual Studio .NET for Maya C++ Plug in Development then while creating API project through wizard , VS creates a Macro called declareSimpleCommand
This Macro takes care of initialize/uninitialized of Plug in.
While in Python we need to take care of this through separate functions

All computations will go in doIt function of class derived from Maya's Library,

Stand Alone applications can also be written using any of both APIs.

Here are some sites for Python development,
http://www.daniweb.com/forums/forum114.html
http://aspn.activestate.com/ASPN/

Happy Developing,
:-)

Maya API Development

Ok,

Here starting Maya API Development,

First some good resources,

http://www.robthebloke.org/
http://hohehohe2.hp.infoseek.co.jp/openMaya-eng/0mokuji.html
http://florian.loitsch.com/gpExport/

And Complete Maya Programming Vol 1 and 2 by David Gould,

:-)

Vishang Shah