This documentation is for the free plugin Py4D in CINEMA 4D R11.5 and not for the C4DSDK of Python in CINEMA 4D R12. For R12, please visit PluginCafe.com

c4d.documents – a module for document stuff

To get an overview of the class members, check out the diagram.

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.

Parameter:doc (The document) – BaseDocument
c4d.documents.SaveDocument(doc, fn, saveflags, format)

Saves the document to a file.

Parameters:
  • doc (BaseDocument) – Command ID
  • fn (str) – Filename to save the document to.
  • saveflags (int) –

    The flags

    SAVEFLAG_SHOWERROR Show a message if an error occurs during save.
    SAVEFLAG_SAVEAS Force a “Save As” and open the file requester.
    SAVEFLAG_DONTADDTORECENTLIST Don’t add the saved document to recent file list.
    SAVEFLAG_AUTOSAVE Set the Autosave mode. Files are not added to the recent file list and the document change star will not be reset.
  • 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
c4d.documents.RenderDocument(doc, rdata, bmp, renderflags)

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()
#init the bitmap with the result size
bmp.Init(width=320, height=240, depth=32)

documents.RenderDocument(doc, rd, bmp)
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.

    RENDERFLAG_EXTERNAL Use render settings for LOD etc. (Otherwise the current document settings are used.)
    RENDERFLAG_NODOCUMENTCLONE Set this flag to avoid an automatic clone of the scene sent to RenderDocument()
    RENDERFLAG_SHOWERRORS Show error messages.
    RENDERFLAG_PREVIEWRENDER Preview render.
    RENDERFLAG_IRR Interactive region render.
c4d.documents.MergeDocument(doc, name, loadflags)

Merges two documents

Parameters:
  • doc (BaseDocument) – The document to merge the loaded scene into.
  • name (str) – File to load the merge document from.
  • loadflags (int) – Flags for the loader:
Return type:

bool

Returns:

True if successful, otherwise False.

c4d.documents.LoadFile(fn)

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

Parameter:fn (str) – The file to load.
c4d.documents.KillDocument(doc)

Remove and free all resources of this document.

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

Insert a document into the CINEMA editor list of documents.

Parameter:doc (BaseDocument) – The document to insert.
c4d.documents.LoadDocument(fn, flags)

Loads a document file and returns it at BaseDocument.

Parameters:
  • fn (str) – The file to load
  • flags (int) –
Return type:

BaseDocument

Returns:

Returns the document on success, otherwise None.

c4d.documents.CloseAllDocuments()

Close all open documents in Cinema 4D.

Return type:bool
Returns: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:

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:

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
            InteractiveModeling_Restart(doc)

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

        return True
Parameter: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.

Table Of Contents

This Page