Press "Yes" when document is opened?



  • Hi,

    I'm trying to open several old documents and save them with the current version.
    The script works but I had to press "Yes" for every document.
    You can see an illustration of the problem here:
    https://www.dropbox.com/s/6ijne28u5unlgej/c4d114_press_yes_python.png?dl=0

    Is there a way around this?

    Thank you for looking at the problem

    You can see the script below

    import c4d
    import os
    
    def main():
    
        for subdir, dirs, files in os.walk('D:\modifyMe'):   
            for file in files:
                filepath = os.path.join(subdir, file)
                flags = c4d.SCENEFILTER_OBJECTS | c4d.SCENEFILTER_MATERIALS 
        
                doc = c4d.documents.LoadDocument(filepath, flags)
                c4d.documents.InsertBaseDocument(doc)
                c4d.documents.SetActiveDocument(doc)
                c4d.CallCommand(12098, 12098) # Save
                
                c4d.documents.CloseAllDocuments()
                
                c4d.EventAdd()
                
    
    if __name__=='__main__':
        main()
    


  • Hello,

    can you provide some old files to reproduce the issue?

    best wishes,
    Sebastian



  • Hi @s_bach

    Can you check on this one?
    https://www.dropbox.com/s/zcgvmw5fe8m126f/c4d114_press_yes_python_hamster_run.zip?dl=0

    You need to open it in version other than R20 otherwise it won't work.
    Let me know if you need anything else.



  • Hello,

    The dialog box is not opened when you load the document. The dialog box is opened when you try to save it using CallCommand().

    Using CallCommand() is the exact same as pressing the button in the UI. So there is nothing to prevent that dialog when you use CallCommand().

    But to save the file, you can simply use c4d.documents.SaveDocument(). This should show no pop-up dialog.

    flags = c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST
    c4d.documents.SaveDocument(loadedDoc, finalUpdatedPath, flags, c4d.FORMAT_C4DEXPORT)
    

    Also, it looks like you are creating something similar to the Scene Updater. This plugin is also written in Python, so you might find some inspiration in its source code.

    best wishes,
    Sebastian



  • @s_bach
    RE: The dialog box is not opened when you load the document. The dialog box is opened when you try to save it using CallCommand().

    Thanks for the clarification.
    The code you presented works as expected. Thank you!


Log in to reply