Solved Issue with registering a ToolData


I'm aware, I'm doing something out of the box here. If it's too absurd, simply ignore my question.

For organizational reasons in a larger project, I'm trying to register a ToolData plugin from a "sub module".

This is roughly the intended project structure:

   |-- myplugin/
        |-- myplugin.pyp
        |-- subdir/
        |-- res/
             |-- usual suspects here

A link to a small example project follows at the end.

I'd like to call RegisterToolPlugin() from within as follows.

In myplugin.pyp:

import submodule # actually a tad bit more complicated, as the subdirs need to be manually added to the search path first



class HolyCowToolData(c4d.plugins.ToolData):

def RegisterSubmodule():
    c4d.plugins.RegisterToolPlugin(..., dat=HolyCowToolData())

This already worked for CommandData plugins or maybe also any plugin type, as long as no resource files are involved. But I doubt one can have a ToolData without at least a dummy resource...

In case of the above example with a dummy ToolData I end with the following error thrown by the call of RegisterToolPlugin():

ReferenceError:Could not find required '__res__'.

If I do instead in myplugin.pyp:

c4d.plugins.RegisterToolPlugin(..., dat=submodule.HolyCowToolData())

it works again. But for several reasons it is not what I'd like to have...

My guess is, C4D is somehow looking in the wrong place for the expected resource files. Yet, having another res folder in submodule doesn't make a difference. So I have no idea, where it's looking for resources. Then again, I may be misinterpreting the error message completely...

As said in the beginning, I'm aware I'm doing something esoteric here and I understand, if no time can be invested to support such stupid ideas. On the other hand I hope, above error message may ring a bell and I could get a hint, what to do differently.

Here's an example project (really just the few lines needed) demonstrating the issue (change REGISTER_HERE in myplugin.pyp from True to False to switch between both cases): (temporary link to my Dropbox, if a future reader still needs this, please PM me)
It also shows, with a CommandData the approach works in principal.

Thanks in advance.

Hi Andreas
The main issue is that a ToolData needs some resources while for a CommandData it's not mandatory.
So when registering a ToolData, Cinema 4D will look for the resource, which is stored into the __res__ variable.
But of course, this variable is defined only in the *.pyp and not all submodule that you create, which Cinema 4D don't have idea they exist before executing your code.

So there are 2 two ways to solve it.

  1. In your myplugin.pyp you can copy the __rest__ content to the submodule like so
submodule.__res__ = __res__
  1. In your SubModule you can load the resource directly from there like so, note this let you have a custom directory for your res folder.
# Path to the res folder
resDir = os.path.join(os.path.dirname(os.path.dirname(__file__)), "res")

__res__ = c4d.plugins.GeResource()
__res__.Init(dir) # Exposes res folder as a C4D Resource
__res__.InitAsGlobal() # Loads all Cinema 4D resource (with the previous resource we added in Init)

# Do you register here


Hi Maxime,

thanks a lot! Both are valid solutions for me. Very helpful.