Find out about Cinema 4D's Python environment

What is this?

About Cinema 4D Python environment and c4d module I tried diving lazily It's also an extension of the C4D Python copy book previously distributed at the event. Feelingly a continuation of this ...?

Cinema4D, command line options on OS X, etc. http://qiita.com/it_ks/items/5c052366fb8d1c9952b0

Before accepting

Here, it will be a little different from the module name, so Speaking of "** c4d **", ** Python module **. The application is abbreviated as Cinema 4D. Mostly.

environment

OSX 10.10.5、Cinema4D R14。

python


print c4d.GetC4DVersion()

14042

It returned with a 5-digit int. Looking at the about dialog, it is divided into 14 and 042.

By the way, the API version is (▼)

python


print c4d.GetAPIVersion()

(1, 1, 2406)
#Is this like this?

The Python environment for Cinema4D R14 is 2.6.4.

python


print sys.version_info

(2, 6, 4, 'final', 0)

I will try to get the OS version via Python.

python


import platform
print platform.mac_ver()
('10.10.5', ('', '', ''), 'i386')

Version Type Cinema 4D has different grades such as Broadcast and Prime under Studio with all of them. In terms of API, those classifications seem to be called "** version type **".

python


print c4d.GeGetVersionType()

4

The version type of Cinema 4D that we are using is "** 4 **". 4, what is ...? According to this https://developers.maxon.net/docs/Cinema4DPythonSDK/html/modules/c4d/index.html#c4d.GeGetVersionType Counting from 0, 4 is "Cinema 4D Broadcast." Correct answer!

python


print c4d.VERSIONTYPE_BROADCAST

4

For the time being, dir ()

Dir () without putting anything inside. Check the tools that are laid flat.

python


import c4d
from c4d import gui
#Welcome to the world of Python
print dir()

['__builtins__', '__file__', '__name__', '__package__', 'c4d', 'doc', 'gui', 'op']

Is like something that can be placed without doing anything, basic equipment.

c4d

python


print type( c4d )

<type 'module'>

help( c4d )

python


Help on module c4d:
NAME
    c4d - Common module for the most required classes and functions.
FILE
    (built-in)
SUBMODULES
    bitmaps
    documents
    gui
    internals
    modules
    plugins
    storage
    threading
    utils
CLASSES
    __builtin__.object
        BaseContainer
        BaseSelect
        BaseTime
        C4DAtom
            GeListNode
                BaseList2D
                    BaseMaterial
                    BaseObject
                        CameraObject
                        PointObject
                            LineObject
                            PolygonObject
                            SplineObject
                    BaseShader
                    BaseTag
                        SelectionTag
                        TextureTag
                        VariableTag
                            NormalTag
                            PointTag
                            PolygonTag
                            SegmentTag
                            TangentTag
                            UVWTag
                    BaseView
                        BaseDraw
                    CCurve
                    CTrack
                CKey
        CPolygon
        CustomDataType
            DateTimeData
            FontData
            Gradient
            InExcludeData
            LayerSet
            MatAssignData
            PLAData
            PriorityData
            SplineData
            UnitScaleData
        DescID
        DescLevel
        HandleInfo
        Matrix
        Vector
    
    class BaseContainer(__builtin__.object)
     |  A container for individual values.
     |  
     |  Methods defined here:
     |  
     |  CopyTo(...)
     |      Copy to another BaseContainer.
     |  

(Omitted)

dir( c4d ) A tremendous amount was returned and I couldn't see everything on the Cinema 4D console

Let's look at the number of items.

python


print len(dir(c4d))

17828

strong

doc

python


print type( doc )

<type 'c4d.documents.BaseDocument'>

It seems that the "Base Document" in c4d.documents is what it is. Other friends ...

python


print dir( c4d.documents )

['AddMarker', 'BaseDocument', 'BatchRender', 'CloseAllDocuments', 'GetActiveDocument', 'GetBatchRender', 'GetFirstDocument', 'GetFirstMarker', 'InsertBaseDocument', 'InteractiveModeling_Restart', 'IsolateObjects', 'KillDocument', 'LayerObject', 'LoadDocument', 'LoadFile', 'MergeDocument', 'RenderData', 'RenderDocument', 'RunAnimation', 'SaveDocument', 'SetActiveDocument', 'SetDocumentTime', 'StopExternalRenderer', '__doc__', '__name__', '__package__']

It looks like a module for dealing with files (scene files) handled by Cinema4D, c4d.documents.

help( doc )

python


