ColorSwatchData Manual

内容表

关于

A ColorSwatchData object can manage multiple color groups. These color groups can be loaded globally from Cinema 4D 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.

// 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 AutoFree<ColorSwatchData> freeData; freeData. 赋值 (colorSwatchData);

// 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) { maxon::ColorA color; Bool selected = false ;

// get color and check if it is selected if (group-> GetColor (c, color, &selected) && selected) { // create new material 材质 * const mat = Material::Alloc (); if (mat == nullptr ) return maxon::OutOfMemoryError( MAXON_SOURCE_LOCATION );

// use color const 向量 rgb { color. r , color. g , color. b }; mat-> SetParameter ( MATERIAL_COLOR_COLOR , rgb, DESCFLAGS_SET::NONE ); doc-> InsertMaterial (mat); } } } }

Allocation/Deallocation

ColorSwatchData instances are created with the usual tools:

// This example allocates a new ColorSwatchData object. // During allocation the color groups of the given BaseDocument are automatically loaded. ColorSwatchData * data = ColorSwatchData::Alloc (doc, false ); if (data == nullptr ) return maxon::OutOfMemoryError( MAXON_SOURCE_LOCATION ); const Int groupCount = data-> GetGroupCount (); ApplicationOutput ( "The document contains " + String::IntToString (groupCount) + " color groups" ); ColorSwatchData::Free (data);

Document Colors

Color groups can be stored in a BaseDocument :

// This example loads a Cinema 4D scene file. // The color swatches of this file are loaded into the given ColorSwatchData object. // The merged colors are saved back to the original document.

// load colors of the original if (!colorSwatchData-> Load (doc)) return maxon::UnexpectedError( MAXON_SOURCE_LOCATION );

// select the scene file Filename sceneFile;

// open a dialog to select a file if (!sceneFile. FileSelect ( FILESELECTTYPE::SCENES , FILESELECT::LOAD , "Select File" _s)) return maxon::OK ;

// load the scene file BaseDocument * loadedDoc = LoadDocument (sceneFile, SCENEFILTER::NONE , nullptr ); if (loadedDoc == nullptr ) return maxon::IoError( MAXON_SOURCE_LOCATION , MaxonConvert (sceneFile, MAXONCONVERTMODE::NONE ), "Could not load document." _s);

// merge the scene file colors colorSwatchData-> Load (loadedDoc, true ); // store merged colors back into the BaseDocument colorSwatchData-> Save (doc); BaseDocument::Free (loadedDoc);

预置

Color swatches can also be stored in the preset library:

To make work with presets easier these utility functions exist:

// This example checks if a color swatches preset with the given name already exists. // If not, the preset is created. const String presetName( "myColorPreset" );

// check if preset already exists if (! ColorSwatchData::PresetExists (presetName)) { // construct url SDKBrowserURL presetUrl = ColorSwatchData::GetPresetDirectory (); presetUrl += presetName;

// save preset if (!colorSwatchData-> SavePreset (presetUrl, "User" , "This is my preset" )) return maxon::UnknownError( MAXON_SOURCE_LOCATION ); }

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

// This example adds a new group to the given ColorSwatchData. // Then the name of each group is printed. colorSwatchData-> AddGroup ( SWATCH_CATEGORY::DOCUMENT , "New Group" ); const Int groupCount = colorSwatchData-> GetGroupCount ( SWATCH_CATEGORY::DOCUMENT ); for ( Int i = 0; i < groupCount; ++i) { const ColorSwatchGroup * const group = colorSwatchData-> GetGroupAtIndex (i, SWATCH_CATEGORY::DOCUMENT ); if (group != nullptr ) { ApplicationOutput ( "Group Name: " + group-> GetName ()); } }

Further utility functions are:

延伸阅读

maxon::Col4::b
T b
定义: col4.h:35
Int
maxon::Int Int
定义: ge_sys_math.h:62
ColorSwatchData::SavePreset
Bool SavePreset(const String &name, const String &author=String(), const String &info=String(), Bool forceOverwrite=false)
ColorSwatchData
定义: lib_colorchooser.h:405
FILESELECTTYPE::SCENES
@ SCENES
3D scene files.
ColorSwatchData::Free
static void Free(ColorSwatchData *&p)
AutoFree::Assign
void Assign(TYPE *p)
定义: ge_autoptr.h:225
maxon::Col4::r
T r
定义: col4.h:33
ColorSwatchData::Load
Bool Load(BaseDocument *doc, Bool merge=false, Bool loadGlobalColors=false)
SDKBrowserURL
定义: lib_browser.h:70
SCENEFILTER::NONE
@ NONE
None.
Filename
Manages file and path names.
定义: c4d_file.h:93
maxon::OK
return OK
定义: apibase.h:2532
AutoFree
定义: ge_autoptr.h:151
LoadDocument
BaseDocument * LoadDocument(const Filename &name, SCENEFILTER loadflags, BaseThread *thread, maxon::String *errorString=nullptr)
ColorSwatchGroup::GetColorCount
Int GetColorCount() const
ColorSwatchGroup::GetName
String GetName() const
MAXONCONVERTMODE::NONE
@ NONE
No check if file exists under case-sensitive drives.
MAXON_SOURCE_LOCATION
#define MAXON_SOURCE_LOCATION
定义: memoryallocationbase.h:66
DESCFLAGS_SET::NONE
@ NONE
None.
ColorSwatchData::GetGroupAtIndex
ColorSwatchGroup * GetGroupAtIndex(Int index, SWATCH_CATEGORY category=SWATCH_CATEGORY::DOCUMENT)
MaxonConvert
maxon::Url MaxonConvert(const Filename &fn, MAXONCONVERTMODE convertMode)
String
定义: c4d_string.h:38
maxon::Col4
A color consisting of three components R, G, B and an alpha.
定义: col4.h:14
BaseDocument::InsertMaterial
void InsertMaterial(BaseMaterial *mat, BaseMaterial *pred=nullptr, Bool checknames=false)
String::IntToString
static String IntToString(Int32 v)
定义: c4d_string.h:495
ColorSwatchData::Save
Bool Save(BaseDocument *doc, Bool saveGlobalColors=false)
C4DAtom::SetParameter
Bool SetParameter(const DescID &id, const GeData &t_data, DESCFLAGS_SET flags)
ColorSwatchData::PresetExists
static Bool PresetExists(const String &name, maxon::BaseArray< SDKBrowserURL > *urls=nullptr)
maxon::Vec3< maxon::Float64, 1 >
材质
定义: c4d_basematerial.h:240
Material::Alloc
static Material * Alloc()
ColorSwatchData::Alloc
static ColorSwatchData * Alloc(BaseDocument *doc=nullptr, Bool global=false)
ColorSwatchGroup
定义: lib_colorchooser.h:217
ApplicationOutput
#define ApplicationOutput(formatString,...)
定义: debugdiagnostics.h:207
BaseDocument::Free
static void Free(BaseDocument *&bl)
maxon::Col4::g
T g
定义: col4.h:34
FILESELECT::LOAD
@ LOAD
Load dialog.
ColorSwatchData::GetGroupCount
Int GetGroupCount(SWATCH_CATEGORY category=SWATCH_CATEGORY::DOCUMENT) const
Bool
maxon::Bool Bool
定义: ge_sys_math.h:53
MATERIAL_COLOR_COLOR
@ MATERIAL_COLOR_COLOR
定义: mmaterial.h:56
ColorSwatchData::AddGroup
ColorSwatchGroup * AddGroup(SWATCH_CATEGORY category=SWATCH_CATEGORY::DOCUMENT, const String &name=String(), Bool selected=false, Int insertAt=-1, const ColorAlphaArray &colors=ColorAlphaArray())
ColorSwatchData::GetPresetDirectory
static SDKBrowserURL GetPresetDirectory()
BaseDocument
定义: c4d_basedocument.h:490
ColorSwatchGroup::GetColor
Bool GetColor(Int index, maxon::ColorA &color, Bool *selected=nullptr) const
Filename::FileSelect
Bool FileSelect(FILESELECTTYPE type, FILESELECT flags, const maxon::String &title, const maxon::String &force_suffix=maxon::String())
SWATCH_CATEGORY::DOCUMENT
@ DOCUMENT

Copyright  © 2014-2025 乐数软件    

工业和信息化部: 粤ICP备14079481号-1