Cura can display fancy 3D models for your printer. Some printer models, like the CR6-SE definition that I use don’t have their platform
metadata value set. This is is fine, and the user will see a generic build plate sized to the printable area. However I can never remember how the virtual build plate is oriented with respect to the physical one. My Saturday afternoon mission was to add a platform model to my configuration to help my brain figure this out.
I don’t need a full-blown model of the entire machine like in the picture (Also, I haven’t seen any 3D models of the CR-6 SE) but I have a WhamBam flex plate that I love. My idea was to make a model of just that build plate so that the tabs will give me orientation.
Cura has documentation on how to add new machines and the definition file format (which may have been helpful if I had found it before I was done…), but I didn’t really want to create a new machine: I wanted to modify my existing configuration without losing any of my settings. I needed to play around with the configuration files quite a bit to make this happen, so my first step was to make a backup!
CuraVersion="4.13"
CuraShare="$HOME/.local/share/cura/$CuraVersion"
CuraConfig="$HOME/.config/cura/$CuraVersion"
CuraCache="$HOME/.cache/cura/$CuraVersion"
mkdir -p "$CuraCache"
DateString=$(date +%Y-%m-%d_%H-%M-%S)
tar -caf "$CuraCache/backup.$DateString.tar.gz" -P "$CuraShare" "$CuraConfig"
This made restoring very easy while I was developing my cura-modify.sh script – and in fact I ran it as the first thing to get a clean slate every time.
BackupToRestore="$CuraCache/backup.2022-01-29_17-11-54.tar.gz"
rm -rf "$CuraShare" "$CuraConfig"
tar -xaf "$BackupToRestore" -P
Here are the commands that modify the existing config files to rename the printer, which allows point at a new definition file later.
# Modification settings
OldPrinterModelName="Creality CR-6 SE"
NewPrinterModelName="MyPrinter"
# Switch active printer
sed -i "s/$OldPrinterModelName/$NewPrinterModelName/g" "$CuraConfig/cura.cfg"
# Rename files
OldPrinterFileName="${OldPrinterModelName// /+}"
NewPrinterFileName="${NewPrinterModelName// /+}"
DefChgSetFile="$CuraShare/definition_changes/${NewPrinterFileName}_settings.inst.cfg"
mv "$CuraShare/definition_changes/${OldPrinterFileName}_settings.inst.cfg" "$DefChgSetFile"
MachInstFile="$CuraShare/machine_instances/${NewPrinterFileName}.global.cfg"
mv "$CuraShare/machine_instances/${OldPrinterFileName}.global.cfg" "$MachInstFile"
UserInstFile="$CuraShare/user/${NewPrinterFileName}_user.inst.cfg"
mv "$CuraShare/user/${OldPrinterFileName}_user.inst.cfg" "$UserInstFile"
# Update model name in files
sed -i "s/$OldPrinterModelName/$NewPrinterModelName/g" "$DefChgSetFile"
sed -i "s/$OldPrinterModelName/$NewPrinterModelName/g" "$MachInstFile"
sed -i "s/$OldPrinterModelName/$NewPrinterModelName/g" "$UserInstFile"
# Point to new definition file
OldPrinterDefinition=$(grep --regexp='^definition = .*' "$DefChgSetFile" | cut -d '=' -f 2 | tr -d ' ')
NewDefinitionName="${NewPrinterModelName// /_}Def"
sed -i "s/$OldPrinterDefinition/$NewDefinitionName/g" "$DefChgSetFile"
sed -i "s/$OldPrinterDefinition/$NewDefinitionName/g" "$MachInstFile"
sed -i "s/$OldPrinterDefinition/$NewDefinitionName/g" "$UserInstFile"
I still needed the mesh to display for the definition file itself, so I sketched the build plate in OnShape. I found that Uranium (the application behind the Cura UI) wants the mesh origin at the center of the printable area, with X pointing right and Z up (same as the Cura axes).
Now came the tricky part. Every bit of info I’ve found tells you to put your platform mesh file in the resources/meshes/
directory inside the installation folder of Cura. This can be done in a Windows installation or if you have built Cura from source, but I use the distributed AppImage binary. AppImages don’t (easily) allow these sort of shenanigans.
Going through the Uranium source code that handles resource paths I noticed that the definition file is always used as a relative path to the built-in resources directory, which lives at /tmp/.mount_Ultima******/usr/bin/resources
(with the *s being different on every invocation). This allows to calculate the relative path to the filesystem root /
as ../../../../../..
and from there to the “absolute” path of the platform mesh file!
I downloaded the .STL export of my build plate model to ~/.local/share/cura/4.13/meshes/whambam-pex-255-45.stl
and finally created the definition file using the relative path as described.
# Get custom platform file
MeshesDir="$CuraShare/meshes"
mkdir -p "$MeshesDir"
PlatformFile="$MeshesDir/whambam-pex-255-45.stl"
# Meshes are only looked for in /tmp/.mount_Ultima******/usr/bin/resources/meshes
RelativePathToPlatform="../../../../../../$PlatformFile"
# Inherit a new definition file with platform defined
NewDefintionFile="$CuraShare/definitions/${NewDefinitionName}.def.json"
cat <<EOF >$NewDefintionFile
{
"name": "$NewPrinterModelName",
"version": 2,
"inherits": "$OldPrinterDefinition",
"metadata": {
"visible": true,
"platform": "$RelativePathToPlatform"
},
"overrides": {
"machine_name": { "default_value": "$NewPrinterModelName" }
}
}
EOF
The definition inherits from the old printer model, so all the (printer) settings will remain.
Only one thing left: Launch Cura and print some stuff!
I’m happy with the result and sure hope to be less confused about build plate orientation in the future 🙂
The full script is available at https://gist.github.com/lalten/f96dbe2fe5141490c39c871fd9e06ff6