c4d.documents

Follow me to the Inheritance diagramm.

Functions

c4d.documents.GetActiveDocument()

Returns the active document of CINEMA 4D.

Return type: BaseDocument
Returns: The actve document.
c4d.documents.GetFirstDocument()

Get the first document in the list of documents within CINEMA.

Return type: BaseDocument
Returns: The first document.
c4d.documents.SetActiveDocument(doc)

Set doc as active document in CINEMA 4D.

Parameters: doc (BaseDocument) – The document.
c4d.documents.SaveDocument(doc, name, saveflags, format)

Saves the document to a file.

Parameters:
  • doc (BaseDocument) – Command ID
  • name (str or MemoryFileStruct) –

    File to save the document to.

    Changed in version R13.051: It is now possible to pass a memory file.

  • saveflags (int) –

    The flags

    SAVEDOCUMENTFLAGS_0 No flags.
    SAVEDOCUMENTFLAGS_DIALOGSALLOWED Flag to inform your plugin that a dialog can be displayed if you wish. If this flag is not set then no dialogs must be opened.
    SAVEDOCUMENTFLAGS_SAVEAS Forces a “Save As” and opens the file requester.
    SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST Don’t add the saved document to recent file list.
    SAVEDOCUMENTFLAGS_AUTOSAVE Sets the Autosave mode. Files are not added to the recent file list and the document change star will not be reset.
    SAVEDOCUMENTFLAGS_SAVECACHES Caches of objects will also be written (only supported by CINEMA 4D file format).
    SAVEDOCUMENTFLAGS_EXPORTDIALOG Opens the Export settings dialog.
  • format (int) –

    The file format to save the document as.

    FORMAT_C4DEXPORT C4D export.
    FORMAT_XMLEXPORT XML export.
    FORMAT_VRML1EXPORT VRML export.
    FORMAT_VRML2EXPORT VRML export.
    FORMAT_DXFEXPORT DXF export.
    FORMAT_3DSEXPORT 3DS export.
    FORMAT_OBJEXPORT OBJ export.
    FORMAT_Q3DEXPORT QuickDraw 3D export
    FORMAT_D3DEXPORT Direct3D import
Return type:

bool

Returns:

True if successful, otherwise False.

c4d.documents.RenderDocument(doc, rdata, bmp[, renderflags=0, th=None])

Renders the document to a bitmap. You need to initialize the image with the size of the renderdata:

import c4d
from c4d import bitmaps, documents

doc = documents.GetActiveDocument()
rd = doc.GetActiveRenderData().GetData()

bmp = bitmaps.BaseBitmap()
#Initialize the bitmap with the result size.
#The resolution must match with the output size of the render settings.
bmp.Init(x=320, y=240, depth=24)

documents.RenderDocument(doc, rd, bmp, c4d.RENDERFLAGS_EXTERNAL)
bitmaps.ShowBitmap(bmp)
Parameters:
  • doc (BaseDocument) – The document you want to render.
  • rdata (BaseContainer) – The render data.
  • bmp (BaseBitmap) – The bitmap where the rendered picture will be saved in. Initialize the image with the size of the renderdata.
  • renderflags (int) –

    Some renderflags.

    RENDERFLAGS_0 None.
    RENDERFLAGS_EXTERNAL Use render settings for LOD etc. (Otherwise the current document settings are used.)
    RENDERFLAGS_NODOCUMENTCLONE Set this flag to avoid an automatic clone of the scene sent to RenderDocument().
    RENDERFLAGS_SHOWERRORS Show error messages.
    RENDERFLAGS_PREVIEWRENDER Preview render.
    RENDERFLAGS_IRR Interactive region render.
    RENDERFLAGS_CREATE_PICTUREVIEWER Renders in a new Picture Viewer.
    RENDERFLAGS_OPEN_PICTUREVIEWER Opens the Picture Viewer.
  • th (BaseThread) –

    New in version R13.016.

    The thread to test for a break or None.

Return type:

int

Returns:

The result:

RENDERRESULT_OK

Function was successful.

RENDERRESULT_OUTOFMEMORY

Not enough memory.

RENDERRESULT_ASSETMISSING

Assets (textures etc.) are missing.

RENDERRESULT_SAVINGFAILED

Failed to save.

RENDERRESULT_USERBREAK

User stopped the processing.

RENDERRESULT_GICACHEMISSING

GI cache is missing.

c4d.documents.MergeDocument(doc, name, loadflags[, thread])

Merges two documents

Parameters:
  • doc (BaseDocument) – The document to merge the loaded scene into.
  • name (str or MemoryFileStruct) –

    File to load the merge document from.

    Changed in version R13.051: It is now possible to pass a memory file.

  • loadflags (int) –

    Flags for the loader:

    SCENEFILTER_0 No flags.
    SCENEFILTER_OBJECTS Load/save only the objects and associated items, such as materials used.
    SCENEFILTER_MATERIALS Load/save only the materials.
    SCENEFILTER_DIALOGSALLOWED Flag to inform your plugin that a dialog can be displayed if you wish, if this flag not set then no dialogs must be opened.
    SCENEFILTER_PROGRESSALLOWED Flag to inform your plugin that a progress bar can be displayed if you wish. The progress bar can be set by calling StatusSetBar().
    SCENEFILTER_MERGESCENE Flag to inform your plugin that this is a merge operation, i.e. that the document you’re inserting to is an existing scene.
    SCENEFILTER_NONEWMARKERS Objects loaded from disk will keep their markers
    SCENEFILTER_SAVECACHES Caches of objects will also be written (only supported by C4D file format). This equals the global option “Save Polygon Objects for Melange Exchange”
  • thread (BaseThread) –

    New in version R13.016.

    The current thread, or None for the main CINEMA 4D thread.

