Jump to content

Sign in to follow this  

Cant create an Instance Object

Recommended Posts

Im still getting my bearings in Python for C4D...but of all the issues ive navigated, this incredibly simple one has be pulling my hair out.  

Just want to create an Instance Object based on Active Object.  Ive tried endless variations (got it working with callcommands but would rather avoid that method), and when I have what I feel like should be working, console outputs nothing.  Printing outputs "none".  Ive gone further to try to "set" referenced object with active which gave me the same result.  What obvious thing am I doing wrong?

import c4d
from c4d import gui

def main():
    obj = doc.GetActiveObject()

if __name__=='__main__':         


Share this post

Link to post


such questions are probably better asked over at the Plugin Café, where MAXON provides free support for developers.

Anyway, looking at the InstanceObject's __init__() function's documentation, it doesn't support a parameter to set the reference object, as you try to do it. Instead you could either set the "Reference Object" parameter like any other parameter or simply call the provided SetReferenceObject() function.

Like so (the undo stuff is completely optional):

import c4d

def main():
    if op is None:
    inst = c4d.InstanceObject()
    doc.AddUndo(c4d.UNDO_NEW, inst)

if __name__=='__main__':

Furthermore, as you can see in my example, in Script Manager there are some global variables predefined (actually that's true for all places, where one can use Python in C4D, yet, the available ones and their content differ a bit):

  • 'op' is the currently active object
  • 'doc' is the currently active document
  • ...

So there's no need to use GetActiveObject() in this context.


For more information I really recommend the docs and above mentioned Plugin Café as it already contains answers to loads of questions.

One additional note: As you are using InstanceObject class, which got introduced in R20, you'd probably want to update your profile with the actual version of C4D you are using. This will help people tremendously in helping you.



Edit: Fixed description of 'doc'

Share this post

Link to post
  • Topic Author
  • This is all fantastic advice/info, thanks a ton.  Im piecemealing what little knowledge i have with what examples/sdk info I can find and I could already tell im pulling from a wide range of time periods/envs/techniques, keeping scoped to the Script Manager variables will surely help me in my troubleshooting later. Will certainly keep Plugin Café in mind next time.    

    Share this post

    Link to post

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Reply to this topic...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    Sign in to follow this  

    • Recently Browsing   0 members

      No registered users viewing this page.

    • Create New...