Creating python plugin results in error
-
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 boxcode:
import os
import sys
import c4d
from c4d import plugins, documents, utilsPLUGIN_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) -
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 -
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. -
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.
-
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 -
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.
-
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.pypand 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. -
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,
NiklasPS: This information was just written down from scratch, I don't give a warranty
for possible minor issues. -
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__) ...