Last active
April 3, 2024 08:11
-
-
Save madhead/9dfc017bd03f3ed585ed4df8ccd925ee to your computer and use it in GitHub Desktop.
FreeCAD × Cura × Flatpak integration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This macro requires some overrides (
flatpak.sh
) to be able to start processes and access host/tmp
directory.