0% found this document useful (0 votes)
225 views2 pages

This document contains C++ code for a Maya plugin that defines a command called "getPoints" to retrieve and output the vertex points of a selected mesh geometry. The code defines a getMeshPoint class that inherits from MPxCommand and overrides required methods. The doIt method gets the selected object, iterates through its polygons and vertices, appending the points to an array which is then output. The plugin registers and deregisters the new command on initialization and cleanup.

Uploaded by

cashdrc
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
225 views2 pages

This document contains C++ code for a Maya plugin that defines a command called "getPoints" to retrieve and output the vertex points of a selected mesh geometry. The code defines a getMeshPoint class that inherits from MPxCommand and overrides required methods. The doIt method gets the selected object, iterates through its polygons and vertices, appending the points to an array which is then output. The plugin registers and deregisters the new command on initialization and cleanup.

Uploaded by

cashdrc
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

//-

// ==========================================================================
// Domingos, 31/05/2010
// [email protected]
// visual3dtools.blogspot.com
//
// ==========================================================================

#include <maya/MIOStream.h>
#include <math.h>

#include <maya/MFnPlugin.h>
#include <maya/MPoint.h>
#include <maya/MPointArray.h>
#include <maya/MDoubleArray.h>
#include <maya/MVector.h>
#include <maya/MVectorArray.h>
#include <maya/MGlobal.h>
#include <maya/MString.h>
#include <maya/MStringArray.h>
#include <maya/MItMeshPolygon.h>
#include <maya/MPxCommand.h>
#include <maya/MArgList.h>
#include <maya/MDagPath.h>
#include <maya/MSelectionList.h>
#include <maya/MItSelectionList.h>
#include <maya/MCommandResult.h>

class getMeshPoint : public MPxCommand


{

public:
getMeshPoint();
virtual ~getMeshPoint();

MStatus doIt( const MArgList& );

static void* creator();


};

//---------------------

void* getMeshPoint::creator()
{
return new getMeshPoint();
}

getMeshPoint::getMeshPoint(){}

getMeshPoint::~getMeshPoint(){}

//-------------------------

MStatus getMeshPoint::doIt( const MArgList& args )


{
MStatus stat;

MSelectionList selList;
MDagPath dagPath;
MObject geo;
MPointArray vertex;
MPointArray Vlist;
//get first object selected
MGlobal::getActiveSelectionList( selList );
stat=selList.getDagPath(0,dagPath);

if ( dagPath.fullPathName()=="" ){
cout<<"No Geometry selected."<<endl;
return stat;
}

//print name of obj


cout<<"\n"<<dagPath.fullPathName()<<endl;

//referencing to the selected obj


MItMeshPolygon poly(dagPath,geo);

unsigned int i=0, j;

//iterate for each polygon


while(poly.isDone()==false){
poly.getPoints(vertex); //get all points for each polygon
for(i=0; i<vertex.length();i++){ //iterate for each points on each polygon
Vlist.append(vertex[i]); //add points coord to array
}
poly.next();
}

//print all points of geometry


for(j=0; j<Vlist.length(); j++)
cout<<Vlist[j]<<endl;

return stat;
}

//-------------------------------

MStatus initializePlugin( MObject obj )


{
MStatus status;
MFnPlugin plugin( obj, "Domingos Silva", "1.0", "2009");

status = plugin.registerCommand( "getPoints", getMeshPoint::creator );


if (!status) {
status.perror("registerCommand");
return status;
}

return status;
}

MStatus uninitializePlugin( MObject obj )


{
MStatus status;
MFnPlugin plugin( obj );

status = plugin.deregisterCommand( "getPoints" );


if (!status) {
status.perror("deregisterCommand");
return status;
}

return status;
}

You might also like