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

    Creating python plugin results in error

    PYTHON Development
    0
    9
    2.5k
    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
      Helper
      last edited by

      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

      On 26/01/2011 at 14:49, xxxxxxxx wrote:

      The error i'm getting is: "Could not initialize global resource for the plugin"

      I'm new to C4D using Python and am a little frustrated just trying to register a helloworld plugin.
      using version R12.032 on Win7 box

      code:
      import os
      import sys
      import c4d
      from c4d import plugins, documents, utils

      PLUGIN_ID = 1000010

      class myFirstPlugin(c4d.plugins.ObjectData) :

      def Init(self, op) :
              c4d.gui.MessageDialog("Hello World")

      if __name__ == "__main__":
          bmp = c4d.bitmaps.BaseBitmap()
          dir, file = os.path.split(__file__)
          fn = os.path.join(dir, "res", "test.tif")
          bmp.InitWith(fn)

      try:
              result = c4d.plugins.RegisterObjectPlugin(
                  id = PLUGIN_ID, 
                  str = "myFirstPlugin", 
                  g = myFirstPlugin,      
                  description = "foo", 
                  info = c4d.OBJECT_GENERATOR | c4d.OBJECT_INPUT, 
                  icon = bmp
              )
              c4d.gui.MessageDialog("result is: " + result)
          except:
              exctype, value = sys.exc_info()[:2]
              c4d.gui.MessageDialog(value)

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

        THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

        On 26/01/2011 at 16:25, xxxxxxxx wrote:

        Got it.  I was missing a required file in my res folder:
        c4d_symbols.h

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

          THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

          On 26/01/2011 at 16:40, xxxxxxxx wrote:

          Yeah, that one always has to be there, as well as C4D_string.str.
          Some with C++ plugins.

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

            THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

            On 27/01/2011 at 06:44, xxxxxxxx wrote:

            Just a small addition: If you want to register a plugin not from the main *.pype, you have to redirect __res__ to the other modules scope.

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

              THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

              On 29/03/2011 at 06:11, xxxxxxxx wrote:

              Originally posted by xxxxxxxx

              Just a small addition: If you want to register a plugin not from the main *.pype, you have to redirect __res__ to the other modules scope.

              what does this mean?
              what would be the scope for a .py, or .pyp

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

                THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                On 30/03/2011 at 06:12, xxxxxxxx wrote:

                This is only important if you register plugins outside the *.pyp file.

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

                  On 05/01/2013 at 10:00, xxxxxxxx wrote:

                  Originally posted by xxxxxxxx

                  Just a small addition: If you want to register a plugin not from the main *.pype, you have to redirect __res__ to the other modules scope.

                  could someone explain that for me, i know what a scope is and i know what the res folder is, but
                  this doesn't make any sense for me. i have got the following plugin structure.

                  pluginfolder
                  ---res
                  ---mainplugin.pyp
                  ---subfolder
                  ------myNodes.pyp

                  and i want to register plugins from myNodes.pyp.

                  import os, sys, time
                    
                  __root__ = os.path.dirname(os.path.dirname(__file__))
                  if os.path.join(__root__, 'modules') not in sys.path: sys.path.insert(0, os.path.join(__root__, 'modules'))
                    
                  import c4d, eCon, cHelp
                  from c4d import bitmaps, plugins, documents
                    
                  # --------------------------------------------------------------------------------------------------------
                  # Base node class (dummy)
                  # --------------------------------------------------------------------------------------------------------
                  class OFhBaseNode(plugins.ObjectData) :
                  ...
                    
                  # --------------------------------------------------------------------------------------------------------
                  # Entry point
                  # --------------------------------------------------------------------------------------------------------
                  if __name__ == "__main__":
                    
                  ...
                    
                      plugins.RegisterObjectPlugin(id          = eCon.ID_ENR_BASENODE,
                                                   str         = "fhBaseNode",
                                                   g           = OFhBaseNode,
                                                   description = "ofhbasenode", 
                                                   icon        = None,
                                                   info        = c4d.OBJECT_GENERATOR)
                  

                  for the last line (info = c4d.OBJECT_GENERATOR), the console returns the following.

                  RuntimeError: Could not initialize global resource for the plugin.

                  I am not sure what i am meant to do. When i do not use subfolders my code works as expected, 
                  but when i use subfolders to structure the plugins in the menu i run into this problem.
                  edit : this also just hapens to the NodeData plugins , i have got a folder with a file with a bunch 
                  of CommandData plugins which are being loaded without any errors.

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

                    On 05/01/2013 at 20:07, xxxxxxxx wrote:

                    Hi Ferdinand,

                    the __res__ variable is available globally in a *.pyp file and is an instance of the
                    c4d.plugins.GeResource class. An instance of this class "represents the contents
                    of the plugins res folder folder" (if one can say it like this..)

                    It is necessary to load the NodeData's description. This is the reason why the
                    CommandData plugins don't cause any problems. If you do not pass the res
                    argument to a function registering a NodeData plugin, the object pointed to
                    by the __res__ variable is taken instead. If you register a NodeData plugin not
                    from a *.pyp file, you need to explicitly pass the __res__ from the *.pyp to the
                    plugin registration function.

                    Best,
                    Niklas

                    PS: This information was just written down from scratch, I don't give a warranty
                    for possible minor issues. 😉

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

                      On 06/01/2013 at 04:15, xxxxxxxx wrote:

                      hi nikklas,

                      by now i definitely owe you a beer 😂. worked like i charm, maxon should pay you 🙂
                      just to help people who might search for this in the future, here is the 'fix' for my
                      problem (you would have to adjust it to your actual folder structure, this is just one
                      up).

                      import os, sys, time
                        
                      __root__ = os.path.dirname(os.path.dirname(__file__))
                      if os.path.join(__root__, 'modules') not in sys.path: sys.path.insert(0, os.path.join(__root__, 'modules'))
                        
                      import c4d, eCon, cHelp
                      from c4d import bitmaps, plugins, documents
                        
                      __res__ = c4d.plugins.GeResource()
                      __res__.Init(__root__)
                      ...
                      
                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post