Maya2018 + VS2017 環境搭建見 博客
html
1. 項目:git
VS 新建了一個 MEL Command類型的項目(MayaProject)github
2. HelloWorld代碼app
#include<maya/MSimple.h> // Use helper macro to register a command with Maya. It creates and // registers a command that does not support undo or redo. The // created class derives off of MPxCommand. // DeclareSimpleCommand( MayaProject, "", "2018"); MStatus sayHello::doIt(const MArgList& args ) { MStatus stat = MS::kSuccess; displayInfo("Hello World!"); // Since this class is derived off of MPxCommand, you can use the // inherited methods to return values and set error messages // setResult( "sayHello command executed!/n" ); return stat; }
3. 運行,debug文件夾中出現了一個mll文件less
4. 把mll文件拷貝到C:\MyProgram\AutoDesk\Maya2018\bin\plug-ins目錄下,而後從新打開maya編輯器
菜單->窗口->設置/首選項->插件管理器ide
MayaProject插件加載進來測試
5. 在maya底部的MEL腳本編輯器中輸入腳本,對插件進行測試this
6. 腳本編輯器顯示 結果spa
附一個建立球模型的代碼:(我尚未運行出來)
// // Copyright (C) // // File: MayaProjectCmd.cpp // // MEL Command: MayaProject // // Author: Maya Plug-in Wizard 2.0 // // Includes everything needed to register a simple MEL command with Maya. // #include <maya/MSimple.h> #include <maya/MGlobal.h> #include <maya/MDagPath.h> #include <maya/MSelectionList.h> #include <maya/MFnDagNode.h> #include <maya/MIOStream.h> #include <maya/MFnMesh.h> #include <maya/MFloatPointArray.h> #include <maya/MString.h> #include <maya/MItSelectionList.h> #include <maya/MItMeshVertex.h> #include <maya/MStringArray.h> // Use helper macro to register a command with Maya. It creates and // registers a command that does not support undo or redo. The // created class derives off of MPxCommand. // DeclareSimpleCommand( MayaProject, "", "2018"); MStatus MayaProject::doIt( const MArgList& args ) // // Description: // implements the MEL MayaProject command. // // Arguments: // args - the argument list that was passes to the command from MEL // // Return Value: // MS::kSuccess - command succeeded // MS::kFailure - command failed (returning this value will cause the // MEL script that is being run to terminate unless the // error is caught using a "catch" statement. // { MStatus stat = MS::kSuccess; MSelectionList selection; MGlobal::getActiveSelectionList(selection); MDagPath dagPath, dagPath_1; MObject component, component_1; MItSelectionList iter(selection); selection.getDagPath(0, dagPath, component); MItMeshVertex meshIter(dagPath, component, &stat); MStringArray verIndexArray; if (stat == MS::kSuccess) { for (; !meshIter.isDone(); meshIter.next()) { MPoint pt = meshIter.position(MSpace::kObject); MItMeshVertex meshIter_1(dagPath); for (; !meshIter_1.isDone(); meshIter_1.next()) { MPoint pt_1 = meshIter_1.position(MSpace::kObject); if (abs(-pt.x - pt_1.x) < 0.01 && abs(pt.y - pt_1.y) < 0.01 && abs(pt.z - pt_1.z) < 0.01) { verIndexArray.append(MString("") + meshIter_1.index()); break; } } } } // Since this class is derived off of MPxCommand, you can use the // inherited methods to return values and set error messages // setResult(verIndexArray ); return stat; }
參考:
https://blog.csdn.net/xdhstc/article/details/40355155(球模型代碼來源)
https://blog.csdn.net/huadingjin/article/details/8083277
https://blog.csdn.net/mincau/article/details/7925520
https://baijiahao.baidu.com/s?id=1608682630689528579&wfr=spider&for=pc(github/WendyAndAndy/MayaDev)