Help on BaseDocument object:
class BaseDocument(c4d.BaseList2D)
 |  Represents a document.
 |  
 |  Method resolution order:
 |      BaseDocument
 |      c4d.BaseList2D
 |      c4d.GeListNode
 |      c4d.C4DAtom
 |      __builtin__.object
 |  
 |  Methods defined here:
 |  
 |  AddUndo(...)
 |      Perform a redo on this document (undo the last undo).
 |  
 |  AnimateObject(...)
 |      Animate a node in this document.
 |  
 |  DoRedo(...)
 |      Perform a redo on this document (undo the last undo).
 |  
 |  DoUndo(...)
 |      Perform an undo operation.
 |  
 |  EndUndo(...)
 |      End the building of multiple undo actions into a single user undo.

(Omitted)

dir( doc ) This person was able to display to the end.

print dir( doc )

python


['AddUndo', 'AddUserData', 'AnimateObject', 'ChangeNBit', 'CheckType', 'ClearKeyframeSelection', 'CopyTo', 'DelBit', 'DoRedo', 'DoUndo', 'Edit', 'EndUndo', 'ExecutePasses', 'FindCTrack', 'FindKeyframeSelection', 'FindSceneHook', 'FindUndoPtr', 'Flush', 'FlushUndoBuffer', 'ForceCreateBaseDraw', 'GetAction', 'GetActiveBaseDraw', 'GetActiveMaterial', 'GetActiveMaterials', 'GetActiveObject', 'GetActiveObjects', 'GetActiveObjectsFilter', 'GetActiveRenderData', 'GetActiveTag', 'GetActiveTags', 'GetActiveToolData
', 'GetAllBits', 'GetAllTextures', 'GetBaseDraw', 'GetBaseDrawCount', 'GetBit', 'GetBubbleHelp', 'GetCTrackRoot', 'GetCTracks', 'GetChanged', 'GetChildren', 'GetClassification', 'GetClone', 'GetData', 'GetDataInstance', 'GetDirty', 'GetDocument', 'GetDocumentName', 'GetDocumentPath', 'GetDown', 'GetDownLast', 'GetDrawTime', 'GetFirstCTrack', 'GetFirstMaterial', 'GetFirstObject', 'GetFirstRenderData', 'GetFirstShader', 'GetFps', 'GetHelperAxis', 'GetHighest', 'GetIcon', 'GetInfo', 'GetLOD', 'GetLayerData', 
'GetLayerObject', 'GetLayerObjectRoot', 'GetListHead', 'GetLoopMaxTime', 'GetLoopMinTime', 'GetMain', 'GetMaterials', 'GetMaxTime', 'GetMinTime', 'GetMode', 'GetNBit', 'GetNLARoot', 'GetName', 'GetNext', 'GetNodeData', 'GetObjects', 'GetOrderedActiveObjects', 'GetParticleSystem', 'GetPred', 'GetRenderBaseDraw', 'GetRenderLod', 'GetSelection', 'GetSettingsInstance', 'GetSplinePlane', 'GetTime', 'GetType', 'GetTypeName', 'GetUndoPtr', 'GetUp', 'GetUserDataContainer', 'InsertAfter', 'InsertBefore', 'InsertMat
erial', 'InsertObject', 'InsertRenderData', 'InsertRenderDataLast', 'InsertShader', 'InsertTrackSorted', 'InsertUnder', 'InsertUnderLast', 'IsAlive', 'IsAxisEnabled', 'IsDocumentRelated', 'IsEditMode', 'IsInstanceOf', 'KeyframeSelectionContent', 'Message', 'MultiMessage', 'Polygonize', 'Read', 'ReadObject', 'Remove', 'RemoveUserData', 'Scale', 'SearchMaterial', 'SearchMaterialInc', 'SearchObject', 'SearchObjectInc', 'SendInfo', 'SetAction', 'SetActiveMaterial', 'SetActiveObject', 'SetActiveRenderData', 'Se
tActiveTag', 'SetAllBits', 'SetBit', 'SetChanged', 'SetData', 'SetDirty', 'SetDocumentName', 'SetDocumentPath', 'SetFps', 'SetKeyframeSelection', 'SetLOD', 'SetLayerData', 'SetLayerObject', 'SetLoopMaxTime', 'SetLoopMinTime', 'SetMaxTime', 'SetMinTime', 'SetMode', 'SetName', 'SetRenderLod', 'SetRewind', 'SetSelection', 'SetTime', 'SetUserDataContainer', 'StartUndo', 'ToggleBit', 'TransferGoal', 'Write', 'WriteObject', '__call__', '__class__', '__delattr__', '__delitem__', '__doc__', '__eq__', '__format__',
 '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__']

The number of items for the time being.

python


print len(dir( doc ))
182

By the way, all the initial letters are capital letters, but can I think that this is all a class?

python


for i in dir(doc):
    print i,':',eval('type(doc.'+i+')')

