A ColorSwatchGroup stores multiple colors as maxon::ColorA. The group itself and the colors can be selected. ColorSwatchGroup elements are stored and handled using ColorSwatchData objects. The class is defined in the lib_colorchooser.h header file.

// This example loops through all colors of all color groups of the given BaseDocument.
// For each selected color a new material is created.
// load document color swatches
ColorSwatchData* const colorSwatchData = ColorSwatchData::Alloc(doc, false);
if (colorSwatchData == nullptr)
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
// AutoFree takes ownership
// loop through groups
const Int groupCount = colorSwatchData->GetGroupCount();
for (Int i = 0; i < groupCount; ++i)
ColorSwatchGroup* group = colorSwatchData->GetGroupAtIndex(i);
if (group)
// loop through colors
const Int colorCount = group->GetColorCount();
for (Int c = 0; c < colorCount; ++c)
Bool selected = false;
// get color and check if it is selected
if (group->GetColor(c, color, &selected) && selected)
// create new material
Material* const mat = Material::Alloc();
if (mat == nullptr)
return maxon::OutOfMemoryError(MAXON_SOURCE_LOCATION);
// use color
const Vector rgb { color.r, color.g, color.b };
Definition: ge_autoptr.h:152
void Assign(TYPE *p)
Definition: ge_autoptr.h:225
Bool SetParameter(const DescID &id, const GeData &t_data, DESCFLAGS_SET flags)
Definition: lib_colorchooser.h:406
ColorSwatchGroup * GetGroupAtIndex(Int index, SWATCH_CATEGORY category=SWATCH_CATEGORY::DOCUMENT)
static ColorSwatchData * Alloc(BaseDocument *doc=nullptr, Bool global=false)
Definition: lib_colorchooser.h:218
Bool GetColor(Int index, maxon::ColorA &color, Bool *selected=nullptr) const
Int GetColorCount() const
Definition: c4d_basematerial.h:241
static Material * Alloc()
maxon::Bool Bool
Definition: ge_sys_math.h:55
maxon::Int Int
Definition: ge_sys_math.h:64
Definition: memoryallocationbase.h:67
Definition: mmaterial.h:56
A color consisting of three components R, G, B and an alpha.
Definition: col4.h:16
T r
Definition: col4.h:33
T g
Definition: col4.h:34
T b
Definition: col4.h:35


ColorSwatchGroups can be created using the usual tools. This is typically not needed.


ColorSwatchGroup elements are stored in a ColorSwatchData object. See ColorSwatchData Color Groups


A ColorSwatchGroup can be selected:

// This example loops through all groups and prints the names of the selected groups.
const Int groupCount = colorSwatchData->GetGroupCount();
for (Int i = 0; i < groupCount; ++i)
const ColorSwatchGroup* const group = colorSwatchData->GetGroupAtIndex(i);
if (group == nullptr)
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
// check if a group could be accessed
// and if that group is selected
if (group->IsGroupSelected())
ApplicationOutput("Group " + group->GetName() + " is selected.");
String GetName() const
Bool IsGroupSelected() const
#define ApplicationOutput(formatString,...)
Definition: debugdiagnostics.h:210


A ColorSwatchGroup can be identified by a name:

// This example adds a new color group.
ColorSwatchGroup* const group = colorSwatchData->AddGroup();
if (group == nullptr)
return maxon::OutOfMemoryError(MAXON_SOURCE_LOCATION);
group->SetName("This is a new group");
ColorSwatchGroup * AddGroup(SWATCH_CATEGORY category=SWATCH_CATEGORY::DOCUMENT, const String &name=String(), Bool selected=false, Int insertAt=-1, const ColorAlphaArray &colors=ColorAlphaArray())
void SetName(String name)


A ColorSwatchGroup stores multiple colors and their selection state. The colors are obtained with:

// This example prints the values of all colors of the given group.
const Int colorCount = group->GetColorCount();
for (Int c = 0; c < colorCount; ++c)
// access the color with the index 'c'
if (!group->GetColor(c, color))
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
ApplicationOutput("Color: @", color);

Colors can be edited with:

New colors are added with:

// This example adds ten random colors to the given group.
Random random;
for (Int c = 0; c < 10; ++c)
const maxon::Float r = random.Get01();
const maxon::Float g = random.Get01();
const maxon::Float b = random.Get01();
const maxon::ColorA color(r, g, b, 1.0);
group->AddColor(color, false);
void SortColors()
Sorts colors in the group based in their HSV values.
Int AddColor(const maxon::ColorA &color, Bool selected=false, Int insertAt=-1)
Definition: c4d_tools.h:812
Float Get01(void)
Float64 Float
Definition: apibase.h:199

The selection status of a color can be utilized with these functions:

Further utility functions are:

Further Reading