Skip to content

Instantly share code, notes, and snippets.

@madhead
Last active April 3, 2024 08:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save madhead/9dfc017bd03f3ed585ed4df8ccd925ee to your computer and use it in GitHub Desktop.
Save madhead/9dfc017bd03f3ed585ed4df8ccd925ee to your computer and use it in GitHub Desktop.
FreeCAD × Cura × Flatpak integration
# -*- coding: utf-8 -*-
import FreeCAD
import Mesh
import MeshPartGui, FreeCADGui
import MeshPart
import Mesh, Part, PartGui
import uuid
import subprocess
selection = FreeCADGui.Selection.getSelection()
files = []
for selected in selection:
document = selected.Document
shape = selected.Shape
id = str(uuid.uuid4())
mesh = selected.Document.addObject('Mesh::Feature', f'Mesh_{id}')
mesh.Mesh = MeshPart.meshFromShape(Shape = shape, LinearDeflection = 0.1, AngularDeflection = 0.0523599, Relative = False)
mesh.Label = selected.Label
file = f'/tmp/{mesh.Label}_{id}.stl'
print(f'Exporting {selected.Label} to {file}')
Mesh.export([mesh], file)
files.append(file)
document.removeObject(mesh.Name)
subprocess.Popen(['flatpak-spawn', '--host', 'flatpak', 'run', 'com.ultimaker.cura', *files])
sudo flatpak override com.ultimaker.cura --filesystem=/tmp
sudo flatpak override org.freecadweb.FreeCAD --filesystem=/tmp
sudo flatpak override org.freecadweb.FreeCAD --talk-name=org.freedesktop.Flatpak
# -*- coding: utf-8 -*-
import FreeCAD
import Mesh
import MeshPartGui, FreeCADGui
import MeshPart
import Mesh, Part, PartGui
import uuid
import os
selection = FreeCADGui.Selection.getSelection()
for selected in selection:
document = selected.Document
shape = selected.Shape
id = str(uuid.uuid4())
mesh = selected.Document.addObject('Mesh::Feature', f'Mesh_{id}')
mesh.Mesh = MeshPart.meshFromShape(Shape = shape, LinearDeflection = 0.1, AngularDeflection = 0.0523599, Relative = False)
mesh.Label = selected.Label
file = os.path.join(os.path.dirname(document.FileName), f'{mesh.Label}_{id}.stl')
print(f'Exporting {selected.Label} to {file}')
Mesh.export([mesh], file)
document.removeObject(mesh.Name)
@madhead
Copy link
Author

madhead commented Mar 18, 2024

This macro requires some overrides (flatpak.sh) to be able to start processes and access host /tmp directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment