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
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Button in Object Generator plugin

    Scheduled Pinned Locked Moved PYTHON Development
    4 Posts 0 Posters 513 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 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)
      
      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        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)
        
        
        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

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

          I had to convert tabs into spaces

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

            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

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