SaveDocument not updating C4D current document
-
On 19/01/2018 at 11:04, xxxxxxxx wrote:
Hi,
We have a function that will save a file to a specific location:
doc=c4d.documents.GetActiveDocument()
doc.SetDocumentName( filePath )
c4d.documents.SaveDocument( doc, str(filePath),
c4d.SAVEDOCUMENTFLAGS_DIALOGSALLOWED,
c4d.FORMAT_C4DEXPORT )This is saving the file as expected, however if I hit Ctrl+S to save over the working file, it does not recognize or know where the current file was saved. Is there an additional function that needs to be called to set the current working file location?
Thanks,
Andrew -
On 21/01/2018 at 10:29, xxxxxxxx wrote:
Hi Andrew! Did you try to add c4d.EventAdd() after the save function?
-
On 22/01/2018 at 05:35, xxxxxxxx wrote:
Hi Andrew, thanks for writing us.
With regard to your email, it's relevant to note that the path set for a document when saving is not the path used by Cinema when the "Open..." or "Save as..." commands are executed. The folder pointed by Cinema 4D to save or load a file via GUI can be retrieved via GeWorldContainerInstance() using the value ID 90003. Please note that this approach is not explicitly supported resulting in an hack rather than an official solution.
Best, Riccardo
-
On 22/01/2018 at 10:58, xxxxxxxx wrote:
Hi Cybor,
I tried adding the eventAdd function after the SaveDocument but it didn't seem to have any effect.
Thanks for the tip though.
-
On 22/01/2018 at 11:23, xxxxxxxx wrote:
Hi Riccardo,
Thanks for this. My question really is how do I let C4D know that the active document has just been saved so that a user hitting "Ctrl+S" to save over the existing document that was just saved with the API will not be presented with a dialog box?
Currently although the SaveDocument function will save the file appropriately, C4D seems to be completely unaware that the document was saved or where it was saved.
Additionally, if I goto close the document, C4D asks me if I want to save changes to my project. There have been no changes made and this dialog actually has the correct location for the project.
Using your advice I set the saved the filepath to the world container instance returned by GetWorldContainerInstance()....
c4d.documents.GetActiveDocument()
doc.SetDocumentName( filePath )
c4d.documents.SaveDocument( doc, str(filePath), c4d.SAVEDOCUMENTFLAGS_DIALOGSALLOWED, c4d.FORMAT_C4DEXPORT )
wci = c4d.GetWorldContainerInstance()
wci[90003] = str( filePath )This fixes the issue with the File/Close option not asking if I want to save the project when it has just been saved, however the File/Save function still presents me with a dialog box, but instead of the path being the last place I manually opened a file, it is defaulting to the root of my documents folder.
My steps are:
Open C4D
Create a cube
Save the project using the API
goto File/Save -- dialog box appears defaulting to ~/Documents (on Windows 7)The behavior I would expect here is that the project is saved to the location it was just saved to with no dialog, overwriting the file the API just created.
Thoughts?
Andrew -
On 22/01/2018 at 11:28, xxxxxxxx wrote:
As a side note here... If I open a project using the API, I can make changes and the File/Save menu option is working as expected.
-
On 22/01/2018 at 12:06, xxxxxxxx wrote:
I believe I found the fix... If I independently set both the document name and path then C4D would recognize the file..
In our original code we were just calling SetDocumentName before SaveDocument.
By calling both SetDocumentName and SetDocumentPath before calling SaveDocument everything at first glance appears to be working as expected.
It might be nice to have a list of requirements posted somewhere of all functions needed to properly save a file and giving C4D all of the expected info. Is there any other settings that we might be missing?
Thanks,
Andrew -
On 24/01/2018 at 01:28, xxxxxxxx wrote:
Hi Andrew, thanks for getting back here.
I apologize and admit that your approach is the correct one. I didn't paid attention to BaseDocument::SetDocumentPath() missing in your initial code and I provided a different solution to the problem.
Thanks for sharing your solution and keeping our knowledge-base "healthy".
Best, Riccardo