Setting up your C++ Hello World example project
As a first exercise in creating a command plug-in, create a command plug-in that prints "Hello World" in the Maya output window.
After setting up your environment according to the instructions in Setting up your build environment, create a directory called helloWorld
and create your helloWorld.cpp
file in that directory.
You can use any editor or IDE to write your code. You will use CMake to generate a Visual Studio project, an Xcode project, or a makefile with which to build your plug-in.
Copy the C++ code to your helloWorld.cpp
file. A walkthrough of this code is provided in A C++ Hello World example explained.
Create a CMakeLists.txt
file for this project and save it to the helloWorld
directory:
cmake_minimum_required(VERSION 3.22.1)
set(PROJECT_NAME helloWorld)
project(${PROJECT_NAME})
include($ENV{DEVKIT_LOCATION}/cmake/pluginEntry.cmake)
set(SOURCE_FILES
helloWorld.cpp
)
set(LIBRARIES
OpenMaya Foundation
)
build_plugin()
Use CMake to generate a project for your code:
cmake -H. -Bbuild -G "Visual Studio 17 2022"
to generate a Visual Studio projectcmake -H. -Bbuild -G Xcode
to generate an Xcode projectcmake -H. -Bbuild -G "Unix Makefiles"
to generate a makefile
On macOS you can optionally choose to generate a project for both arm64 architectures and Intel x86_64 architectures. See Building with cmake for more information.
Once you have generate your project or makefile, you can either open the project in Visual Studio or Xcode and build your plug-in from there, or use CMake again to build your plug-in:
cmake --build build
You can now load your plug-in into Maya using the Plug-in Manager, which is accessed from Window > Settings/Preferences > Plug-in Manager from the Maya menu.
Once loaded, run helloWorld
from the Maya command window:
Your greeting will be printed to the Maya output window.