How to use VisualC++ for Maya Plug-in
I'm writing These for Maya animator who want to know how to start writting own Plug-in.Now Microsoft give us Visual C++ as Free.
It's good chance to learn how to make plug-in for Maya without any costs.
1.How to install and setting Microsoft Visual C++ 2005 Express Edition
Referencehttp://www.awug.dk/community/index.php?action=profile;u=2;sa=showPosts
- Download and install Microsoft Visual C++ 2005 Express Edition
http://lab.msdn.microsoft.com/express/visualc/default.aspx
(or Microsoft Visual C++ 2005 Express Edition Japanese version)
http://www.microsoft.com/japan/msdn/vstudio/express/visualc/
- Download and install Microsoft Platform SDK for x86.
http://www.microsoft.com/downloads/details.aspx?FamilyId=A55B6B43-E24F-4EA3-A93E-40C0EC4F68E5&displaylang=en
-How to install PlatformSDK(I'm explaining it in this document)
http://msdn.microsoft.com/vstudio/express/visualc/usingpsdk/
Then Open C:\Program Files\Microsoft Visual Studio 8\VC\VCProjectDefaults\corewin_express.vsprops
Replace
AdditionalDependencies="kernel32.lib"
to
AdditionalDependencies="kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib"
Save and Close.
Then Start Visutal C++ 2005 Express Edition
from menu, Tool -> Options -> Projects and Solutions -> VC++ Directories
Show directories for: Include/Library/Executable Files:
Include: C:\Program Files\Alias\Maya7.0\include and C:\Program Files\Microsoft Platform SDK\Include
Library: C:\Program Files\Alias\Maya7.0\lib and C:\Program Files\Microsoft Platform SDK\Lib
Execute: C:\Program Files\Alias\Maya7.0\bin and C:\Program Files\Microsoft Platform SDK\Bin
- Below is setting of project. Maybe you might need to set each time when you make new project.
(Gray lines are not necessary)
from menu, Project -> Properties
Configuration Properties -> General -> Configuration Type: Dynamic Library (.dll).
C/C++ -> General -> Additional Include Directories:C:\Program Files\Alias\Maya7.0\include; C:\Program Files\Microsoft Platform SDK\Include
C/C++ -> Preprocesser -> Preprocessor Definations: WIN32;_DEBUG;_WINDOWS;_USRDLL;NT_PLUGIN
If you are using iostream, also you need to add REQUIRE_IOSTREAM.
and be careful. this option has small difference between debug and release.
C/C++ -> Code Generation -> Runtime Library: Multi Threaded or Multi-threaded Debug DLL (/MDd)
Linker -> General -> Output file: yourProject.mll
Linker -> General -> Additional Library Directories: C:\Program Files\Alias\Maya7.0\lib; C:\Program Files\Microsoft Platform SDK\Lib
Linker -> Input ->Additional Dependencies:odbc32.lib odbccp32.lib OpenMaya.lib Foundation.lib
Linker -> Command Line -> Additional Options: /export:initializePlugin /export:uninitializePlugin
2.Project Settings
VC8 can't use Maya7 plug-in wizard.
Actually you don't need to use that, but you might be confused about project setting.
Below lists are the project settings made by Plug-inWizard with VC7.
I also attached VC8 setting converted from VC7 project.
General

Debugging

Command and Symbol Path is empty when I open the HelloWorldProject with VC7.
CPP>General

Additional Include Directories
..\..\include
Debug Information Foramt
Program Database for Edit & Continue(/ZI)(Debug Mode)
CPP>Optimization

CPP>Preprocessor

There are no _AFXDLL and _MBCS in helloWorldProject.
CPP>CodeGeneration

Only Release mode of helloWorld, It has
Enable String Pooling Yes(/GF)
Enable Function-Level Linking Yes(/Gy)
CPP>Language

Everything No in HelloWorld.
CPP>Precompiled Headers

CPP>OutputFiles

helloWorld is
ASM List Location .\Debug/
Object File Name .\Debug/
Program Database File Name .\Debug/
CPP>BrowseInformation

CPP>Advanced

Compile As Default in HelloWorld.
CPP>CommandLine

Linker>General

Enable Incremental Linking No(/INCREMENTAL:NO)
Suppress Startup Banner Yes(/NOLOGO)
Additional Library Directories ..\..\lib
Linker>Input

In HelloWorldProject, Additional Dependencies Also have
odbc32.lib
odbccp32.lib
Linker>Debugging

Linker>System

InHelloWorldProject, SubSystem is
Windows(/SUBSYSTEM:WINDOWS)
Linker>Optimization

Linker>EmbeddedIDL

Linker>Advanced

InHelloWorldProject,Target Machine is
MachineX86(/MACHINE:X86)
Linker>CommandLine

InHelloWorldProject, There are only
/export:initializePlugin /export:uninitializePlugin
3.How to solve Error
These are my experiences.
If you got any problem when compiling&building your program, just check these examples.
error LNK2001: unresolved external symbol "public: virtual bool __thiscall MPxCommand::hasSyntax(void)const "
Make sure your prject setting is correct.
C/C++ -> Preprocesser -> Preprocessor Definations: WIN32;_DEBUG;_WINDOWS;_USRDLL;NT_PLUGIN
Linker -> Input ->Additional Dependencies:odbc32.lib odbccp32.lib OpenMaya.lib Foundation.lib
error C2872: 'ostream' : ambiguous symbol
or
error C2065: 'cerr' : undeclared identifier
include <iostream> and add REQUIRE_IOSTREAM to
C/C++ -> Preprocesser -> Preprocessor Definations
fatal error LNK1104: compiler can't open 'libcimtd.lib'
.Net 2002 code compiled with .Net 2003.
libcimtd.lib is used with old iostream lib. and .Net2003 doesn't support this.
change <iostream.h> to <iostream>
and also you might need to add this after this line.
using namespece std;
error C2065: 'i' : undeclared identifier
if your code has such aline like his
for (i=0;i<numSurface;i++)
you had better change it to
int i=0;
for (;i<numSurface;i++)
Maybe C++ need to define everything even such a small variable.
error LNK2001: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall-----
error LNK2001: unresolved external symbol "__declspec(dllimport) public: void __thiscall-------
Include the library:
OpenMayaUI.lib
error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall MFnParticleSystem::MFnParticleSystem(void)"
Include the library:
OpenMayaFX.lib
Error: line 1: initializePlugin function could not be found in plug-in (your plug-in) //
check project propaty and make sure all include&lib is correct version of Maya.
and make sureLinker>command Line contains
/export:initializePlugin /export:uninitializePlugin
debug is ok, release was error.But mll was created.
Linker>General>Redister Output No
(I'm not sure...)
LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
libcpmtd.lib(xdebug.obj) : error LNK2019: unresolved external symbol __malloc_dbg referenced in function "void * __cdecl operator new(unsigned int,struct std::_DebugHeapTag_t const &,char *,int)" (??2@YAPAXIABU_DebugHeapTag_t@std@@PADH@Z)
libcpmtd.lib(xdebug.obj) : error LNK2019: unresolved external symbol __free_dbg referenced in function "void __cdecl operator delete(void *,struct std::_DebugHeapTag_t const &,char *,int)" (??3@YAXPAXABU_DebugHeapTag_t@std@@PADH@Z)
I got this trouble when I changed Multi-thread DLL to Multi-thread.
Remove _DEBUG from Preprocessor Definitions.
My plug-in works OK with my PC, but it doesn't work with other machine.
(Environment issue: Visual C++ 2005 Express)
Change Multi-thread DLL to Multi-thread.
It will include librarys inside DLL. Plug-in file size will become bigger.
Delete all additional include file except OpenMaya.lib Foundation.lib.
odbc32.lib odbccp32.lib OpenMaya.lib Foundation.lib -> OpenMaya.lib Foundation.lib
At leaset, You had better Remove _DEBUG!
Details
4.Technique
How to put message1) Put your message into Maya scriptEditor.
MString tmpStr = ( "Values: " );
tmpStr += (value);
MGlobal::displayInfo(tmpStr);
(*of course you need to define these value previously.)
2) Output to OutputWindow.
cout << "inputGeometry1 " << inputGeometry.apiTypeStr()<< endl;
cerr << "aaa"<< endl;
you don't need to care about type of variable with this way. that's good point.
Although, you might need to include iostream.
5.Reference
My recommended!http://www.robthebloke.org/
http://www.comet-cartoons.com/
http://www.max.hi-ho.ne.jp/kotamura/welcome/
http://www.davidgould.com/(Good book)
Japanese pages below.
http://hohehohe2.hp.infoseek.co.jp/
http://www009.upp.so-net.ne.jp/minecorp/
http://www.not-enough.org/abe/manual//openmaya-au02/start.html
http://www.alias.co.jp/products-services/maya/pdf/apiquickstart.pdf
MessageBoard
|
3DCG
|
Siggraph004
|
EnglishDiary
|
Gallery
|
Return to top
copyright(c) 2001-2005 Hajime Nakamura
copyright(c) 2001-2005 Hajime Nakamura