Plugin Cafe Homepage
Forum Home Forum Home > Plugin Cafe > PYTHON Development
  New Posts New Posts
  FAQ FAQ  Forum Search   Register Register  Login Login

Creating an c4d-object with python

 Post Reply Post Reply
Author
Message
casimirsmets View Drop Down
Member
Member


Joined: 2013 Apr 29
Location: Belgium
Online Status: Offline
Posts: 321
Post Options Post Options   Quote casimirsmets Quote  Post ReplyReply Direct Link To This Post Topic: Creating an c4d-object with python
    Posted: 2013 May 13 at 6:13am
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
Back to Top
littledevil View Drop Down
Member
Member
Avatar

Joined: 2012 Feb 09
Online Status: Offline
Posts: 727
Post Options Post Options   Quote littledevil Quote  Post ReplyReply Direct Link To This Post Posted: 2013 May 13 at 7:00am
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.
There are holes in the sky. Where the rain gets in.
But they're ever so small. That's why the rain is thin.
Back to Top
NiklasR View Drop Down
Member
Member


Joined: 2010 Dec 13
Location: Germany
Online Status: Offline
Posts: 2558
Post Options Post Options   Quote NiklasR Quote  Post ReplyReply Direct Link To This Post Posted: 2013 May 13 at 7:45am
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


Edited by NiklasR - 2013 May 13 at 7:45am
Back to Top
casimirsmets View Drop Down
Member
Member


Joined: 2013 Apr 29
Location: Belgium
Online Status: Offline
Posts: 321
Post Options Post Options   Quote casimirsmets Quote  Post ReplyReply Direct Link To This Post Posted: 2013 May 13 at 8:09am
Yes indeed, the noobs try it out :D

And thanx for your answer littledevil! It helped me much.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Bulletin Board Software by Web Wiz Forums® version 9.61 [Free Express Edition]
Copyright ©2001-2009 Web Wiz

This page was generated in 0.094 seconds.