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.13)

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:

Note: If you are using macOS on a machine with an Apple Silicon chip, you will also need to set the architecture:

cmake -H. -Bbuild -G Xcode -DCMAKE_OSX_ARCHITECTURES=x86_64

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.