About
A ColorSwatchData object can manage multiple color groups. These color groups can be loaded globally from Cinema 4D, a BaseDocument or a preset and saved back to these sources. Local color groups and global color groups are stored separately. The class is defined in the lib_colorchooser.h header file.
  
  
 
  
  ColorSwatchData* 
const colorSwatchData = ColorSwatchData::Alloc(
doc, 
false);
 
  if (colorSwatchData == nullptr)
 
  
  AutoFree<ColorSwatchData> freeData;
  freeData.Assign(colorSwatchData);
 
  
  const Int groupCount = colorSwatchData->GetGroupCount();
 
 
  for (
Int i = 0; 
i < groupCount; ++
i)
 
  {
    ColorSwatchGroup* group = colorSwatchData->GetGroupAtIndex(
i);
 
    if (group)
    {
      
      const Int colorCount = group->GetColorCount();
 
 
      for (
Int c = 0; 
c < colorCount; ++
c)
 
      {
 
        
        if (group->GetColor(
c, color, &selected) && selected)
 
        {
          
          Material* const mat = Material::Alloc();
          if (mat == nullptr)
 
          
          const Vector rgb { color.
r, color.
g, color.
b };
 
          doc->InsertMaterial(mat);
 
        }
      }
    }
  }
Py_ssize_t i
Definition: abstract.h:645
 
NONE
Definition: asset_browser.h:1
 
Py_UNICODE c
Definition: unicodeobject.h:1200
 
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:69
 
#define ConstDescID(...)
Definition: lib_description.h:592
 
@ MATERIAL_COLOR_COLOR
Definition: mmaterial.h:56
 
maxon::Bool Bool
Definition: ge_sys_math.h:46
 
maxon::Int Int
Definition: ge_sys_math.h:55
 
maxon::Vec3< maxon::Float64, 1 > Vector
Definition: ge_math.h:140
 
const char * doc
Definition: pyerrors.h:226
 
A color consisting of three components R, G, B and an alpha.
Definition: col4.h:16
 
  
Allocation/Deallocation
ColorSwatchData instances are created with the usual tools:
- ColorSwatchData::Alloc(): Creates a new ColorSwatchData object. If the second argument is set to true, the global group is loaded.
 
- ColorSwatchData::Free(): Destroys the given ColorSwatchData.
 
  
  
 
  ColorSwatchData* data = ColorSwatchData::Alloc(
doc, 
false);
 
  if (data == nullptr)
 
  const Int groupCount = data->GetGroupCount();
 
  ApplicationOutput(
"The document contains " + String::IntToString(groupCount) + 
" color groups");
 
 
  ColorSwatchData::Free(data);
#define ApplicationOutput(formatString,...)
Definition: debugdiagnostics.h:204
 
  
Document Colors
Color groups can be stored in a BaseDocument:
- ColorSwatchData::Load(): Loads the color groups from the given BaseDocument.
 
- ColorSwatchData::Save(): Saves the color groups to the given BaseDocument.
 
  
  
  
 
  
  if (!colorSwatchData->Load(
doc))
 
 
  
  Filename sceneFile;
 
  
 
  
  if (loadedDoc == nullptr)
 
  
  colorSwatchData->Load(loadedDoc, true);
  
  colorSwatchData->Save(
doc);
 
 
  BaseDocument::Free(loadedDoc);
SCENES
Filter for scene files only.
Definition: asset_browser.h:6
 
LOAD
Load.
Definition: c4d_filterdata.h:1
 
return OK
Definition: apibase.h:2740
 
BaseDocument * LoadDocument(const Filename &name, SCENEFILTER loadflags, BaseThread *thread, maxon::String *errorString=nullptr, const ProgressDelegate &progressDelegate=ProgressDelegate())
 
maxon::Url MaxonConvert(const Filename &fn, MAXONCONVERTMODE convertMode)
 
  
Presets
Color swatches can also be stored in the preset library:
- ColorSwatchData::LoadPreset(): Loads the color groups from the given preset.
 
- ColorSwatchData::SavePreset(): Saves the color gorups to the given preset.
 
To make work with presets easier these utility functions exist:
- ColorSwatchData::PresetExists(): Returns true if the given preset name already exists.
 
- ColorSwatchData::ValidPreset(): Returns true if the given URL points to a valid preset.
 
- ColorSwatchData::GetPresetDirectory(): Returns the user's default Color Swatch Preset directory.
 
- ColorSwatchData::browserPresetType: The ID of color swatch preset objects.
 
 
Color Groups
The color swatches stored in a ColorSwatchData are stored in groups. These groups can either be stored with the document (SWATCH_CATEGORY::DOCUMENT) or with Cinema 4D itself (SWATCH_CATEGORY::GLOBAL).
- ColorSwatchData::GetGroupCount(): Returns the number of groups stored.
 
- ColorSwatchData::GetGroupAtIndex(): Returns the group stored at the given index.
 
- ColorSwatchData::AddGroup(): Adds a new group to the ColorSwatchData.
 
- ColorSwatchData::SetGroupAtIndex(): Replaces the group at given index.
 
- ColorSwatchData::InsertGroup(): Adds the given group.
 
- ColorSwatchData::RemoveGroup(): Removes the group with the given index.
 
- ColorSwatchData::RemoveSelectedItems(): Removes selected groups and colors.
 
  
  
 
 
  for (
Int i = 0; 
i < groupCount; ++
i)
 
  {
    if (group != nullptr)
    {
    }
  }
DOCUMENT
Document settings mode.
Definition: lib_activeobjectmanager.h:15
 
 Further utility functions are:
- ColorSwatchData::Merge(): Merges the groups with the groups stored in the given object.
 
- ColorSwatchData::CopyFrom(): Copies the data from the given ColorSwatchData object.
 
- ColorSwatchData::Reset(): Removes all stored groups and colors, including globals.
 
Further Reading