Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode.
Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).
Hi All,
I'm writing a plugin that imports, processes and exports 3d files (whatever cinema4d supports). It has two way of working:
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?
Hello,
there should be no problem importing *.py files form a *.pyp file. What do you mean with "import just doesn't work."?
*.py
*.pyp
For example: you can have a formulas.py file (next to your *.pyp) that looks like this:
formulas.py
def SomeCalculation(): return 5
you can import int in your *.pyp just with
import formulas
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.
__res__
best wishes, Sebastian
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
you find information on how to format code in this thread: How to Post Questions.
Thanks
Any hint why the hello world code I wrote is not working?
you might have to add the pyp file path to the system path using:
pyp
sys.path.append(os.path.dirname(__file__))
so
import sys import os sys.path.append(os.path.dirname(__file__)) import hello_function