Modular plugin programming
Rage last edited by s_bach
I'm writing a plugin that imports, processes and exports 3d files (whatever cinema4d supports). It has two way of working:
- using parameter -scene, it checks merges all the top level objects and check if there are duplicates, and then checks if the object is already stored in a database
- using parameter -object, it just merges everything in the scene (removing cameras lamps etc) and then exports the object
I wanted to keep the code in modules, storing the first part in a scene_exporter.py and the second one in object_exporter.py and here comes the problems. I don't know if it's because the plugin is in a .pyp file, but the import just doesn't work.
What should I do to keep the code modular?
s_bach last edited by
there should be no problem importing
*.pyfiles form a
*.pypfile. What do you mean with "import just doesn't work."?
For example: you can have a
formulas.pyfile (next to your
*.pyp) that looks like this:
def SomeCalculation(): return 5
you can import int in your
and then use
number = formulas.SomeCalculation()
It gets a little bit more complicated if you want to register plugins in your sub-modules. In that case you would have to hand over the
__res__structure to these modules.
Rage last edited by Rage
Let me share you an example.
This is a simple hello world program.
In 'hello.pyp' I have (how do I format the text to code?):
import c4d import sys import hello_function def PluginMessage(id, data): if id==c4d.C4DPL_COMMANDLINEARGS: hello_function.say('Hello World') return True return False
In 'hello_function.py' I have:
def say(word): print(word)
When I run this from commandline, in the console I get the error that the hello_function package has not being found. They're on the same folder. I don't see any reason why this is not working
s_bach last edited by
you find information on how to format code in this thread: How to Post Questions.
Rage last edited by
Any hint why the hello world code I wrote is not working?
s_bach last edited by s_bach
you might have to add the
pypfile path to the system path using:
import sys import os sys.path.append(os.path.dirname(__file__)) import hello_function