python


AddUndo : <type 'builtin_function_or_method'>
AddUserData : <type 'builtin_function_or_method'>
AnimateObject : <type 'builtin_function_or_method'>
ChangeNBit : <type 'builtin_function_or_method'>
CheckType : <type 'builtin_function_or_method'>
ClearKeyframeSelection : <type 'builtin_function_or_method'>
CopyTo : <type 'builtin_function_or_method'>
DelBit : <type 'builtin_function_or_method'>
DoRedo : <type 'builtin_function_or_method'>
DoUndo : <type 'builtin_function_or_method'>
Edit : <type 'builtin_function_or_method'>
EndUndo : <type 'builtin_function_or_method'>
ExecutePasses : <type 'builtin_function_or_method'>
FindCTrack : <type 'builtin_function_or_method'>
FindKeyframeSelection : <type 'builtin_function_or_method'>
FindSceneHook : <type 'builtin_function_or_method'>
FindUndoPtr : <type 'builtin_function_or_method'>
Flush : <type 'builtin_function_or_method'>
FlushUndoBuffer : <type 'builtin_function_or_method'>
ForceCreateBaseDraw : <type 'builtin_function_or_method'>
GetAction : <type 'builtin_function_or_method'>
GetActiveBaseDraw : <type 'builtin_function_or_method'>
GetActiveMaterial : <type 'builtin_function_or_method'>
GetActiveMaterials : <type 'builtin_function_or_method'>
GetActiveObject : <type 'builtin_function_or_method'>
GetActiveObjects : <type 'builtin_function_or_method'>
GetActiveObjectsFilter : <type 'builtin_function_or_method'>
GetActiveRenderData : <type 'builtin_function_or_method'>
GetActiveTag : <type 'builtin_function_or_method'>
GetActiveTags : <type 'builtin_function_or_method'>
GetActiveToolData : <type 'builtin_function_or_method'>
GetAllBits : <type 'builtin_function_or_method'>
GetAllTextures : <type 'builtin_function_or_method'>
GetBaseDraw : <type 'builtin_function_or_method'>
GetBaseDrawCount : <type 'builtin_function_or_method'>
GetBit : <type 'builtin_function_or_method'>
GetBubbleHelp : <type 'builtin_function_or_method'>
GetCTrackRoot : <type 'builtin_function_or_method'>
GetCTracks : <type 'builtin_function_or_method'>
GetChanged : <type 'builtin_function_or_method'>
GetChildren : <type 'builtin_function_or_method'>
GetClassification : <type 'builtin_function_or_method'>
GetClone : <type 'builtin_function_or_method'>
GetData : <type 'builtin_function_or_method'>
GetDataInstance : <type 'builtin_function_or_method'>
GetDirty : <type 'builtin_function_or_method'>
GetDocument : <type 'builtin_function_or_method'>
GetDocumentName : <type 'builtin_function_or_method'>
GetDocumentPath : <type 'builtin_function_or_method'>
GetDown : <type 'builtin_function_or_method'>
GetDownLast : <type 'builtin_function_or_method'>
GetDrawTime : <type 'builtin_function_or_method'>
GetFirstCTrack : <type 'builtin_function_or_method'>
GetFirstMaterial : <type 'builtin_function_or_method'>
GetFirstObject : <type 'builtin_function_or_method'>
GetFirstRenderData : <type 'builtin_function_or_method'>
GetFirstShader : <type 'builtin_function_or_method'>
GetFps : <type 'builtin_function_or_method'>
GetHelperAxis : <type 'builtin_function_or_method'>
GetHighest : <type 'builtin_function_or_method'>
GetIcon : <type 'builtin_function_or_method'>
GetInfo : <type 'builtin_function_or_method'>
GetLOD : <type 'builtin_function_or_method'>
GetLayerData : <type 'builtin_function_or_method'>
GetLayerObject : <type 'builtin_function_or_method'>
GetLayerObjectRoot : <type 'builtin_function_or_method'>
GetListHead : <type 'builtin_function_or_method'>
GetLoopMaxTime : <type 'builtin_function_or_method'>
GetLoopMinTime : <type 'builtin_function_or_method'>
GetMain : <type 'builtin_function_or_method'>
GetMaterials : <type 'builtin_function_or_method'>
GetMaxTime : <type 'builtin_function_or_method'>
GetMinTime : <type 'builtin_function_or_method'>
GetMode : <type 'builtin_function_or_method'>
GetNBit : <type 'builtin_function_or_method'>
GetNLARoot : <type 'builtin_function_or_method'>
GetName : <type 'builtin_function_or_method'>
GetNext : <type 'builtin_function_or_method'>
GetNodeData : <type 'builtin_function_or_method'>
GetObjects : <type 'builtin_function_or_method'>
GetOrderedActiveObjects : <type 'builtin_function_or_method'>
GetParticleSystem : <type 'builtin_function_or_method'>
GetPred : <type 'builtin_function_or_method'>
GetRenderBaseDraw : <type 'builtin_function_or_method'>
GetRenderLod : <type 'builtin_function_or_method'>
GetSelection : <type 'builtin_function_or_method'>
GetSettingsInstance : <type 'builtin_function_or_method'>
GetSplinePlane : <type 'builtin_function_or_method'>
GetTime : <type 'builtin_function_or_method'>
GetType : <type 'builtin_function_or_method'>
GetTypeName : <type 'builtin_function_or_method'>
GetUndoPtr : <type 'builtin_function_or_method'>
GetUp : <type 'builtin_function_or_method'>
GetUserDataContainer : <type 'builtin_function_or_method'>
InsertAfter : <type 'builtin_function_or_method'>
InsertBefore : <type 'builtin_function_or_method'>
InsertMaterial : <type 'builtin_function_or_method'>
InsertObject : <type 'builtin_function_or_method'>
InsertRenderData : <type 'builtin_function_or_method'>
InsertRenderDataLast : <type 'builtin_function_or_method'>
InsertShader : <type 'builtin_function_or_method'>
InsertTrackSorted : <type 'builtin_function_or_method'>
InsertUnder : <type 'builtin_function_or_method'>
InsertUnderLast : <type 'builtin_function_or_method'>
IsAlive : <type 'builtin_function_or_method'>
IsAxisEnabled : <type 'builtin_function_or_method'>
IsDocumentRelated : <type 'builtin_function_or_method'>
IsEditMode : <type 'builtin_function_or_method'>
IsInstanceOf : <type 'builtin_function_or_method'>
KeyframeSelectionContent : <type 'builtin_function_or_method'>
Message : <type 'builtin_function_or_method'>
MultiMessage : <type 'builtin_function_or_method'>
Polygonize : <type 'builtin_function_or_method'>
Read : <type 'builtin_function_or_method'>
ReadObject : <type 'builtin_function_or_method'>
Remove : <type 'builtin_function_or_method'>
RemoveUserData : <type 'builtin_function_or_method'>
Scale : <type 'builtin_function_or_method'>
SearchMaterial : <type 'builtin_function_or_method'>
SearchMaterialInc : <type 'builtin_function_or_method'>
SearchObject : <type 'builtin_function_or_method'>
SearchObjectInc : <type 'builtin_function_or_method'>
SendInfo : <type 'builtin_function_or_method'>
SetAction : <type 'builtin_function_or_method'>
SetActiveMaterial : <type 'builtin_function_or_method'>
SetActiveObject : <type 'builtin_function_or_method'>
SetActiveRenderData : <type 'builtin_function_or_method'>
SetActiveTag : <type 'builtin_function_or_method'>
SetAllBits : <type 'builtin_function_or_method'>
SetBit : <type 'builtin_function_or_method'>
SetChanged : <type 'builtin_function_or_method'>
SetData : <type 'builtin_function_or_method'>
SetDirty : <type 'builtin_function_or_method'>
SetDocumentName : <type 'builtin_function_or_method'>
SetDocumentPath : <type 'builtin_function_or_method'>
SetFps : <type 'builtin_function_or_method'>
SetKeyframeSelection : <type 'builtin_function_or_method'>
SetLOD : <type 'builtin_function_or_method'>
SetLayerData : <type 'builtin_function_or_method'>
SetLayerObject : <type 'builtin_function_or_method'>
SetLoopMaxTime : <type 'builtin_function_or_method'>
SetLoopMinTime : <type 'builtin_function_or_method'>
SetMaxTime : <type 'builtin_function_or_method'>
SetMinTime : <type 'builtin_function_or_method'>
SetMode : <type 'builtin_function_or_method'>
SetName : <type 'builtin_function_or_method'>
SetRenderLod : <type 'builtin_function_or_method'>
SetRewind : <type 'builtin_function_or_method'>
SetSelection : <type 'builtin_function_or_method'>
SetTime : <type 'builtin_function_or_method'>
SetUserDataContainer : <type 'builtin_function_or_method'>
StartUndo : <type 'builtin_function_or_method'>
ToggleBit : <type 'builtin_function_or_method'>
TransferGoal : <type 'builtin_function_or_method'>
Write : <type 'builtin_function_or_method'>
WriteObject : <type 'builtin_function_or_method'>
__call__ : <type 'method-wrapper'>
__class__ : <type 'type'>
__delattr__ : <type 'method-wrapper'>
__delitem__ : <type 'method-wrapper'>
__doc__ : <type 'str'>
__eq__ : <type 'method-wrapper'>
__format__ : <type 'builtin_function_or_method'>
__ge__ : <type 'method-wrapper'>
__getattribute__ : <type 'method-wrapper'>
__getitem__ : <type 'method-wrapper'>
__gt__ : <type 'method-wrapper'>
__hash__ : <type 'method-wrapper'>
__init__ : <type 'method-wrapper'>
__le__ : <type 'method-wrapper'>
__len__ : <type 'method-wrapper'>
__lt__ : <type 'method-wrapper'>
__ne__ : <type 'method-wrapper'>
__new__ : <type 'builtin_function_or_method'>
__reduce__ : <type 'builtin_function_or_method'>
__reduce_ex__ : <type 'builtin_function_or_method'>
__repr__ : <type 'method-wrapper'>
__setattr__ : <type 'method-wrapper'>
__setitem__ : <type 'method-wrapper'>
__sizeof__ : <type 'builtin_function_or_method'>
__str__ : <type 'method-wrapper'>
__subclasshook__ : <type 'builtin_function_or_method'>

