Skip to content

Instantly share code, notes, and snippets.

@lalten
Created Jan 29, 2022
Embed
What would you like to do?
Modify Cura printer settings to use a custom platform mesh.
#!/bin/bash
set -eux
## Setup
# Modification settings
OldPrinterModelName="Creality CR-6 SE"
NewPrinterModelName="MyPrinter"
# Cura paths
CuraVersion="4.13"
CuraShare="$HOME/.local/share/cura/$CuraVersion"
CuraConfig="$HOME/.config/cura/$CuraVersion"
CuraCache="$HOME/.cache/cura/$CuraVersion"
MeshesDir="$CuraShare/meshes"
# Restore backup
BackupToRestore="/home/laurenz/.cache/cura/4.13/backup.2022-01-29_17-11-54.tar.gz"
rm -rf "$CuraShare" "$CuraConfig"
tar -xaf "$BackupToRestore" -P
# Place platform mesh
mkdir -p "$MeshesDir"
PlatformFile="$MeshesDir/whambam-pex-255-245.stl"
# Export and download the STL from
# https://cad.onshape.com/documents/fd5e235b97204b51e84c3735/w/34f754d7b86d55489cbe842c/e/100359ddd9f51e64f9e63609
cp "$HOME/Downloads/whambam-pex-255-245.stl" "$PlatformFile"
# Make backup
mkdir -p "$CuraCache"
DateString=$(date +%Y-%m-%d_%H-%M-%S)
tar -caf "$CuraCache/backup.$DateString.tar.gz" -P "$CuraShare" "$CuraConfig"
## Modify Cura
# 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"
# Meshes are only looked for in /tmp/.mount_Ultima******/usr/bin/resources/meshes
# (With the mount dir being created by the AppImage)
# The built-in resources path is the only one that is used, see
# https://github.com/Ultimaker/Uranium/blob/1eacb050882b7ad63dfd1e731ee35eafbd07c93d/UM/Scene/Platform.py#L58
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment