Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Recent
    • Tags
    • Users
    • Login

    Creating an c4d-object with python

    Scheduled Pinned Locked Moved PYTHON Development
    4 Posts 0 Posters 446 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      Helper
      last edited by

      On 13/05/2013 at 06:13, xxxxxxxx wrote:

      If I try to load my plugin, I get the following error:

      ReferenceError: the object 'c4d.documents.BaseDocument' is not alive

      Here is my code:

      import c4d
      import os
      import sys
      from c4d import gui, plugins, bitmaps, documents, utils

      PLUGIN_ID = 1000002 # Test ID

      MY_BUTTON           = 11005

      global doc
      doc = c4d.documents.GetActiveDocument()

      def AddObject(doc) :

      NewObject = c4d.BaseObject(c4d.Ocube)
        NewObject[c4d.PRIM_CUBE_LEN,c4d.VECTOR_Y] = 100
        NewObject.SetName('New Object')
        doc.InsertObject(NewObject)
        c4d.EventAdd()

      -> After that AddObject gets called in another function.

      Does anybody know what I am doing wrong?

      Greetings,

      Casimir Smets

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        On 13/05/2013 at 07:00, xxxxxxxx wrote:

        don't define your document as a global variable. it will be run when the plugin is being loaded
        (at c4d start up). generally do not define anything as a global variable except from constants 
        like plugin IDs or strings.

        either grab the document manually in the addobject method or pass it to the method. almost 
        all overwriteable plugin methods provide the active document. either as a direct parameter or 
        like the NodeData plugins by the basedocument attached to the passed node - GeListNode.
        GetDocument().

        if you do really need a variable to be accessible for multiple methods make it a class member.

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          On 13/05/2013 at 07:45, xxxxxxxx wrote:

          I've seen this so often. I'm really interested why people think that they need to grab the active
          document at the top level of the plugin instead of the place where they actually need it. Seems to
          be something everyone does when starting out. Tongue

          1 Reply Last reply Reply Quote 0
          • H Offline
            Helper
            last edited by

            On 13/05/2013 at 08:09, xxxxxxxx wrote:

            Yes indeed, the noobs try it out 😄

            And thanx for your answer littledevil! It helped me much.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post