added .gitignore, scripts and FreeCAD-Template

This commit is contained in:
vaughn committed 2026-10-08 21:00:24 -04:00
1 parent 890906502a
commit 09baaba383
3 files changed
+91 -2

No files matched your search

+39 -2
View File
@@ -1,3 +1,40 @@
# FreeCAD-Template
# Tandem-t-slim-X2-Case-CAD
Template for FreeCAD project files
This is designed to serve as a base repository for use with FreeCAD projects.
Note: This does NOT version the .FCStd files directly, but rather allows you to unpack them for version control.
# How to Use
You will need to manually pack and unpack freecad files using the provided scripts (you may need to chmod +x the fc-pack and fc-unpack scripts). A total workflow looks like so:
>cd <project-dir>
> git clone . (or git pull for an existing repo)
>./fc-pack
Now open the file in FreeCAD, make any changes like normal, and save the file
>./fc-unpack
>git add *
>git push
# Additional options
fc-pack can take directories (or lists of directories) as an argument, if you would only like to work on a limited number of files in a repository.
Usage: fc-pack <dir-1> <dir-2> ...
with no arguments, fc-pack attempts to find all decompressed FreeCAD projects by searching for Document.xml files in the current directory and any subdirectories
fc-unpack can similarly take a file or list of files as an argument, if you would only like to commit changes to a limited number of FreeCAD projects in one repository.
Usage: fc-unpack <file-1> <file-2> ...
with no arguments fc-unpack attempts to find and unpack every .FCStd file in the current directory and any subdirectories
# Why?
Why use version control? You can roll back changes, create different concurrent versions by branching\*, and keep shared projects easily accessible in a shared location. This is just scratching the surface of what version control can do, generally, although this template only enables a small portion of that for FreeCAD projects.
# OK, but why like this?
The main benefit to handling files in this way is a reduced repository size, as you do not have one big binary blob added to the repo every commit.
Ostensibly, this also allows you to merge and parse changes in a human-readable way, but this is a tenuous claim; the structure of a FreeCAD project is not consistent and modular enough to ensure that two people's work won't conflict, even if you're working on entirely different parts of a .FCStd project.
Of course, you still get the other benefits of version control, and this allows your FreeCAD project files to sit neatly amongst your other versioned files, without bloating your repo, and without leaving them entirely unversioned.
This is a very simple set of files: the .gitignore, which ignores .FCStd files, an fc-unpack script that unzips the .FCStd files to their own folders, and an fc-pack script that uses freecad to [re]generate a .FCStd file from a directory to which a .FCStd file had previously been unpacked.
\*Merge at your own risk!
Executable
+22
View File
@@ -0,0 +1,22 @@
#!/bin/bash
#take specific directory/ies as arguments
dirs=("$@")
#if you don't give this command a list of directories to use, it will recursively search the current directory for the Document.xml project file, and use the parent directories of these to package .FCStd files
if [ "${dirs}x" == "x" ]
then
dirs=$(find . -iname "Document.xml" -printf "'%p'\n" | xargs dirname | sort -u)
fi
prev_dir=$(pwd)
echo "${dirs}" | while read -r d
do
cd "${d}"
fname=$(basename "${d}")
#freecad requires a specific structure to the zipped file, wherein the Document.xml file is first, then every file name that is parsed in the Document.xml file needs to come in that order; this ordering is not apparent when viewing the .zip archive with e.g. 7zip.
#there should not be a reason this is necessary, but it is, so we must depend on the user to have freecad installed for this script
freecad -c "from freecad import project_utility; project_utility.createDocument(\"$(pwd)/Document.xml\", \"../${fname}.FCStd\")"
#if freecad had a more normal structure for reading its own files, a simple zip command like below could be used
#zip -9 -q -r ../"${fname}".FCStd *
cd "${prev_dir}"
done
Executable
+30
View File
@@ -0,0 +1,30 @@
#!/bin/bash
#This script is designed to unpack every FreeCAD .FCStd project file into a folder in the same directory as the source file. All files in the current directory, or any subdirectories, will be processed
#take files as arguments
files=("$@")
#no arguments provided
if [ "${files}x" == "x" ]
then
#recursively find all .fcstd files in the current directory
files=$(find . -iname "*.fcstd")
fi
prev_dir="$(pwd)"
echo "${files}" | while IFS= read -r f
do
dir=$(dirname "${f}")
fn=$(basename "${f}")
name="${fn%.*}"
ext="${fn##*.}"
#only attempt this for .FCStd files
if [ "${ext,,}" == "fcstd" ]
then
#unzip into new folder in same directory as source file
cd "${dir}"
mkdir -p "${name}"
unzip -qq -d "${name}" -o "${fn}"
cd "${prev_dir}"
fi
done