cpp maya plugin example


dashuai009/cpp-maya-plugins

This is an example collection of cpp maya plugins, sourced fromautodesk website.

Setting-up-your-build

how can I get these code?

I use a Python crawler, in 1cpp_maya_plugins to get these code.

Develop

First,

1cmake_minimum_required(VERSION 3.26)
2project(maya_plugins)
3
4set(CMAKE_CXX_STANDARD 17)
5
6# set maya include path
7set(MAYA_PATH "C:/Program Files/Autodesk/Maya2022")
8include_directories(${MAYA_PATH}/include)
9link_directories(${MAYA_PATH}/lib)
10set(LINK_FLAGS "/export:initializePlugin /export:uninitializePlugin")
11# Maya plug-ins that consist of a single file and are intended for your own individual use or for use within your organization can be distributed by placing the files in a shared directory pointed at by the MAYA_PLUG_IN_PATH in users' Maya.env files.
12
13# You can add several directories to MAYA_PLUG_IN_PATH. Each directory must be separated by a semicolon (;) on Windows or by a colon (:) on macOS and Linux.
14
15set(MAYA_PLUG_IN_PATH "C:/Users/User/work/maya-plugins/out")
16
17add_subdirectory(helloWorld)
18add_subdirectory(pickCmd)
19add_subdirectory(pluginCallbacks)
20add_subdirectory(zoomCameraCmd)

for every single plugin in subdirectry:

1cmake_minimum_required(VERSION 3.26)
2project(pickCmd)
3
4message(${PROJECT_NAME})
5# output a dll
6add_library(${PROJECT_NAME} SHARED pickCmd.cpp)
7
8# set the suffix of the output dynamic library to .mll,
9# and directly put it into ourself plugin dirs
10set_target_properties(
11 ${PROJECT_NAME}
12 PROPERTIES
13 SUFFIX ".mll"
14 RUNTIME_OUTPUT_DIRECTORY_DEBUG "${MAYA_PLUG_IN_PATH}/plug-ins") # debug
15
16#set_target_properties(${PROJECT_NAME} PROPERTIES RELEASE_POSTFIX ".mll")
17
18# These two libs are only the core modules of Maya. If you need to use other modules, you need to add other libs, such as OpenMayaUI.lib. You can find all of them in `${MAYA_PATH}/lib`
19target_link_libraries(${PROJECT_NAME} Foundation OpenMaya)

Build