Button in Object Generator plugin

On 08/01/2018 at 07:36, xxxxxxxx wrote:

I have an Object Generator plugin that has an only one button.
I want to perform some operations when pressing it.
For example, create a sphere and insert it under Object Generator plugin...

Here is how my code looks like, but it's not working...

import c4d
from c4d import plugins, utils
import os
  
TESTPLUGIN_ID = 1040447
TESTPLUGIN_VALUE = 1000
  
class Testplugin(c4d.plugins.ObjectData) :
  
    def Message(self, node, type, data) :
        if type == c4d.MSG_DESCRIPTION_COMMAND:
        if data["id"][0].id == TESTPLUGIN_VALUE:
                sphere = c4d.BaseObject(c4d.Osphere)
                sphere.InsertUnder(node)
        return True
  
if __name__ == "__main__":
    bmp = c4d.bitmaps.BaseBitmap()
    dir, file = os.path.split(__file__)
    fn = os.path.join(dir, "res", "icon.tif")
    bmp.InitWith(fn)
    result = plugins.RegisterObjectPlugin(
        id = TESTPLUGIN_ID, 
        str = "Test Plugin", 
        g = Testplugin, 
        description = 
        "Otestplugin", 
        info = c4d.OBJECT_GENERATOR, 
        icon = bmp)

On 08/01/2018 at 10:12, xxxxxxxx wrote:

Figured it out...

  1. import c4d
  2. from c4d import plugins, utils
  3. import os
  4.   
  5. TESTPLUGIN_ID = 1040447
  6. TESTPLUGIN_VALUE = 1000
  7.   
  8. class Testplugin(c4d.plugins.ObjectData) :
  9.   
  10.     def Message(self, node, type, data) :
  11.         if type == c4d.MSG_DESCRIPTION_COMMAND:
  12.             if data["id"][0].id == TESTPLUGIN_VALUE:
  13.                 sphere = c4d.BaseObject(c4d.Osphere)
  14.                 sphere.InsertUnder(node)
  15.         return True
  16.   
  17. if __name__ == "__main__":
  18.     bmp = c4d.bitmaps.BaseBitmap()
  19.     dir, file = os.path.split(__file__)
  20.     fn = os.path.join(dir, "res", "icon.tif")
  21.     bmp.InitWith(fn)
  22.     result = plugins.RegisterObjectPlugin(
  23.         id = TESTPLUGIN_ID, 
  24.         str = "Test Plugin", 
  25.         g = Testplugin, 
  26.         description = 
  27.         "Otestplugin", 
  28.         info = c4d.OBJECT_GENERATOR, 
  29.         icon = bmp)

On 08/01/2018 at 10:13, xxxxxxxx wrote:

I had to convert tabs into spaces

On 09/01/2018 at 02:51, xxxxxxxx wrote:

Hi Merk,

Python pays a lot of attention to indentation and is never suggested to mix up spaces and tabs. Beware for the next time 😉

Best, Riccardo