Programmatically set backup save options for Std Save

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
dunaden
Posts: 7
Joined: Wed Nov 18, 2020 2:43 pm

Programmatically set backup save options for Std Save

Post by dunaden »

I'm setting up a script to auto-generate some files on a Linux server. As part of the process I'm using Std Save to save some FreeCAD files as intermediary build files (from a makefile), code snippet below for reference. This ends up with some backup .FCstd1 files being generated - I would like to avoid this.

I am aware that I can set FreeCAD to not generate these files from the GUI by setting to false this parameter:
"Tools > Edit Parameters -> BaseApp > Preferences > Document > CreateBackupFiles"

What I would like to do is set this parameter programmatically (ideally from the python interface) so that I can avoid the backup files on a headless server (potentially dockerised to be spooled up and destroyed as needed).

Any help, advice or pointing me to where I can find things myself is appreciated!

Trivial code snippet for clarity:

Code: Select all

import FreeCAD
doc = FreeCAD.newDocument("someTrash")
doc.saveAs("~/my_file.FCstd")
# This line will create a .FCstd1 file unless the correct parameter is set in FreeCAD
doc.saveAs("~/my_file.FCstd")
And for completeness sake this is my home setup on which I'm testing things for now (and the version I'm intending to have deployed on the server which will be Ubuntu based).
OS: Linux Mint 19.3
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.4.
Build type: Release
Python version: 3.6.8
Qt version: 5.9.5
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/HongKong (en_HK)
Syres
Veteran
Posts: 2898
Joined: Thu Aug 09, 2018 11:14 am

Re: Programmatically set backup save options for Std Save

Post by Syres »

Something like:

Code: Select all

import FreeCAD
noBackupFiles = FreeCAD.ParamGet('User parameter:BaseApp/Preferences/Document')
noBackupFiles.SetBool("CreateBackupFiles", False)
User avatar
dunaden
Posts: 7
Joined: Wed Nov 18, 2020 2:43 pm

Re: Programmatically set backup save options for Std Save

Post by dunaden »

Perfect, that's exactly what I needed - thank you so much for the prompt and succinct help!
Post Reply