#include <maya/MFnPlugin.h>
#include <maya/MPxCommand.h>
#include <maya/MGlobal.h>
#include <maya/MSelectionList.h>
#include <maya/MItSelectionList.h>
#include <maya/MObject.h>
#include <maya/MDagPath.h>
#include <maya/MItMeshVertex.h>
#include <maya/MItMeshEdge.h>
class convertVerticesToContainedEdgesCommand :
public MPxCommand
{
public:
convertVerticesToContainedEdgesCommand();
virtual ~convertVerticesToContainedEdgesCommand();
static void* creator();
private:
};
convertVerticesToContainedEdgesCommand::convertVerticesToContainedEdgesCommand()
{
}
convertVerticesToContainedEdgesCommand::~convertVerticesToContainedEdgesCommand()
{
previousSelectionList.
clear();
}
void* convertVerticesToContainedEdgesCommand::creator()
{
return new convertVerticesToContainedEdgesCommand;
}
bool convertVerticesToContainedEdgesCommand::isUndoable() const
{
return true;
}
{
return redoIt();
}
MStatus convertVerticesToContainedEdgesCommand::redoIt()
{
MObject multiVertexComponent, singleVertexComponent;
int dummyIndex;
{
vertexComponentIter.getDagPath(meshDagPath, multiVertexComponent);
if (!multiVertexComponent.
isNull())
{
for (
MItMeshVertex vertexIter(meshDagPath, multiVertexComponent); !vertexIter.
isDone(); vertexIter.next())
{
vertexIter.getConnectedEdges(connectedEdgesIndices);
for (
unsigned i=0; i<connectedEdgesIndices.
length(); i++)
{
edgeIter.setIndex(connectedEdgesIndices[i], dummyIndex);
vertexName += ".vtx[";
vertexName += edgeIter.
index(0);
vertexName += "]";
singleVertexList.
add(vertexName);
singleVertexList.
getDagPath(0, meshDagPath, singleVertexComponent);
if (!singleVertexComponent.
isNull() && previousSelectionList.hasItem(meshDagPath, singleVertexComponent))
{
singleVertexList.
clear();
vertexName = meshName;
vertexName += ".vtx[";
vertexName += edgeIter.
index(1);
vertexName += "]";
singleVertexList.
add(vertexName);
singleVertexList.
getDagPath(0, meshDagPath, singleVertexComponent);
if (!singleVertexComponent.
isNull() && previousSelectionList.hasItem(meshDagPath, singleVertexComponent))
{
edgeName += ".e[";
edgeName += connectedEdgesIndices[i];
edgeName += "]";
finalEdgesSelection.
add(edgeName);
}
}
}
}
}
}
}
MStatus convertVerticesToContainedEdgesCommand::undoIt()
{
}
{
MFnPlugin plugin(obj, PLUGIN_COMPANY,
"4.0",
"Any");
status = plugin.registerCommand("convertVerticesToEdges", convertVerticesToContainedEdgesCommand::creator);
if (!status)
{
status.
perror(
"registerCommand");
return status;
}
return status;
}
{
status = plugin.deregisterCommand("convertVerticesToEdges");
if (!status)
{
status.
perror(
"deregisterCommand");
return status;
}
return status;
}