Maya+VS编程入门初体验(HelloWorld)

Maya2018 + VS2017 环境搭建见 博客

1. 项目:

VS 新建了一个 MEL Command类型的项目(MayaProject)

2. HelloWorld代码

#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文件

4. 把mll文件拷贝到C:\MyProgram\AutoDesk\Maya2018\bin\plug-ins目录下,然后重新打开maya

菜单->窗口->设置/首选项->插件管理器

MayaProject插件加载进来

5. 在maya底部的MEL脚本编辑器中输入脚本,对插件进行测试

6. 脚本编辑器显示 结果

 

 

 

 

 

 附一个创建球模型的代码:(我还没有运行出来)

//
// 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)

 

posted @ 2019-06-04 16:07  Not-Bad  阅读(1347)  评论(0编辑  收藏  举报