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).
On 10/06/2015 at 04:53, xxxxxxxx wrote:
Hello again, 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:
Hi Holger,
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:
Hi Andreas, 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[0], now - os.path.getctime(files[0]) # Iterate over all remaining files. for f in files[1:]: age = now - os.path.getctime(f) if gt(age, oldest[1]) : # Set new oldest. oldest = f, age # Return just the name of oldest file. return oldest[0] 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)
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. Parameters:|
LoadFile()
MemoryFileStruct
StatusSetBar()
BaseThread
Return type:| [BaseDocument](file:///C:/Users/Tangerine/Desktop/Python%20Docs%20R14/help/modules/c4d.documents/BaseDocument/index.html#c4d.documents.BaseDocument)
BaseDocument
Returns:| Document that was loaded, or None if it failed. _tr>
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()
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.