FreeCad, can I set the default directory for my user files? Linux

WobblyHand

H-M Supporter - Diamond Member
H-M Lifetime Diamond Member
Joined
Dec 18, 2019
Messages
6,447
Haven't yet found a way to do this. Right now when I open a file, freecad automatically opens /home/wobblyhand but that's not where I keep my freecad files. I'd like to have the File Open & Save default to /home/wobblyhand/Documents/freecad. Is there a configuration file or setting I can change? Haven't found it in preferences. Opening to the wrong directory is just not an endearing feature.

Searching for FreeCad Start up and configuration, I find an environment variable named FREECAD_USER_HOME. Think this is the correct variable. Where and how can this be set? Thanks. Sorry for the linuxy question, rather than CAD.
 
If you're using a program launcher on your desktop you can edit it to change that environment variable. Right-click on the icon and see if "edit launcher" is one of the options. If so, you can insert something like "env FREECAD_USER_HOME = /whererever-you-want-your-files-to-go" in front of the executable. Or change it, if it's already there. After doing that you may find that the icon has changed. If so, you can get it back by clicking on the box next to the "icon" legend and selecting it in the list that pops up. This is how Ubuntu works but most modern linux distros have something similar.

If there's no launcher, you're still not out of luck. You can create a new launcher by simply right-clicking on a blank part of the desktop. If your current FreeCad setup places the executable on the desktop, you don't want to delete it, otherwise you will have to reinstall it.

The old-school way would be to write a shell script that sets the environment variable and then calls the program. You'd need to open a command-line interface or terminal emulator and type in the script name to fire up the program. The usual caveats apply -- change the script permissions to make it executable, and, depending on your current working directory, you might have to preface the script name with "./" -- assuming you don't want to type in the entire path.
 
If you're launching from a terminal, you could also just add export FREECAD_USER_HOME=/some-path to your ~/.bashrc or ~/.zshrc, depending on whether you're using bash or zsh.

I typically do what @homebrewed recommended and set up a little wrapper script, since I don't have a regular desktop environment. I have my $PATH variable set up to include a directory in my home dir, so I can just drop my script there and then launch my application from the terminal, or using dmenu. If you have a desktop environment, then I'd recommend trying the first approach @homebrewed called out.

My setup is like this (this is wrapping cargo, a tool for working with code written in Rust):
Bash:
❯ ls -lt /home/greg/bin
-rwxr-xr-x 1 greg greg       54 Jan 19  2021 cargo
❯ cat /home/greg/bin/cargo
#!/bin/bash
RUSTC_WRAPPER=sccache /usr/bin/cargo "$@"
❯ echo $PATH
/home/greg/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin
❯ grep PATH /home/greg/.zshrc
export PATH="$HOME/bin:$PATH"

You'd want to write something like this:

Bash:
#!/bin/bash
export FREECAD_USER_HOME=/wherever/you/want
# Assuming freecad is installed at /usr/bin, which may not be the case. You can figure this out by running type freecad in a terminal
exec /usr/bin/freecad "$@"

Again, this is only if you want to launch from a terminal, or using something like dmenu. If you prefer launching via a desktop, then there's no need to do all of this. I'm just a weirdo who does things the old-fashioned way.
 
Newer versions of Ubuntu like 20.04, the current stable LTS, don't allow creating launchers like you describe. The Gnome3 developers seemed to have decontented that ability. Find it quite annoying as I used to do just what you described for apps that I built. Now one has to do it the Debian way and do some additional bs. Successfully made a launcher that way once, but it really was unnecessarily painful.

Maybe the most expeditious way to get this done is via a bash script.

I had installed FreeCad using the stable PPA. It did not install a launcher. To launch, I either have to go to Show Applications and click, (what a lot of work just to launch!) or more usually, just type in freecad at the CLI.

Thanks @homebrewed and @Badabinski. One of these ideas will work!
 
Unfortunately, that environment variable seems to only affect where the configuration files are stored. It did not change the default save path in the bit of testing I did.
 
I just tested the FREECAD_USER_DATA env var and yeah: doesn't seem to apply to user files even though their documentation seems to indicate it should. I tested with the latest version (0.19). Like RandyWilson said: i see that FC creates it's temp directory under this defined path, but the file save doesn't honor the value.
 
As I read the Documentation that *HOME variable should set the base directory, and the *DATA variable will set the config file location, with a default of FREECAD_USER_HOME/.FreeCAD as the default.


Thus I can only conclude that the load/save function is broken in this respect. Seems to effect Windows, too.
 
Using the bash file did result in the File Open directory being in the right place. Some other things have clearly messed up, as the default workbench has been replaced with start. Doesn't know where recent files are either. Preferences have been all reset. Background back to gradient mode. Doesn't know about the macros I had loaded. No record of loaded workbenches. Foo. So using
FREECAD_USER_HOME
did more than just change where my CAD files are, it changed the location of the config files, which probably were auto regenerated to their defaults.

Reverting. Launched using CLI with just
Code:
$ freecad
. Everything is correct, save for the File Open Save location. Workbenches, macros, recent files are intact. At least I haven't lost those settings. Well, back to where I was. Thankful for that.
 
I have a work around. The load/save function will remember where it was during each session. So we can set it in a startup macro, just like the videos showed.

Create an empty file-part-body and save it in your data directory as <whatever-file>. Now, follow his startup macro, but rather than creating the file-part-body sequence, we load the file created above.
 
Back
Top