Return type:

bool

Returns:

True if successful, otherwise False.

c4d.documents.LoadFile(name)

Loads a file into CINEMA 4D (file, image, ...) and opens it.

Parameters: name (or MemoryFileStruct) –

The file to load.

Changed in version R13.051: It is now possible to pass a memory file.

c4d.documents.KillDocument(doc)

Remove and free all resources of this document.

Parameters: doc (BaseDocument) – The document to free.
c4d.documents.InsertBaseDocument(doc)

Insert a document into the CINEMA editor list of documents.

Parameters: doc (BaseDocument) – The document to insert.
c4d.documents.LoadDocument(name, loadflags[, thread])

Similar to LoadFile() but this time the document isn’t put into the editors list of documents and you have control over the document.

Parameters:
  • name (str or MemoryFileStruct) –

    The file to load.

    Changed in version R13.051: It is now possible to pass a memory file.

  • loadflags (int) –

    Flags for the loader:

    SCENEFILTER_0 No flags.
    SCENEFILTER_OBJECTS Load/save only the objects and associated items, such as materials used.
    SCENEFILTER_MATERIALS Load/save only the materials.
    SCENEFILTER_DIALOGSALLOWED Flag to inform your plugin that a dialog can be displayed if you wish, if this flag not set then no dialogs must be opened.
    SCENEFILTER_PROGRESSALLOWED Flag to inform your plugin that a progress bar can be displayed if you wish. The progress bar can be set by calling StatusSetBar().
    SCENEFILTER_MERGESCENE Flag to inform your plugin that this is a merge operation, i.e. that the document you’re inserting to is an existing scene.
    SCENEFILTER_NONEWMARKERS Objects loaded from disk will keep their markers
    SCENEFILTER_SAVECACHES Caches of objects will also be written (only supported by C4D file format). This equals the global option “Save Polygon Objects for Melange Exchange”
  • thread (BaseThread) –

    New in version R13.016.

    The current thread, or None for the main CINEMA 4D thread.

Return type:

BaseDocument

Returns:

Document that was loaded, or None if it failed.

c4d.documents.CloseAllDocuments()

Close all open documents in CINEMA 4D.

Return type: bool
Returns: True on success, otherwise False
c4d.documents.SetDocumentTime(doc, time)

Controls the time of the active document doc. Unlike BaseDocument.SetTime() it handles running animation.

Parameters:
Return type:

bool

Returns:

True on success, otherwise False

c4d.documents.RunAnimation(doc, stop[, forward])

Controls the animation in the active document doc.

Parameters:
  • doc (BaseDocument) – The document to control. Usually GetActiveDocument()
  • stop (bool) – If this is True the animation is stopped, otherwise it’s running.
  • forward (bool) – If this is True the direction is set to forward, otherwise it’s set to backward.
Return type:

bool

Returns:

True on success, otherwise False

c4d.documents.InteractiveModeling_Restart(doc)

Used for modeling tools with GUI input. Applies the last modeling undo so that new values of the modeling tool can be applied. An example from the edge cut code:

from c4d import documents, plugins

class TestTool(plugins.ToolData):

    def MouseInput(self, doc, data, draw, win, msg):
        if not doc: return False

        if doc.GetMode() == documents.Medges:
            active = p.GetActiveObjects(True)

            #undo step before
            documents.InteractiveModeling_Restart(doc)

            self.ModelingEdgeCut(active, c4d.MODIFY_EDGESELECTION, data, doc, win, msg, True)
            c4d.EventAdd()

        return True
Parameters: doc (BaseDocument) – The document.
Return type: bool
Returns: True if successful, otherwise False.
c4d.documents.IsolateObjects(doc, t_objects)

A helper routine to copy the objects t_objects of document doc to a new document (returned). All materials associated are also copied over and the links are corrected.

Parameters:
  • doc (BaseDocument) – The document that contains the objects in t_objects.
  • t_objects (list of BaseObject) – The objects to isolate.
Return type:

BaseDocument

Returns:

The document containing the isolated objects.

c4d.documents.StopExternalRenderer()

Stop the external renderer.

Return type: bool
Returns: True if the rendering has been canceled, otherwise False.
c4d.documents.GetBatchRender()

Get the batch render instance.

Return type: BatchRender
Returns: The batch render.
c4d.documents.GetFirstMarker(doc)

New in version R13.016.

Returns the first timeline marker of the document.

Parameters: doc (BaseDocument) – The document.
Return type: BaseList2D
Returns: The first timeline marker.
c4d.documents.AddMarker(doc, pPred, time, name)

New in version R13.016.

Inserts a timeline marker into the document at a given time. Optionally an insertion point pPred in the timeline marker list can be specified, giving the marker before the wanted insertion point.

Parameters:
  • doc (BaseDocument) – The document in which to insert.
  • pPred (BaseList2D) – The optional timeline marker to use as list insertion point.
  • time (BaseTime) – The time position of the timeline marker.
  • name (str) – The name of the timeline marker.
Return type:

BaseList2D

Returns:

The added timeline marker, or None if insertion failed.

Table Of Contents