THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 12/12/2012 at 13:36, xxxxxxxx wrote:
it is still not 100% clear to me what you want. since you are talking about modules,
i assume you are talking about multiple files. lets assume you have got 2 files.
c://myModule.py
myScriptfile.py
myScriptfile.py doens't have to be physically on your hardrive you can also create just in
the memory within the document. the import statements for myScriptfile.py would be :
import sys, os
__mypath__ = 'c:\\'
if __myPath__ not in sys.path: sys.path.insert(0, __myPath__)
import c4d, myModule
...
however, i am 100% sure one of the more experienced guys here will come arround
and tell us, that absolute paths are bad. so normally you would do something like that :
import sys, os
# that line is just working in a script/tag or node, for a plugin we had to use c4d.documents
# and so o. also the document has to be saved at leasst once, otherwise doc.GetDocumentPath()
# will be "".
if doc.GetDocumentPath() not in sys.path: sys.path.insert(0, doc.GetDocumentPath())
import c4d, myModule
or like this
__currdir__ = os.path.join(os.path.dirname(__file__) , 'modules')
if __currdir__ not in sys.path: sys.path.insert(0, __currdir__)
import c4d, myModule
you can also just drop the script into the c4d usersettings python modules folder.
ps : also note that python sometimes needs a __init__.py file (no content)
in the folder you want to become a module folder. i also never understood when
they have to be created and when not, so i just drop them here and there :)
pps: just to make it really clear. myModule.py has to exist before c4d has been started.
Any changes made to myModule.py while C4d is running , won't take any effect before
C4D has been restarted again.