All functions. There are days like that.

op

python


print type(op)

<type 'NoneType'>

It's a mystery.

help( op )

python


Welcome to Python 2.6!  This is the online help utility.
If this is your first time using Python, you should definitely check out
the tutorial on the Internet at http://docs.python.org/tutorial/.
Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules.  To quit this help utility and
return to the interpreter, just type "quit".
To get a list of available modules, keywords, or topics, type "modules",
"keywords", or "topics".  Each module also comes with a one-line summary
of what it does; to list the modules whose summaries contain a given word
such as "spam", type "modules spam".
help> 
You are now leaving help and returning to the Python interpreter.
If you want to ask for help on a particular object directly from the
interpreter, you can type "help(object)".  Executing "help('string')"
has the same effect as typing a particular string at the help> prompt.

???

Different from normal help (None) ……

python


#Help on the terminal(None)

>>> help(None)

Help on NoneType object:

class NoneType(object)
 |  Methods defined here:
 |  
 |  __hash__(...)
 |      x.__hash__() <==> hash(x)
 |  
 |  __repr__(...)
 |      x.__repr__() <==> repr(x)
(END) 

It seems that Python in Cinema 4D has dropped once and restarted. What is this

BaseObject Actually, op will be filled with ** when you select an object.

Make a cube and then ask


