Skip to content

Instantly share code, notes, and snippets.

@fwilleke80
Last active July 17, 2019 10:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fwilleke80/d4fa5a587bcc18a44b866e478a05e83d to your computer and use it in GitHub Desktop.
Save fwilleke80/d4fa5a587bcc18a44b866e478a05e83d to your computer and use it in GitHub Desktop.
Close all open documents in Cinema 4D, even the unsaved ones, skip the Save question for each one
"""
Name-US:Close all documents
Description-US:Close all open documents, even the unsaved ones (hold SHIFT to skip the question)
Name-DE:Alle Dokumente schließen
Description-DE:Schließt alle Dokumente, auch die ungespeicherten (SHIFT halten um die Abfrage zu unterdrücken)
"""
import c4d
def CountOpenDocuments():
# Iterate documents
currentDocument = c4d.documents.GetFirstDocument()
if not currentDocument:
return 0
documentCounter = 0
while currentDocument:
documentCounter += 1
currentDocument = currentDocument.GetNext()
return documentCounter
def KillAllDocuments():
# Iterate documents
currentDocument = c4d.documents.GetFirstDocument()
if not currentDocument:
return 0
documentCounter = 0
while currentDocument:
closeDocument = currentDocument
currentDocument = currentDocument.GetNext()
# Remove document from list, and kill it
closeDocument.Remove()
c4d.documents.KillDocument(closeDocument)
# Increase counter
documentCounter += 1
return documentCounter
# Main function
def main():
# Detect SHIFT key
force = False
res = c4d.BaseContainer()
if c4d.gui.GetInputState(c4d.BFM_INPUT_KEYBOARD, c4d.BFM_INPUT_QUALIFIER, res):
force = res[c4d.BFM_INPUT_QUALIFIER] & c4d.QSHIFT
documentCounter = CountOpenDocuments()
if force or c4d.gui.QuestionDialog('Really close all ' + str(documentCounter) + ' documents, even the unsaved?' if documentCounter > 1 else 'Really close the open document without saving?'):
documentCounter = KillAllDocuments()
c4d.StatusSetText('Closed ' + str(documentCounter) +
' documents.' if documentCounter > 1 else 'Closed the open document.')
# Execute main()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment