About
A BaseDocument represents a Cinema 4D scene with all its content. Cinema 4D can manage multiple open scenes simultaneously in a document list. It is possible to load, create, edit, render and save scenes in the background. A document contains:
- Objects, materials and tags
- Render settings
- Document settings
- Layers
- Takes
- Scene hooks
- Undo actions
- Warning
- The active BaseDocument is the scene currently displayed in the editor. This active BaseDocument must not be edited from another thread than the main thread. Watch out for functions marked as "called in a thread context". If one needs to change the document from an asynchronous dialog, StopAllThreads() must be called before.
BaseDocument objects are an instance of Tbasedocument
.
if (virtualDoc == nullptr)
if (cube == nullptr)
virtualDoc->InsertObject(cube, nullptr, nullptr);
if (bitmap == nullptr)
const Int32 height = 720;
RenderData*
const rdata = virtualDoc->GetActiveRenderData();
if (rdata == nullptr)
nullptr,
nullptr, bitmap,
flags,
nullptr);
PyCompilerFlags * flags
Definition: ast.h:14
RENDERRESULT RenderDocument(BaseDocument *doc, const BaseContainer &rdata, ProgressHook *prog, void *private_data, BaseBitmap *bmp, RENDERFLAGS renderflags, BaseThread *th, WriteProgressHook *wprog=nullptr, void *data=nullptr)
Bool ShowBitmap(const Filename &fn)
Definition: ge_autoptr.h:37
Definition: c4d_basecontainer.h:47
void SetFloat(Int32 id, Float r)
Definition: c4d_basecontainer.h:533
BaseContainer GetData()
Definition: c4d_baselist.h:2329
Definition: c4d_baseobject.h:225
static BaseObject * Alloc(Int32 type)
Definition: c4d_basedocument.h:144
Py_UCS4 * res
Definition: unicodeobject.h:1113
@ RDATA_XRES
Definition: drendersettings.h:154
@ RDATA_YRES
Definition: drendersettings.h:155
maxon::Int32 Int32
Definition: ge_sys_math.h:60
IMAGERESULT
Definition: ge_prepass.h:3914
@ OK
Image loaded/created.
#define Ocube
Cube.
Definition: ge_prepass.h:1102
RENDERFLAGS
Definition: ge_prepass.h:4681
@ NODOCUMENTCLONE
Set to avoid an automatic clone of the scene sent to RenderDocument().
RENDERRESULT
Definition: ge_prepass.h:422
@ OK
Function was successful.
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:67
unsigned long Py_ssize_t width
Definition: pycore_traceback.h:88
Access
Cinema 4D can handle multiple open scenes in a document list:
To navigate the document list GetNext() and GetPred() can be used:
if (activeDocument == nullptr)
while (document != nullptr)
{
if (docMarker.
IsEqual(activeDocMarker))
{
}
else
{
}
}
BaseDocument * GetActiveDocument()
BaseDocument * GetFirstDocument()
Definition: c4d_basedocument.h:498
BaseDocument * GetNext()
Definition: c4d_basedocument.h:534
Filename GetDocumentName()
const GeMarker & GetMarker() const
Definition: c4d_baselist.h:2428
A unique marker that identifies an object.
Definition: c4d_baselist.h:1320
Bool IsEqual(const GeMarker &m) const
Definition: c4d_baselist.h:1350
#define ApplicationOutput(formatString,...)
Definition: debugdiagnostics.h:210
- Note
- GetActiveDocument() and GetFirstDocument() only work in Cinema 4D versions that have an active document (not in Team Render Client, Command Line etc.). Use GetActiveDocument() only in combination with dialogs etc. but NEVER in NodeData based plugins or expressions.
-
GeListNode::GetDocument() returns the BaseDocument that hosts a given entity. Use this method to access the document in a NodeData based plugin and all functions that are part of the execution or drawing pipeline. But never forget to check for
nullptr
, as there are situations where elements are not part of any document at all.
Allocation/Deallocation
A BaseDocument can be created with the usual tools:
AutoAlloc can be used to handle a temporary document. A new document can be added to the document list:
if (newDocument == nullptr)
void InsertBaseDocument(BaseDocument *doc)
void SetActiveDocument(BaseDocument *doc)
void EventAdd(EVENT eventflag=EVENT::NONE)
void SetDocumentName(const Filename &fn)
static BaseDocument * Alloc()
- Note
- BaseDocuments can also be created by loading Cinema 4D files. See Disc I/O below.
Destroy
A dynamically created BaseDocument should be destroyed with BaseDocument::Free(). To remove a BaseDocument from the document list use KillDocument().
Copy
BaseDocument is based on C4DAtom and can be cloned using C4DAtom::GetClone():
if (cloneDocument == nullptr)
Definition: c4d_baselist.h:1395
const char * doc
Definition: pyerrors.h:226
Preview Image
When a scene is saved the current editor image is saved with the BaseDocument to create a thumbnail preview image.
if (bitmap != nullptr)
{
}
Definition: c4d_basebitmap.h:428
Properties
Data
Multiple settings are stored inside the BaseDocument. The different types of settings are defined in DOCUMENTSETTINGS, the parameter IDs in ddoc.h
.
void SetBool(Int32 id, Bool b)
Definition: c4d_basecontainer.h:498
Bool GetBool(Int32 id, Bool preset=false) const
Definition: c4d_basecontainer.h:295
@ DOCUMENT_USEGENERATORS
Definition: ddoc.h:24
maxon::Bool Bool
Definition: ge_sys_math.h:55
@ GENERAL
General settings.
and
if (settings == nullptr)
void SetString(Int32 id, const maxon::String &s)
Definition: c4d_basecontainer.h:569
@ DOCUMENT_INFO_AUTHOR
Definition: ddoc.h:48
@ DOCUMENT
Document settings.
- Note
- BaseDocument::GetSettingsInstance() won't work with DOCUMENTSETTINGS::GENERAL.
Objects
A BaseDocument hosts multiple BaseObject based scene objects. These objects are organized in an object tree.
- Note
- Using BaseDocument::InsertObject() will trigger the message MSG_DOCUMENTINFO_TYPE_OBJECT_INSERT.
See also BaseObject Manual.
if (object != nullptr)
{
}
if (cubeObject == nullptr)
doc->InsertObject(cubeObject,
nullptr,
nullptr);
void SetName(const maxon::String &name)
Definition: c4d_baselist.h:2387
return OK
Definition: apibase.h:2690
In some cases multiple instances of a certain object class can be inserted into the scene but only one instance will be used (e.g. the Sky object). This is typically the "highest" instance.
if (stageObject == nullptr)
String GetName() const
Definition: c4d_baselist.h:2381
#define Ostage
Stage.
Definition: ge_prepass.h:1066
Materials
A BaseDocument hosts multiple BaseMaterial based materials. These materials are stored in a list and can be applied to objects in the scene.
See also BaseMaterial Manual
if (material)
{
}
if (greenMaterial == nullptr)
doc->InsertMaterial(greenMaterial);
Definition: c4d_basematerial.h:28
static BaseMaterial * Alloc(Int32 type)
#define Mmaterial
Standard material.
Definition: ge_prepass.h:998
Selections
Inside a scene multiple objects, materials or tags can be selected.
if (selection == nullptr)
doc->GetSelection(selection);
const Int32 cnt = selection->GetCount();
if (cnt == 0)
{
{
}
else
{
}
}
Py_ssize_t i
Definition: abstract.h:645
Definition: c4d_baselist.h:2208
#define Tbaselist2d
2D list.
Definition: ge_prepass.h:986
PyObject * element
Definition: unicodeobject.h:1016
Object selections can be managed separately:
- Note
- To get the position of the anchor of an object multi-selection one can use BaseDocument::GetHelperAxis().
-
To correctly add objects to the selection of active objects with BaseDocument::SetActiveObject() one must update internal caches by calling BaseDocument::GetActiveObject() after an object was added to the selection.
if (selection == nullptr)
const Int32 cnt = selection->GetCount();
if (cnt == 0)
doc->SetActiveObject(
nullptr);
{
if (nullobject == nullptr)
if (cube == nullptr)
doc->InsertObject(cube,
nullptr,
nullptr);
}
void SetMg(const Matrix &m)
Definition: c4d_baseobject.h:488
Matrix GetMg() const
Definition: c4d_baseobject.h:482
#define NOTOK
Definition: ge_sys_math.h:267
#define Onull
Null.
Definition: ge_prepass.h:1068
#define SELECTION_ADD
Adds to the current selection.
Definition: c4d_basedocument.h:390
Material selections can be managed separately, too:
if (tag == nullptr)
if (material != nullptr)
Definition: c4d_basetag.h:48
Definition: c4d_basetag.h:654
BaseMaterial * GetMaterial(Bool ignoredoc=false)
#define SELECTION_NEW
Starts a new selection.
Definition: c4d_basedocument.h:389
#define Ttexture
Texture - TextureTag.
Definition: ge_prepass.h:1392
Finally tag selections can be managed:
if (tags == nullptr)
doc->GetActiveTags(tags);
const Int32 cnt = tags->GetCount();
if (cnt == 0)
{
if (tag == nullptr)
{
}
}
Int32 GetType() const
Definition: c4d_baselist.h:1411
void SetMaterial(BaseMaterial *mat)
RenderData
RenderData objects represent the render settings stored in a document. They allow access to the actual settings, multipass objects and post effects.
See also RenderData Manual.
if (renderData == nullptr)
renderData->
SetName(
"Preview Render Settings"_s);
doc->InsertRenderDataLast(renderData);
doc->SetActiveRenderData(renderData);
static RenderData * Alloc()
Scene Hooks
Scene hooks are used to add additional data to the document or to influence the execution pipeline. These scene hooks are stored in the document:
if (dynamicsHook == nullptr)
const BaseContainer & GetDataInstanceRef() const
Definition: c4d_baselist.h:2362
Definition: c4d_basedocument.h:51
@ WORLD_ENABLED
Definition: dynworldobject.h:6
Layers
Layers are used to organize a document. A layer is represented by a LayerObject and these LayerObject objects are organized in a tree:
See also Layer Manual.
if (layers == nullptr)
if (layer != nullptr)
Definition: c4d_baselist.h:2044
GeListNode * GetFirst()
Definition: c4d_baselist.h:2100
Definition: c4d_basedocument.h:253
Takes
Takes allow to handle multiple versions of a scene within the same document. The takes of a document are stored in a TakeData object:
if (takeData == nullptr)
BaseTake*
const newTake = takeData->
AddTake(
"This is a new take",
nullptr,
nullptr);
if (newTake == nullptr)
Definition: lib_takesystem.h:335
Definition: lib_takesystem.h:589
BaseTake * AddTake(const String &name, BaseTake *parent, BaseTake *cloneFrom)
Bool SetCurrentTake(BaseTake *take)
See Take System Overview
Changed Mode
The change status of a document indicates that the scene was changed after the last time it was saved. The status is displayed with a little star (*) in the application title bar.
if (activeDoc == nullptr)
void KillDocument(BaseDocument *&doc)
Document Name and Path
A document is presented in the application using its filename. Because of this the name of the document cannot be obtained with BaseList2D::GetName() that returns a String and not a Filename.
{
if (suffix == "c4d")
else
}
else
{
}
Manages file and path names.
Definition: c4d_file.h:94
Definition: c4d_string.h:39
Bool IsPopulated() const
Definition: string.h:1449
Level of Detail
The level of detail defines how detailed certain objects are displayed in the editor. This is typically used in custom ObjectData based generators.
if (
doc->GetRenderLod() ==
false)
{
if (renderData == nullptr)
}
Float GetFloat(Int32 id, Float preset=0.0) const
Definition: c4d_basecontainer.h:335
@ RDATA_LOD
Definition: drendersettings.h:63
maxon::Float Float
Definition: ge_sys_math.h:66
- Note
- The LOD buttons in the editor represent the values 25%, 50% and 100%.
Time
The current timeline position of a document and the timeline size is defined using BaseTime objects.
- Note
- Setting the current time will not animate the document. See paragraph Animate below.
Current time:
Definition: c4d_basetime.h:25
Framerate:
- Note
- The framerate defined in the render settings is independent from the document framerate.
In the viewport, and for a render in the viewport, it will return the project's setting FrameRate.
Rendering elsewhere, it will return the RenderData FrameRate setting.
if (renderData == nullptr)
Int32 GetInt32(Int32 id, Int32 preset=0) const
Definition: c4d_basecontainer.h:303
@ RDATA_FRAMERATE
Definition: drendersettings.h:173
Timeline dimensions:
Used Time:
Loop Preview:
const BaseTime loopDuration =
doc->GetLoopMaxTime() -
doc->GetLoopMinTime();
doc->SetLoopMinTime(minTime);
doc->SetLoopMaxTime(minTime + loopDuration);
Mode
A document can be in different modes defining which elements should be edited (objects, points, edges, etc.).
if (tag == nullptr)
{
}
@ Medges
Edge edit mode.
Definition: c4d_basedocument.h:1898
@ Mpolygons
Polygon edit mode.
Definition: c4d_basedocument.h:1899
@ Mpoints
Point edit mode.
Definition: c4d_basedocument.h:1897
#define Tpointselection
Point selection - SelectionTag.
Definition: ge_prepass.h:1404
#define Tedgeselection
Edge selection - SelectionTag. The edges are encodes like this: (4*poly)+edge, where edge goes from 0...
Definition: ge_prepass.h:1421
#define Tpolygonselection
Polygon selection - SelectionTag.
Definition: ge_prepass.h:1403
Active Tool
The currently active tool is stored in the document.
- Note
- To edit the settings of the Move/Scale/Rotate tools the actual plugin instance has to be accessed with FindPlugin().
Axis and Plane
The helper axis represents the position of the handles used to move a multi-selection.
if (helperAxis == nullptr)
if (nullObject == nullptr)
doc->InsertObject(nullObject,
nullptr,
nullptr);
nullObject->
SetMg(matrix);
{
if (baseObject == nullptr)
doc->InsertObject(baseObject, nullObject,
nullptr);
baseObject->
SetMg(position);
}
void Remove()
Definition: c4d_baselist.h:1917
@ Mmodel
Model mode.
Definition: c4d_basedocument.h:1902
Editor Windows
An editor window is represented by a BaseDraw object. Such a BaseDraw object allows access to the currently used camera. The render view is the editor window used to define the camera that will be used while rendering the final image.
See also BaseView / BaseDraw Manual.
if (baseDraw == nullptr)
Matrix targetPosition = activeObject->GetMg();
targetPosition.
off = cameraMatrix.
off + (900.0 * cameraMatrix.
sqmat.v3);
activeObject->SetMg(targetPosition);
Definition: c4d_basedraw.h:754
BaseObject * GetEditorCamera()
Definition: c4d_basedraw.h:874
V off
The translation vector.
Definition: matrix.h:263
SqrMat3< V > sqmat
The 3×3 matrix for rotation, scale and shear.
Definition: matrix.h:266
Net Context
If the document is currently handled inside a Team Render context can be checked using the net render context:
else
void MessageDialog(const maxon::String &str)
void * context
Definition: pycapsule.h:49
PyObject * op
Definition: object.h:520
Definition: lib_net.h:829
Functionality
Animate
Scene elements can be animated by setting keyframes with specific values at a specific time. The BaseDocument class offers functions to create such keyframes:
if (undoObject == nullptr)
doc->AutoKey(undoObject, cubeObject,
true,
true,
true,
true,
true,
true);
static void Free(BaseObject *&bl)
Bool SetParameter(const DescID &id, const GeData &t_data, DESCFLAGS_SET flags)
C4DAtom * GetClone(COPYFLAGS flags, AliasTrans *trn)
Definition: c4d_baselist.h:1480
Definition: lib_description.h:330
@ PRIM_CUBE_SUBY
Definition: ocube.h:9
@ PRIM_CUBE_SUBX
Definition: ocube.h:8
@ PRIM_CUBE_SUBZ
Definition: ocube.h:10
See also Animation Tracks.
To apply keyframe animation, expressions, generators and deformers the document has to be animated.
{
if (cube)
{
}
}
doc->SetTime(originalTime);
static String VectorToString(const Vector32 &v, Int32 nnk=-1)
Definition: c4d_string.h:571
@ INTERNALRENDERER
Rendering in the editor.
When a new keyframe is created a default template is used. This template can be edited:
doc->GetDefaultKey(
key, overdub);
doc->SetDefaultKey(
key, overdub);
PyObject * key
Definition: abstract.h:289
The result of simulations is often iterative: The current frame depends on the results of previous calculations. To calculate the state of a particle simulation at a certain frame all frames before that have to be calculated:
Definition: c4d_gedata.h:83
const BaseTime & GetTime() const
Definition: c4d_gedata.h:481
@ PARTICLEOBJECT_STOP
Definition: oparticle.h:29
Undo
The undo system of Cinema 4D allows to store operations in undo actions that can be executed to undo and redo user interaction.
See also Undo System Manual.
if (cube == nullptr)
doc->InsertObject(cube,
nullptr,
nullptr);
@ NEWOBJ
A new object, material, tag, or other classic API node instance has been inserted into the document....
Undo actions can be executed:
Pick Session
A pick session can be used to select multiple objects.
See PickSessionDataStruct.
Send Messages
Convert and Export
The objects of a BaseDocument can be converted to polygon objects and associated sounds and textures can be collected:
while (browse.GetNext(&id, &data))
{
if (data != nullptr)
{
}
}
Definition: c4d_gedata.h:674
const Filename & GetFilename() const
Definition: c4d_gedata.h:475
Int32 GetType() const
Definition: c4d_gedata.h:407
@ DA_FILENAME
Filename.
Definition: c4d_gedata.h:48
- IsolateObjects(): Creates a new document that contains only copies of the given objects and their materials.
if (newDoc == nullptr)
BaseDocument * IsolateObjects(BaseDocument *doc, const AtomArray &t_objects)
Disc I/O
A BaseDocument can be created by reading if from a file on disc. It is possible to load *.c4d files and supported import file formats.
- LoadFile(): Used to load a file. A loaded Cinema 4D file will be automatically added to the document list.
- Note
- LoadFile() does not work with a Filename in Memory Read Mode, in this case use LoadDocument() instead.
"Select scene file to load (c4d, fbx, obj, etc)."_s);
"Loaded document with the file name '@', and changed the name to '@'.",
PyCompilerFlags const char * filename
Definition: ast.h:15
Bool LoadFile(const Filename &name, Bool allowAsync)
maxon::Url MaxonConvert(const Filename &fn, MAXONCONVERTMODE convertMode)
@ READ
Check for file read operation.
@ NONE
No check if file exists under case-sensitive drives.
- LoadDocument(): Will load a given Cinema 4D file into a BaseDocument object. Do not forget to set the scene filter flags.
- MergeDocument(): Loads and merges the given Cinema 4D file into the given BaseDocument.
return maxon::UnexpectedError(
"Select scene file to load (c4d, fbx, obj, etc)."_s);
{
if (progress > lastProgress)
{
lastProgress = progress;
}
return true;
});
if (!loadedDocument)
return maxon::IoError(
BaseDocument * LoadDocument(const Filename &name, SCENEFILTER loadflags, BaseThread *thread, maxon::String *errorString=nullptr, const ProgressDelegate &progressDelegate=ProgressDelegate())
void StatusSetBar(Int32 p)
Bool GeIsMainThreadAndNoDrawThread()
void StatusClear()
Clears the status bar text.
Definition: string.h:1235
int32_t Int32
32 bit signed integer datatype.
Definition: apibase.h:176
SCENEFILTER
Definition: ge_prepass.h:298
@ MERGESCENE
Flag to inform a plugin that this is a merge operation, i.e. the document that is inserted to is an e...
@ OBJECTS
Load/save objects.
@ MATERIALS
Load/save materials.
void _ApplicationOutput(maxon::TARGETAUDIENCE t, maxon::WRITEMETA lvl, const maxon::String &str, Int line, const Char *file)
#define FormatString(...)
Definition: string.h:2100
The list of recently opened scene files is accessed with:
- GetRecentDocumentsList(): Returns the list of recently opened scene files.
{
if (loadedDoc == nullptr)
ApplicationOutput(
"Document " + fileStr +
": " + startFrameStr +
" - " + endFrameStr);
}
static void Free(BaseDocument *&bl)
Int32 GetFrame(Float fps) const
Definition: c4d_basetime.h:107
static String IntToString(Int32 v)
Definition: c4d_string.h:495
- SaveDocument(): Saves the document to a Cinema 4D file or to a supported export file format.
- SaveProject(): Saves the document like the "Save Project with Assets" command.
if (tempDoc == nullptr)
if (cube == nullptr)
tempDoc->InsertObject(cube, nullptr, nullptr);
Bool SaveDocument(BaseDocument *doc, const Filename &name, SAVEDOCUMENTFLAGS saveflags, Int32 format)
#define FORMAT_C4DEXPORT
Cinema 4D export.
Definition: ge_prepass.h:3525
@ DONTADDTORECENTLIST
Do not add the saved document to the recent file list.
Render
A BaseDocument can be rendered independently from the GUI and the Picture Viewer into a BaseBitmap (see BaseBitmap Manual).
if (loadedDoc == nullptr)
if (rdata == nullptr)
if (bitmap == nullptr)
nullptr, nullptr, bitmap, renderFlags, nullptr);
Definition: ge_autoptr.h:155
void Assign(TYPE *p)
Definition: ge_autoptr.h:234
void SetTime(Int32 id, const BaseTime &b)
Definition: c4d_basecontainer.h:590
BaseTime GetTime(Int32 id, const BaseTime &preset=BaseTime()) const
Definition: c4d_basecontainer.h:411
RenderData * GetActiveRenderData()
@ RDATA_FRAMETO
Definition: drendersettings.h:167
@ RDATA_FRAMEFROM
Definition: drendersettings.h:166
Messages
On certain events (load, save, render,...) a MSG_DOCUMENTINFO message is sent to elements contained in a document.
{
return false;
{
{
return false;
break;
}
}
break;
}
void SetInt32(Int32 id, Int32 l)
Definition: c4d_basecontainer.h:505
#define MSG_DOCUMENTINFO_TYPE_LOAD
Document was loaded.
Definition: c4d_baselist.h:476
#define MSG_DOCUMENTINFO
Sent as broadcast message by the document when it is loaded, saved , merged etc. The corresponding da...
Definition: c4d_baselist.h:465
const char const char * msg
Definition: object.h:438
Message struct for the MSG_DOCUMENTINFO message.
Definition: c4d_baselist.h:1025
Futher document related messages:
Further Reading