I don't know anything about plugins, but I had a similar problem recently when trying to reference a data file located in the same folder as my C4D scene, without resorting to the full path name (ie to make the folder more portable). This code worked for me
import c4d, os
def main():
directory = doc.GetDocumentPath() # get doc directory
datafilepath = os.path.join(directory, 'testfile.txt') # get data file full path
you might be able to adapt it to your needs
edit - this is the full answer I got from cg society
import os
def doc_path_join(doc, *filenames):
"""
Creates an absolute path given by a document and a filename.
The document must have a path, otherwise ValueError is raised.
Example:
doc_path_join(doc, "test.txt") # /example/path/test.txt
doc_path_join(doc, "..", "test.txt") # /example/test.txt
doc_path_join(doc, "tex", "test.txt") # /example/path/tex/test.txt
@param doc Instance of c4d.documents.BaseDocument. Must have a document path.
@param filenames Strings as filenames.
"""
directory = doc.GetDocumentPath()
if not directory:
raise ValueError("document has no path")
return os.path.join(directory, *filenames)