Load Document with Documentpath [SOLVED]
On 10/06/2015 at 04:53, xxxxxxxx wrote:
I have a problem with loading a file. I use c4d.documents.LoadFile() to load a File into the Editor. The Problem is that all Texturelinks are gone as the Document does not have a Location. Also When I want to save the File a dialog opens where to save.
What I want is basically the same behavior as the Usual Load-File function of C4D when I press ctrl+O.
Is there a solution?
On 10/06/2015 at 06:54, xxxxxxxx wrote:
unfortunately I can not reproduce your problem.
For me LoadFile() works as expected and just the way, you'd like it to behave.
So you will probably need to provide me with more details. C4D version, operating system, maybe also a complete code line showing the invocation of LoadFile().
On 10/06/2015 at 07:38, xxxxxxxx wrote:
Here is the Code I am using. I found some snippet on the web to get the last modfied File in a Folder and load that. When it load all the TexturePaths are gone and I have to save the document
import c4d, os, glob, time, operator from c4d import gui from c4d import documents def get_oldest_file(files, _invert=False) : gt = operator.lt if _invert else operator.gt # Check for empty list. if not files: return None # Raw epoch distance. now = time.time() # Select first as arbitrary sentinel file, storing name and age. oldest = files, now - os.path.getctime(files) # Iterate over all remaining files. for f in files[1:]: age = now - os.path.getctime(f) if gt(age, oldest) : # Set new oldest. oldest = f, age # Return just the name of oldest file. return oldest def get_youngest_file(files) : return get_oldest_file(files, _invert=True) def main() : FilePath="/Users/holgerbiebrach/Aktuelle Projekte/1502_TS_burnedoutcar/c4d/BurnedCar_LODs_001.c4d" FileDir=os.path.dirname(FilePath) os.chdir(FileDir) files = glob.glob('*.c4d') c4d.documents.LoadFile(get_youngest_file(files)) c4d.EventAdd() if __name__=='__main__': main() c4d.EventAdd()
On 10/06/2015 at 16:28, xxxxxxxx wrote:
Try using LoadDocument() instead of LoadFile() :
_<_dt id="c4d.s.load" style="line-height: 16.5px; : rgb251, 234, 174;"_>_
c4d.documents.LoadDocument(name, loadflags[, thread])(file:///C:/Users/Tangerine/Desktop/Python%20Docs%20R14/help/modules/c4d.documents/index.html?highlight=documents#c4d.documents.LoadDocument)
Similar to [
LoadFile()](file:///C:/Users/Tangerine/Desktop/Python%20Docs%20R14/help/modules/c4d.documents/index.html?highlight=documents#c4d.documents.LoadFile) but this time the document isn't put into the editors list of documents and you have control over the document.
- name (str or [
MemoryFileStruct](file:///C:/Users/Tangerine/Desktop/Python%20Docs%20R14/help/modules/c4d.storage/MemoryFileStruct/index.html#c4d.storage.MemoryFileStruct)) – The file to load.
- loadflags (int) –
Flags for the loader:
| SCENEFILTER_0| No flags.
SCENEFILTER_OBJECTS| Load/save only the objects and associated items, such as materials used.
SCENEFILTER_MATERIALS| Load/save only the materials.
SCENEFILTER_DIALOGSALLOWED| Flag to inform your plugin that a dialog can be displayed if you wish, if this flag not set then no dialogs must be opened.
SCENEFILTER_PROGRESSALLOWED| Flag to inform your plugin that a progress bar can be displayed if you wish. The progress bar can be set by calling [
SCENEFILTER_MERGESCENE| Flag to inform your plugin that this is a merge operation, i.e. that the document you are inserting to is an existing scene.
SCENEFILTER_NONEWMARKERS| Objects loaded from disk will keep their markers
SCENEFILTER_SAVECACHES| Caches of objects will also be written (only supported by C4D file format). This equals the global option "Save Polygon Objects for Melange Exchange"<_<_t_>_
- thread ([
BaseThread](file:///C:/Users/Tangerine/Desktop/Python%20Docs%20R14/help/modules/c4d.threading/BaseThread/index.html#c4d.threading.BaseThread)) – The current thread, or None for the main CINEMA 4D thread.
Document that was loaded, or None if it failed.
Here's roughly how i've used it:
file = documents.LoadDocument(filePath, c4d.SCENEFILTER_OBJECTS | c4d.SCENEFILTER_MATERIALS | c4d.SCENEFILTER_MERGESCENE) documents.InsertBaseDocument(file) doc = documents.GetActiveDocument()
- name (str or [
On 11/06/2015 at 02:04, xxxxxxxx wrote:
the problem arises from changing the directory to the project directory and then loading the document without any path.
Change your main function like this:
def main() : FilePath="/Users/holgerbiebrach/Aktuelle Projekte/1502_TS_burnedoutcar/c4d/BurnedCar_LODs_001.c4d" FileDir=os.path.dirname(FilePath) os.chdir(FileDir) files = glob.glob('*.c4d') foundFile = get_youngest_file(files) foundFull = FileDir + "/" + foundFile # re-add the full path c4d.documents.LoadFile(foundFull) c4d.EventAdd()
On 11/06/2015 at 02:35, xxxxxxxx wrote:
Hey Andreas, Thanks a lot. That is working now. The Problem I am facing now is that this is not OS independed as because of "/".
How could I make this work on OSX and Windows?
On 11/06/2015 at 02:38, xxxxxxxx wrote:
It should already work on both. C4D will take care and convert / to \ on Windows.
Actually I tested the above code on Windows.
On 11/06/2015 at 03:02, xxxxxxxx wrote:
oh..great! Thanks a lot.