Skip to content

Instantly share code, notes, and snippets.

@fwilleke80
Last active July 17, 2019 10:06
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/3f0e1bcad87c425fe096f5bc2f62f61b to your computer and use it in GitHub Desktop.
Save fwilleke80/3f0e1bcad87c425fe096f5bc2f62f61b to your computer and use it in GitHub Desktop.
[C4D] Save current document as template. Like the built-in script, just better, and in Python.
"""
Name-US:Save as template
Description-US:Saves the current document as template (hold CTRL to remove existing template, hold SHIFT to skip question dialog)
Name-DE:Als Template speichern
Description-DE:Speichert das aktuelle Dokument als Template (CTRL gedrückt halten um vorhandenes Template zu entfernen, SHIFT gedrückt halten um Abfrage zu überspringen)
"""
import os
import c4d
def main():
# Detect SHIFT key
res = c4d.BaseContainer()
if c4d.gui.GetInputState(c4d.BFM_INPUT_KEYBOARD, c4d.BFM_INPUT_QUALIFIER, res):
force = res[c4d.BFM_INPUT_QUALIFIER] & c4d.QSHIFT
remove = res[c4d.BFM_INPUT_QUALIFIER] & c4d.QCTRL
else:
force = False
remove = False
# Build target path
filename = os.path.join(
c4d.storage.GeGetStartupWritePath(), 'template.c4d')
# Ask user (or skip asking if force == True)
if not remove and (force or c4d.gui.QuestionDialog('Do you want to save the current document as template?')):
# Save document & set name
doc.SetDocumentName('template.c4d')
c4d.documents.SaveDocument(doc, filename, 0, c4d.FORMAT_C4DEXPORT)
print(filename + ' saved.')
elif remove and (force or c4d.gui.QuestionDialog('Do you really want to remove the current scene template?')):
# Delete template file
try:
os.remove(filename)
except OSError:
pass
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment