API 过渡

内容表

关于

Cinema 4D R20 introduced significant changes of the C++ API. The new MAXON API was introduced, which is fundamentally different that the previous, classic, API. The classic API is still available in the cinema.framework , but several components of the classic API have been replaced with new MAXON API components.

Any plugin that was written for an earlier SDK (R19 or older) must be adapted and re-compiled to work with Cinema 4D R20.

注意
For API changes introduced with Cinema 4D R15 see Transition to Cinema 4D R15 API .
警告
In future releases more and more parts of the classic API will be replaced with new MAXON API components.

Project Files

由于 Cinema 4D R20 the SDK does no longer contain any project files. The project files for frameworks, plugins and solutions must be created using the project Tool. See 工程工具 .

Code Adaptations

Code Style

The source processor is part of the tool chain to build a plugin (see 源处理器 ). This source processor checks the source code and creates automatically additional code. The processor also checks the code style according to the level that is set in the project's projectdefinition.txt file (see 工程工具 ).

String Resources

The naming scheme of string resource folders was changed. The resource folder that was named "strings_us" is now named "strings_en-US". See 插件资源 .

Namespaces

The complete MAXON API is defined in the maxon namespace. In contrast, the classic API is defined in the global namespace. To avoid collisions and ambiguity it might be necessary to use fully qualified names.

// This example uses explicit namespaces to use new and classic components.

// creating a maxon::String maxon::String helloWorld { "Hello World" };

// creating a classic String ::String fooBar { "FooBar" };

包括

Wherever possible unneeded includes and umbrella includes were removed. It might be necessary to add additional includes to include specific header files explicitly.

Global Resources

The global resources instances has been renamed to g_resource .

// This example loads the plugin's resources when // C4DPL_INIT_SYS is sent to PluginMessage().

case C4DPL_INIT_SYS : { // don't start plugin without resource if ( g_resource . Init () == false ) return false ; return true ; }

Enumerations

Simple enumerations were reformatted as enumeration classes. Since "0" is not a valid enumeration value name it has been replaced with "NONE".

The macro ENUM_END_FLAGS() has been removed. If you have a custom enumeration you have to use MAXON_ENUM_LIST() or MAXON_ENUM_FLAGS() .

// This example uses the enumeration value DESCFLAGS_GET::NONE to use GetParameter(). // In previous versions of Cinema 4D this was DESCFLAGS_GET_0. GeData data; // access the parameter if (cubeObject->GetParameter( PRIM_CUBE_LEN , data, DESCFLAGS_GET::NONE ) == false ) return maxon::UnexpectedError( MAXON_SOURCE_LOCATION );

// get the value const 向量 size = data. GetVector (); DiagnosticOutput ( "Cube Size: @" , size);

Using new Data Types

The MAXON API introduces new data types and replaces or extends classic data types:

// This example creates a sphere object and uses "_s" // to declare a maxon::String to define the name. BaseObject * const sphere = BaseObject::Alloc ( Osphere ); if (sphere == nullptr ) return maxon::OutOfMemoryError( MAXON_SOURCE_LOCATION );

// set the name of the new sphere using a maxon::String sphere-> SetName ( "New Sphere" _s); doc-> InsertObject (sphere, nullptr , nullptr );

错误系统

The MAXON API error system allows functions to return an explicit error state. Several functions of the classic API have been replaced with new functions that do return such an error state e.g. NewObj() or maxon::BaseArray::Append() . It is needed to handle this error state. See Error Handling .

The error system also allows to re-write functions so they return error states. This is extremely helpful to find the source of any error and to write stable code.

// This example shows how errors returned with "iferr_return" can be handled.

// catch any error iferr_scope_handler { // print error to console err.DiagOutput(); // debug stop err.DbgStop(); };

// create and fill array maxon::BaseArray<maxon::Int> intValues; intValues. Append (100) iferr_return ; intValues. Append (200) iferr_return ;

// allocate memory maxon::AutoMem<maxon::Char> buffer = NewMemClear ( maxon::Char , 100) iferr_return ; // access memory buffer[0] = 0;

Terminology

Several functions have been renamed to follow a consistent terminology. Functions like "Content()" that check if a given instance has any content have been renamed to "IsPopulated()" and "IsEmpty()".

// This example uses IsPopulated() and IsEmpty() to check the string.

// create string const maxon::String someText { "some text" };

// check if populated if (someText.IsPopulated()) DiagnosticOutput ( "String is not empty" );

// check if empty if (someText.IsEmpty()) DiagnosticOutput ( "String is empty" );

New Logger System

Cinema 4D R20 introduced a new, complex and adaptable logger system. The standard console is just one of many available loggers now. One can write messages to the standard console using ApplicationOutput() 而不是 GePrint() 。见 LoggerInterface Manual .

// This example prints the given message to both the IDE console and the application console window.

// define message const maxon::String someMessage { "some message" };

// print the message to the console DiagnosticOutput (someMessage);

// print the message to the application console window ApplicationOutput (someMessage);

延伸阅读

BaseDocument::InsertObject
void InsertObject(BaseObject *op, BaseObject *parent, BaseObject *pred, Bool checknames=false)
GeResource::Init
Bool Init()
NewMemClear
#define NewMemClear(T, cnt)
定义: defaultallocator.h:205
BaseObject
定义: c4d_baseobject.h:224
maxon::String
定义: string.h:1197
iferr_return
#define iferr_return
定义: resultbase.h:1434
MAXON_SOURCE_LOCATION
#define MAXON_SOURCE_LOCATION
定义: memoryallocationbase.h:66
maxon::BaseArray
定义: basearray.h:366
DiagnosticOutput
#define DiagnosticOutput(formatString,...)
定义: debugdiagnostics.h:166
Osphere
#define Osphere
Sphere.
定义: ge_prepass.h:1041
String
定义: c4d_string.h:38
maxon::BaseArray::Append
MAXON_ATTRIBUTE_FORCE_INLINE ResultRef< T > Append()
定义: basearray.h:569
maxon::Vec3< maxon::Float64, 1 >
PRIM_CUBE_LEN
@ PRIM_CUBE_LEN
定义: ocube.h:6
GeData
定义: c4d_gedata.h:82
iferr_scope_handler
#define iferr_scope_handler
定义: resultbase.h:1361
BaseList2D::SetName
void SetName(const maxon::String &name)
定义: c4d_baselist.h:2324
ApplicationOutput
#define ApplicationOutput(formatString,...)
定义: debugdiagnostics.h:207
maxon::Char
char Char
signed 8 bit character
定义: apibase.h:180
BaseObject::Alloc
static BaseObject * Alloc(Int32 type)
DESCFLAGS_GET::NONE
@ NONE
None.
g_resource
GeResource g_resource
Global resources for Cinema 4D.
C4DPL_INIT_SYS
#define C4DPL_INIT_SYS
Initialize system.
定义: c4d_plugin.h:28
maxon::BaseRef
定义: apibase.h:1522
GeData::GetVector
const Vector & GetVector(void) const
定义: c4d_gedata.h:451

Copyright  © 2014-2025 乐数软件    

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