Please preset filename for export

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
Ank
Posts: 101
Joined: Thu Sep 19, 2019 5:22 pm

Please preset filename for export

Post by Ank »

I design things, export to STL, revise, export again.
Every time, the export filename is blank.

Please populate the default export filename to be the name of the FreeCAD filename.
chrisb
Veteran
Posts: 54197
Joined: Tue Mar 17, 2015 9:14 am

Re: Please preset filename for export

Post by chrisb »

I support this. As a workaround I can - from the second export on - just click on the existing file. This may be OS dependant.

OS: macOS 10.15
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.23258 (Git)
Build type: Release
Branch: master
Hash: 78c6cc1362c39e3f1f778c52ae2a1c82badeec20
Python version: 3.8.6
Qt version: 5.12.5
Coin version: 4.0.0
OCC version: 7.4.0
Locale: C/Default (C)
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
kisolre
Veteran
Posts: 4166
Joined: Wed Nov 21, 2018 1:13 pm

Re: Please preset filename for export

Post by kisolre »

Maybe have a format string - file name, body name, feature if selected, ...
User avatar
chennes
Veteran
Posts: 3909
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Please preset filename for export

Post by chennes »

Related: issue #3131.
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
User avatar
yorik
Founder
Posts: 13660
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Please preset filename for export

Post by yorik »

The export name should indeed take the filename (or document name?) by default...
User avatar
chennes
Veteran
Posts: 3909
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Please preset filename for export

Post by chennes »

Would you implement this as an optional last parameter to Gui::FileDialog::getSaveFileName()? Or as a static variable set on the FileDialog class? Or something else? getSaveFileName() is called around 40 places in the code (though some of those calls are actually to the QFileDialog, not the wrapper class), so I think we'd want the parameter to be optional.
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
User avatar
yorik
Founder
Posts: 13660
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Please preset filename for export

Post by yorik »

chennes wrote: Tue Dec 15, 2020 4:17 pm Would you implement this as an optional last parameter to Gui::FileDialog::getSaveFileName()? Or as a static variable set on the FileDialog class? Or something else? getSaveFileName() is called around 40 places in the code (though some of those calls are actually to the QFileDialog, not the wrapper class), so I think we'd want the parameter to be optional.
I think I'd indeed pass it as the last optional argument to Gui::FileDialog::getSaveFileName(). I believe there must be one central place where this is done for all export types, as the individual exporters already get objects list + filename. I would bet on https://github.com/FreeCAD/FreeCAD/blob ... c.cpp#L301

This should be easy to implement, but it probably needs some testing to make sure no file is overwritten accidentally, as the file extension doesn't appear in the export dialog.

A further improvement could be to add the file extension and change it when the filetype filter changes..
User avatar
chennes
Veteran
Posts: 3909
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Please preset filename for export

Post by chennes »

I did not realize that if the parameter named dir to getSaveFileName() includes not just a directory, but also a filename, then this dialog will already almost do what we want it to. Although the QFileDialog::setDirectory() method discards the filename when it is called, if we are using the native file dialog, that static method does not discard the filename, and will select it as needed. So I believe only a small tweak to the non-native dialog code is needed to also select the file, if there is one. There is no change to the method signature. Finally, the calling code just needs to be modified to include a default filename.
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
User avatar
chennes
Veteran
Posts: 3909
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Please preset filename for export

Post by chennes »

kisolre wrote: Mon Dec 14, 2020 10:18 pm Maybe have a format string - file name, body name, feature if selected, ...
I'm not sure the first implementation will have this, or at least it may not expose it to the end user, but I am giving it some thought. Can you help me generate a list of things that would make sense in the default filename? Some people's workflows are very export-heavy, and a good default filename could be a big time saver. The obvious things I can think of are:
  • FCStd filename of the active file (can you select things across files to export?)
  • Label of the selected object if there is only one (what if there are multiple?)
  • Label of the selected object's parent in the GUI (how far up the tree?)
  • Custom text
  • Date/Time
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
chrisb
Veteran
Posts: 54197
Joined: Tue Mar 17, 2015 9:14 am

Re: Please preset filename for export

Post by chrisb »

I have commented in the developer forum, and I think you made an excellent proposal.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
Post Reply