Changing Object Props. / was: I quit,... [SOLVED]

  • On 26/10/2014 at 11:40, xxxxxxxx wrote:

    Please, if some one can help with this code.

    The issue : Every time I change a any property of the object created with this plugin, the materials get created again.

    I'm new on python and c4d sdk, but I've got some help from Sebastian in this forum and I've able to achieve this code. Please, can some one help me?

    -------------  _ myPlugin.pyp ----------------_
    import os
    import sys
    import c4d
    from c4d import gui, plugins, bitmaps, documents


    def CreateMaterialTag(name, color, light) :
        # doc
        doc = documents.GetActiveDocument()
        #Add Mat
        myMat = c4d.BaseMaterial(5703)
        myMat[c4d.MATERIAL_COLOR_COLOR] = color
        return myMat

    def GenSoftBox(op) :
        if not op: return
        # cube
        cube = c4d.BaseObject(c4d.Ocube)
        # insert cube into op
        myTag1 = c4d.TextureTag()
        myTag1[c4d.TEXTURETAG_MATERIAL] = CreateMaterialTag("SoftBoxBlack",c4d.Vector(0.01,0.01,0.05), False)
        # ADD TO SCENE

    class myPlugin(plugins.ObjectData) :

    def __init__(self) :

    def GetVirtualObjects(self, op, hierarchyhelp) :
            # Disabled the following lines because cache flag was set
            # So the cache build is done before this method is called
            dirty = op.CheckCache(hierarchyhelp) or op.IsDirty(c4d.DIRTY_DATA)
            if dirty is False: return op.GetCache(hierarchyhelp)

    def Init(self, op) :
            return True

    def Message(self, node, type, data) :
            if type==c4d.MSG_DESCRIPTION_COMMAND:
                if data['id'][0].id==SB_ON_OFF:
                    print "Pushed button with command ID"
            return True

    def main() :
        bmp = c4d.bitmaps.BaseBitmap()
        dir, file = os.path.split(__file__)
        fn = os.path.join(dir,"res","icon.tif")
            result = plugins.RegisterObjectPlugin(
                id = PLUGIN_ID,
                str = "myPlugin",
                g = myPlugin,
                description = "myDescription",
                info = c4d.PLUGINFLAG_SMALLNODE | c4d.OBJECT_INPUT,
                icon = bmp
            if (result) :
                print "Plugin initialized."

            exctype, value = sys.exc_info()[:2]
            print str(value)

    if __name__ == "__main__":

    I remarked the code where should look at, I believe I missing the method where the GenSoftBox() method should be called, but I really dont know what to do!!

    Any help will be appreciated!! Cheers!!

    BTW Sorry about my bad english.

  • On 26/10/2014 at 12:00, xxxxxxxx wrote:


    download the sdk there are several example plugins, for example the Py-RoundedTube, which is an object plugin. I started with those and it was really helpful.
    I guess your function should better be placed at GetVirtualObjects().

    Best wishes

  • On 27/10/2014 at 02:36, xxxxxxxx wrote:


    to help us understand your issue please share more information about what you are trying to do.

    An object's Init() function is not meant to be used to edit the document. It is supposed to be used to define default parameter values etc. when a new instance of this object was created. For different reasons multiple instances of an object can exist (so Init() may be called multiple times).

    Also, a generator plugin typically does not create objects by making them child objects of itself. A generator creates virtual child objects in GetVirtualObjects(). These virtual child objects are re-created every time the generator object becomes dirty. To use your object as a generator you must set the OBJECT_GENERATOR   flag in RegisterObjectPlugin ().

    Since GetVirtualObjects() creates virtual child objects you should not create materials in that context because creating materials means to edit the document (which you should not do in this function, see Important Threading Information and Threading). So you should create the materials based on some user interaction (like pressing a button etc.).

    As Martin said, please take a look at the RoundedTube example.

    best wishes,

Log in to reply