c4d.CallCommand(5159) #cube

print type(op)
<type 'c4d.BaseObject'>

It looks like an instance of c4d.BaseObject.

Help (op) again

python


help(op)

Help on BaseObject object:
class BaseObject(BaseList2D)
 |  Object base class.
 |  
 |  Method resolution order:
 |      BaseObject
 |      BaseList2D
 |      GeListNode
 |      C4DAtom
 |      __builtin__.object
 |  
 |  Methods defined here:
 |  
 |  AddDependence(...)
 |      Add a child object to the dependence list.
 |  
 |  CheckCache(...)
 |      Check if cache is built.
 |  
 |  CompareDependenceList(...)
 |      Compares if anything in the dependence list has changed.
 |  
 |  CopyMatrixTo(...)
 |      Copy the matrix of the object to another.
 |  
 |  CopyTagsTo(...)
 |      Copy the tags of the object to another.

(Omitted)

dir( op )

When I tried dir, this person also found that the contents were all uppercase letters and all functions.

python


print len( dir(op) )

168

sys

python


import sys
print sys.modules.keys()

['MacOS', 'subprocess', 'gc', 'c4d.modules', 'c4d.modules.particles', 'encodings.encodings', 'struct', 'c4d.modules.character.builder', 'c4dPyHelper', 'imp', 'c4d.utils', 'collections', 'zipimport', 'string', 'repr', 'signal', 'c4d.internals', 'pydoc', 'token', 'shlex', 'macostools', 'dis', 'cStringIO', 'encodings', 'abc', 're', 'UserDict', 'fcntl', 'c4d.utils.noise', 'inspect', 'exceptions', 'Carbon.Res', 'codecs', 'pkgutil', 'traceback', '_Res', 'itertools', 'opcode', 'os', 'marshal', '_collections', '_s
re', '__builtin__', 'operator', 'c4d.storage', 'select', 'c4d.modules.character', 'posixpath', 'errno', 'binascii', 'sre_constants', 'c4d', 'os.path', 'c4d.gui', 'c4d.modules.snap', 'Carbon', 'c4d.modules.onlinehelp', '_warnings', 'Carbon.Files', 'encodings.__builtin__', '_codecs', 'tokenize', 'c4d.plugins', 'webbrowser', 'Carbon.File', '_struct', 'keyword', '_File', 'posix', 'encodings.aliases', 'Carbon._Res', 'c4d.modules.hair', 'sre_parse', 'pickle', 'copy_reg', 'sre_compile', 'site', '__main__', 'c4d.m
odules.bodypaint', 'ic', 'strop', 'c4d.threading', 'encodings.codecs', 'Carbon._File', '_abcoll', 'c4d.documents', 'c4d.bitmaps', 'c4d.modules.thinkingparticles', 'genericpath', 'stat', 'warnings', 'encodings.ascii', 'time', 'sys', 'types', 'icglue', 'c4d.modules.render', 'c4d.modules.graphview', 'c4d.modules.mograph', 'linecache', 'Carbon.warnings']

You're reading a lot of ** below ** c4d.

python


print sys.getdefaultencoding()

ascii

Encode, ascii?

python


#Take a look at the file system as well.
print sys.getfilesystemencoding()

utf-8

From the terminal


>>> sys.getfilesystemencoding()
'utf-8'

Attitude that changes from system encoding.

python


print sys.argv

['']

python


print sys.stdin
print sys.stdout
print sys.stderr

<__main__.StdCatcher instance at 0x11b7191b8>
<__main__.StdCatcher instance at 0x11b7191b8>
<__main__.StdErrCatcher instance at 0x11b719170>

StdCatcher。。。

python


help( sys.stdin )

Help on instance of StdCatcher in module __main__:
class StdCatcher
 |  Methods defined here:
 |  
 |  flush(self)
 |  
 |  readline(self)
 |  
 |  write(self, st)


python


print sys.exec_prefix

/Applications/MAXON/CINEMA 4D R14/resource/modules/python/res/Python.osx.framework

print sys.prefix

/Applications/MAXON/CINEMA 4D R14/resource/modules/python/res/Python.osx.framework

python


print sys.executable

/Applications/MAXON/CINEMA 4D R14/CINEMA 4D.app/Contents/MacOS/CINEMA 4D

python


print sys.flags

sys.flags(debug=0, py3k_warning=0, division_warning=0, division_new=0, inspect=0, interactive=0, optimize=0, dont_write_bytecode=1, no_user_site=0, no_site=0, ignore_environment=0, tabcheck=0, verbose=0, unicode=0, bytes_warning=0)

dont_write_bytecode = 1, so Does not generate .pyc or .pyo.

"Command" family in c4d

Command Handlers.

ID=5159


#For example, for the ID 5159

c4d.CallCommand(5159) #cube

print c4d.GetCommandName(5159)
cube

print c4d.GetCommandHelp(5159)
Add a cube object

python


help(c4d.CallCommand)

Help on built-in function CallCommand in module c4d:
CallCommand(...)
    Call Command

...... Is it wrong to expect something from the help command?

What command is that ID?

Turn with for and try to inquire from one end. However, only those that start with "ID".

python


for i in dir(c4d):
    if i.startswith('ID'):
        tmpID = c4d.__dict__[i]
        if c4d.GetCommandName(tmpID):
            print i,tmpID,c4d.GetCommandName(tmpID)

result


IDM_CM_CLOSEWINDOW 12097 Close
IDM_COPY 12107 copy
IDM_CUT 12106 cut
IDM_DELETE 12109 Erase
IDM_INVERSION 12374 Invert all
IDM_KEY_LAST 12415 Move to previous key
IDM_KEY_NEXT 12416 Move to next key
IDM_PASTE 12108 paste
IDM_REDO 12297 Rerun
IDM_SELECTALL 12112 Select all
IDM_SELECTNONE 12113 Deselect all
IDM_UNDO 12105 Cancel
ID_BASECURVE 1015549 IGES curve
ID_BASEGROUP 1015545 IGES group
ID_BASESURFACE 1015548 IGES surface
ID_CAMERA_LOCK_PIVOT 440000104 Lock camera pivot
ID_CAMERA_MAGNIFY 1016008 Film zoom
ID_CAMERA_MOVE 1016007 Move film
ID_CAMERA_SET_PIVOT 1021420 Set camera pivot
ID_CAMERA_ZOOM 1016009 Film scaling
ID_CAMERA_ZOOM_IN 1016010 Zoom in
ID_CAMERA_ZOOM_OUT 1016011 Zoom out
ID_CA_CONSTRAINT_TAG_CLAMP_TARGET_COUNT 50000 Rendering settings
ID_CA_CONSTRAINT_TAG_MIRROR_TARGET_Show COUNT 70000 filter
ID_CA_CONSTRAINT_TAG_SPRING_TARGET_COUNT 60000 export filter
ID_CA_PAINT_TOOL_DISPLAY_COLOR 12002 Stop
ID_CONVERT_SELECTION_TOOL 1011181 Convert selection
ID_LASTTOOL_END 1021392 -
ID_LASTTOOL_START 1021385 Move
ID_MAPPEDCURVE 1015547 IGES Mapped curve
ID_MEASURE_TOOL 1011182 Measurement work
ID_MODELING_ARRANGE_TOOL 200000068 Arrange
ID_MODELING_ARRAY_TOOL 450000045 array
ID_MODELING_BEVEL_TOOL 450000005 bevel
ID_MODELING_BRIDGE_TOOL 450000008 bridge
ID_MODELING_BRUSH_TOOL 1016202 brush
ID_MODELING_CENTER_TOOL 200000071 Centering
ID_MODELING_CLONE_TOOL 450000042 clone
ID_MODELING_CLOSEHOLE_TOOL 450000010 Close polygon hole
ID_MODELING_COLLAPSE_COMMAND 1015924 Crush
ID_MODELING_DUPLICATE_TOOL 200000067 Duplicate
ID_MODELING_EDGECUT_TOOL 1009661 Edge cut
ID_MODELING_EDGE_SPLINE_COMMAND 1009671 Edge selection to spline
ID_MODELING_EXTRUDE_INNER_TOOL 450000004 Extruded into the plane
ID_MODELING_EXTRUDE_TOOL 1011183 Extrude
ID_MODELING_FILL_SELECTION_TOOL 1011178 Meet the selection
ID_MODELING_FREESELECTION 200000085 Lasso selection
ID_MODELING_IRON_TOOL 450000014 Iron
ID_MODELING_KNIFE_TOOL 1016030 knife
ID_MODELING_LIVESELECTION 200000083 Live selection
ID_MODELING_LOOP_TOOL 1011192 Loop selection
ID_MODELING_MAGNET_TOOL 1016185 Magnet
ID_MODELING_MATRIX_EXTRUDE_TOOL 1011126 Matrix extrusion
ID_MODELING_MELT_COMMAND 1010136 Melt
ID_MODELING_MOVE 200000088 move
ID_MODELING_NORMALMOVE_TOOL 450000000 Move along normal
ID_MODELING_NORMALROTATE_TOOL 450000002 Rotate along normal
ID_MODELING_NORMALSCALE_TOOL 450000001 Scale along normal
ID_MODELING_OM_SELECT_HIDE 1016208 Hide object
ID_MODELING_OM_SELECT_INVERT 1016207 Invert object selection
ID_MODELING_OM_SELECT_SHOW 1016209 Show object
ID_MODELING_OUTLINE_SELECTION_TOOL 1011179 Outline selection
ID_MODELING_POINT_ADD_TOOL 450000007 Create points
ID_MODELING_POLYGON_CREATE_TOOL 450000006 Create polygon
ID_MODELING_POLYSELECTION 200000086 Polygon selection
ID_MODELING_RANDOMIZE_TOOL 200000070 Randomize
ID_MODELING_RECTSELECTION 200000084 Rectangle selection
ID_MODELING_RING_TOOL 1011180 Ring selection
ID_MODELING_ROTATE 200000090 rotation
ID_MODELING_SCALE 200000089 scale
ID_MODELING_SETVALUE_TOOL 200000065 Align points values
ID_MODELING_SHORTCUT_SELECTVISIBLE 1016757 Switch only visible elements
ID_MODELING_SLIDE_TOOL 450000012 Sliding
ID_MODELING_SMOOTH_SHIFT_TOOL 450000003 Smooth shift
ID_MODELING_SPLINE_CHAMFER_TOOL 450000043 Chamfer
ID_MODELING_SPLINE_PROJECT_TOOL 450000046 Projection
ID_MODELING_SPLINE_ROUND_TOOL 450000039 Round
ID_MODELING_STITCHANDSEW_TOOL 450000011 Stitching
ID_MODELING_TRANSFER_TOOL 200000069 Transcription
ID_MODELING_WELD_TOOL 450000009 Join
ID_NGON_FORCERETRI_MENU 1016173 N-Update inside gon
ID_NGON_REMOVE_MENU 1016174 N-Remove gons
ID_NGON_RETRI_MENU 1016160 N-Always update inside gon
ID_OBJECTHANDLES_ONOFF_MENU 1016176 Show axis
ID_OPERATORPOOL_PLUGIN 1001138 XPresso pool
ID_SCALEDOCUMENT_CMD 200000277 Scale project...
ID_SDS_DEC_MENU 1016178 Reduced the number of divisions of Hyper NURBS
ID_SDS_INC_MENU 1016177 Increased the number of divisions of Hyper NURBS
ID_SDS_ONFFF_MENU 1016179 Isoline editing
ID_TREEVIEW_PLUGIN 1001145 XPresso Manager
ID_TRIMMEDSURFACE 1015546 IGES Trimmed Surface

There are some things like, oh, I think it was an ID that goes into here. Or rather, it seems that the correspondence between the ID and the content is written somewhere.

Summary

I'm tired so around here

It's an SDK so it's not that friendly (prejudice)

By the way, once While explaining the Python environment of Cinema 4D Actually, I think there was a rock article about Python (and open source culture). How about that (distant eyes) Was Python really bad? ?? ?? ?? ?? ?? ?? ?? ??

Isn't there any document that explicitly mentions what "op" is? let's search.

Remarks

Executing a function in the documentation

It often happens that you request id or a numerical value as an argument, What number should I put in! I feel like.

Generally, there is a table just below, and it seems that you can get an ID by adding "c4d." To the item name. (Same for c4d.VERSIONTYPE_BROADCAST at the beginning)

For example, gui.MessageDialog. c4d_doc.png

python


def main():
    gui.MessageDialog('Hello World!')

    gui.MessageDialog('Hello World!',c4d.GEMB_YESNOCANCEL)
    print c4d.GEMB_YESNOCANCEL # -> 3
    gui.MessageDialog( str(c4d.GEMB_YESNOCANCEL),3 )

I added 3 lines to the function written when I made a new one in the script manager. c4d_getID.png The figure is where the third dialog is displayed.

Script manager and command line

It's nice to write new code in the script manager, If this is the case, the executed script will not be output to the console. (Although it may be desirable)

When executed from the command line, the executed contents are also output to the console. [OK] is attached to the head.  c4d_cmdline.png

By the way, script manager doesn't work undo? Isn't that a demon?

reference

c4d module https://developers.maxon.net/docs/Cinema4DPythonSDK/html/modules/c4d/index.html

c4d.GetC4DVersion https://developers.maxon.net/docs/Cinema4DPythonSDK/html/modules/c4d/index.html#c4d.GetC4DVersion

c4d.documents.BaseDocument (= doc) https://developers.maxon.net/docs/Cinema4DPythonSDK/html/modules/c4d.documents/BaseDocument/index.html#c4d.documents.BaseDocument

c4d.BaseObject (= op) https://developers.maxon.net/docs/Cinema4DPythonSDK/html/modules/c4d/C4DAtom/GeListNode/BaseList2D/BaseObject/index.html#c4d.BaseObject

Command Handler https://developers.maxon.net/docs/Cinema4DPythonSDK/html/modules/c4d/index.html#command-handler

c4d.gui.MessageDialog https://developers.maxon.net/docs/Cinema4DPythonSDK/html/modules/c4d.gui/index.html#c4d.gui.MessageDialog

cookbook https://developers.maxon.net/docs/Cinema4DPythonSDK/html/misc/cookbook.html There are two example sentences

Examples https://github.com/PluginCafe/cinema4d_py_sdk Samples are available on github.

Recommended Posts

Find out about Cinema 4D's Python environment
Find out about launching Anaconda Prompt
Find out about Cinema 4D's Python environment
Find out about launching Anaconda Prompt
python beginners tried to find out
About python slices
About python comprehension
python DS debugging
Python environment construction
About Python tqdm.
python environment settings
About python yield
About python, class
python windows environment
Environment construction (python)
python comment out
About python inheritance
About python, range ()
python environment construction
Think about building a Python 3 environment in a Mac environment
Python --Environment construction
About python decorators
About python reference
About Python decorators
[Python] About multi-process
python environment construction
I used Python to find out about the role choices of the 51 "Yachts" in the world.
Write about building a Python environment for writing Qiita Qiita
Find out the location of Python class definition files.
python memo (for myself): About the development environment virtualenv
[Python] Chapter 01-02 About Python (Execution and installation of development environment)
About Python for loops
Find the maximum Python
Summary about Python scraping
[Python] Get environment variables
About function arguments (python)
My python environment memo
Unification of Python environment
python windows environment construction
homebrew python environment construction
[Python] Memo about functions
Summary about Python3 + OpenCV3
About Python, for ~ (range)
About Python3 character code
[Python] Memo about errors
Python, about exception handling
About Python Pyramid traversal
Create a Python environment
Development environment in Python
About Python3 ... (Ellipsis object)
[Python] Chapter 01-01 About Python (First Python)
[Python] About standard input
About __all__ in python
Mac environment construction Python
Virtual environment with Python 3.6
Python environment construction @ Win7
Python environment for projects
I tried to find out the outline about Big Gorilla
Find out the apparent width of a string in python
Python --Find out number of groups in the regex expression