Macro 3D Printer 3mf Workflow/fr

Macro_3D_Printer_3mf_Workflow

Description
Macro de FreeCAD permettant d'exporter des fichiers 3MF lisses et de conserver tous les paramètres d'impression du slicer, avec un flux de travail automatique vers votre slicer préféré.

Version macro : 00.07
Date dernière modification : 2026/11/26
Version FreeCAD : Toutes
Téléchargement : Icône de la barre d'outils

Macro 3D_Printer_3mf_Workflow 3D_Printer_3mf_Workflow_ConfigIni.FCMacro
Auteur: 2cv001

Auteur
2cv001
Téléchargement
Icône de la barre d'outils

Macro 3D_Printer_3mf_Workflow 3D_Printer_3mf_Workflow_ConfigIni.FCMacro

Liens
Version Macro
00.07
Dernière modification
2026/11/26
Version(s) FreeCAD
Toutes
Raccourci clavier
None
Voir aussi
None

Description

Temporary code for external macro link. Do not use this code. This code is used exclusively by Addon Manager. Link for optional manual installation: Macro


# This code is copied instead of the original macro code
# to guide the user to the online download page.
# Use it if the code of the macro is larger than 64 KB and cannot be included in the wiki
# or if the RAW code URL is somewhere else in the wiki.

from PySide import QtGui, QtCore

diag = QtGui.QMessageBox(QtGui.QMessageBox.Information,
    "Information",
    "This macro must be downloaded from this link\n"
    "\n"
    "https://raw.githubusercontent.com/2cv001/3D_printer_3mf_workflow/refs/heads/main/3D_Printer_3mf_Workflow.FCMacro" + "\n"
    "\n"
    "Quit this window to access the download page")

diag.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
diag.setWindowModality(QtCore.Qt.ApplicationModal)
diag.exec_()

import webbrowser 
webbrowser.open("https://raw.githubusercontent.com/2cv001/3D_printer_3mf_workflow/refs/heads/main/3D_Printer_3mf_Workflow.FCMacro")

Macro de FreeCAD permettant d'exporter des fichiers 3MF lisses et de conserver tous les paramètres d'impression du slicer, avec un flux de travail automatique vers votre slicer préféré.

Description plus détaillée :

https://github.com/2cv001/3D_printer_3mf_workflow/blob/main/README.md

Objectif

Cette macro automatise et améliore le flux de travail d'impression 3D depuis FreeCAD vers votre slicer en :

En quelques mots

Principe du lissage

Avec des facettes visibles

Sans les facettes visibles

La macro exporte les objets sélectionnés vers un fichier 3MF en utilisant les paramètres de tessellation spécifiés (LinearDeflection et AngularDeflection). Les maillages sont calculés en mémoire, toujours sous le contrôle de ces deux paramètres : rien n'est ajouté au document FreeCAD.

Présentation du flux de travail

Premier lancement

Lancements suivants

Utilisation

Installez la macro à l'aide du Gestionnaire des extensions de FreeCAD, puis sélectionnez les objets à imprimer dans l'arborescence.

Lancez la macro depuis FreeCAD. Le chemin d'accès au logiciel de découpage est défini directement dans la boîte de dialogue principale de la macro, à l'aide du champ de saisie prévu à cet effet.

Lors du premier lancement, configurez vos paramètres d'impression dans le logiciel de découpage et enregistrez le fichier .3mf (en général, sauf dans Cura, il suffit d'appuyer sur Ctrl+S ou de cliquer sur « Save » dans le menu).

Lors de vos prochains démarrages, profitez de la réutilisation automatique de vos paramètres.

Macro_3D_Printer_3mf_workflow capture écrant

Lancement d'autres programmes ou commandes

La macro peut exécuter automatiquement vos propres commandes, avant ou après l’exportation. Cette fonctionnalité est facultative et peut être utilisée pour automatiser des étapes supplémentaires de votre flux de travail, telles que :

La fenêtre des options répertorie vos commandes, chacune accompagnée d'une case à cocher : cochez celles que vous souhaitez exécuter cette fois-ci. Les commandes exécutées avant l'exportation sont signalées par la mention « (before the export) ».

Configuration (facultatif : commandes supplémentaires)

Une macro d'aide dédiée est fournie pour faciliter la configuration. Vos commandes sont stockées dans un fichier .ini utilisé par le flux de travail.

Le bouton ⚙️ dans la fenêtre d'options vous permet à la fois d'installer et d'ouvrir la macro de configuration (3D_Printer_3mf_Workflow_ConfigIni.FCMacro). La liste des commandes affichée dans la fenêtre des options est mise à jour dès que vous la fermez.

Fenêtre de configuration : la commande sélectionnée contient une erreur (C:/… au lieu de C:\…), le programme vous le signale avant que vous ne l'exécutiez.

Chaque ligne du tableau correspond à une commande :

Colonne Signification
Command Le programme et ses paramètres
Label Le nom affiché dans la fenêtre des options
Delay (s) Temps d'attente avant l'exécution de la commande
Enabled by default Case cochée dans la fenêtre des options au démarrage de la macro
Before the export Exécute la commande avant l'exportation plutôt qu'après

Passez la souris sur le titre d'une colonne pour afficher les infobulles d'aide.

Écrire une commande

Les règles à connaître :

Before or after the export

  • After the export (default): the commands run in order once the 3MF is written and the slicer launched, before the end message. FreeCAD is not blocked while a delay runs.
  • Before the export checked: the command runs as soon as the options are validated, before the meshing. Typical use: turn on the printer and start preheating while FreeCAD exports. The macro waits for each delay (countdown in the status bar) and the export only starts after the last "before" command. The 3MF is not written yet at that time: do not use %EXPORT% in these commands.

Example: a "before" command turns on the Shelly plug, a second "before" command with a 10 s delay sends the preheating to Klipper once the printer has started, then the export begins.

The "before" commands are stored separately in the .ini file (EXTRA_COMMANDS_BEFORE): an older version of the macro ignores them.

Utilisation de %PROJECT%, %PROJECTDIR%, %PROJECTNAME% %EXPORT% et %EXPORTNAME% dans les commandes utilisateur

Lorsque vous définissez des commandes de post-traitement personnalisées dans le flux de travail, vous pouvez utiliser trois espaces réservés spéciaux. Ces espaces réservés sont automatiquement remplacés par des valeurs dérivées de votre fichier de projet FreeCAD.

Emplacements disponibles

Emplacements et leur signification

  • %PROJECT% : chemin d'accès complet du projet FreeCAD sans extension
  • %PROJECTDIR% : dossier contenant le projet FreeCAD
  • %PROJECTNAME% : nom du fichier de projet sans extension
  • %EXPORT% : chemin d'accès complet de l'objet sélectionné à exporter, sans extension
  • %EXPORTNAME% : nom du fichier d'exportation, sans extension

To build a path in another folder, use the names: "C:\Backup\%EXPORTNAME%.3mf", not "C:\Backup\%EXPORT%.3mf".

Exemples

These examples are also available with Add from a template. Replace the parts between < > with your own values.

Copiez le fichier 3MF généré à côté du projet :

copy "%PROJECT%.3mf" "%PROJECTDIR%/backup/%PROJECTNAME%.3mf"

On Linux / macOS:

cp "%EXPORT%.3mf" "%PROJECTDIR%/backup/%EXPORTNAME%.3mf"

Lancez un script stocké dans le dossier du projet :

python "%PROJECTDIR%/scripts/postprocess.py" "%PROJECT%.3mf"

Open the project folder (Windows):

explorer "%PROJECTDIR%"

Envoyez une requête HTTP en utilisant le nom du projet :

Turning on the printer (to check "Before the export")

Allumez une prise intelligente Shelly Gen 1

Gen 1 with a password (restricted login):

curl --fail -u <USER>:<PASSWORD> "http://<PLUG_IP>/relay/0?turn=on"

Gen2

Ou si votre appareil est protégé par un mot de passe :

Through the Shelly cloud (server address and authorization key in the Shelly app: User settings → Authorization cloud key; device ID in the device settings):

curl --fail -X POST "https://<CLOUD_SERVER>/device/relay/control" -d "channel=0&turn=on&id=<DEVICE_ID>&auth_key=<API_KEY>"

Home Assistant (long-lived access token created in your Home Assistant profile):

curl --fail -X POST -H "Authorization: Bearer <TOKEN>" -H "Content-Type: application/json" -d "{\"entity_id\":\"switch.<PLUG_NAME>\"}" "http://<HOME_ASSISTANT_ADDRESS>:8123/api/services/switch/turn_on"

Jeedom (API key in Settings → System → Configuration → API; command ID shown in the advanced configuration of the command):

curl --fail "http://<JEEDOM_ADDRESS>/core/api/jeeApi.php?apikey=<API_KEY>&type=cmd&id=<COMMAND_ID>"

Preheat the bed of a Klipper printer to 60 °C (Moonraker):

curl --fail -X POST "http://<PRINTER_IP>:7125/printer/gcode/script?script=M140%20S60"

Keep your keys and passwords for yourself: they are stored in clear text in the .ini file.

Going further

Exporting several objects

Select one or more objects (Ctrl+click in the tree) and run the macro. All the selected objects go into a single 3MF, each one as a separate object in the slicer, with its own print settings.

The top right corner of the options window shows a small isometric image of the selected objects, with their colors (for a PartDesign Body, the color of its visible feature), so you can check what will be exported. It is drawn by the macro from a very coarse mesh, without OpenGL, in a few hundredths of a second; the document and the 3D view are not touched.

  • First export: the objects keep exactly their FreeCAD layout (X, Y and Z). The group is centered on the plate and the lowest object rests on it. If objects overlap, QIDISlicer / PrusaSlicer ask whether to load them as a single object having multiple parts: answer Yes to keep them assembled, No to get separate objects (then arrange them on the plate).
  • Next exports: each FreeCAD object is matched with the slicer object of the same name. Its geometry is replaced; its settings and its position and rotation on the plate are kept, and it is put back on the plate.
  • Objects that are no longer selected are removed from the 3MF; newly selected objects are added at their FreeCAD position.
  • Copies made on the plate in the slicer (duplicated objects or added instances) are kept as long as the object has not changed in FreeCAD. When it has changed, the macro asks: Keep the copies (each one gets the new geometry and keeps its place; if the part got bigger they may overlap, use "Arrange" in the slicer) or Remove the copies. With Do not recover slicer position/rotation checked, the copies are removed.
  • With a single selected object and a 3MF whose object has another name, the first object on the plate is replaced and renamed after the FreeCAD object, so 3MF files made by previous versions keep working.
  • With the STL option, all the selected objects go into one STL file.
  • Objects inside an App::Part are exported at their global position.

Choosing the base 3MF

The 3MF file for print parameters list chooses the 3MF whose print settings and objects are reused:

  • No base (new 3MF): a new 3MF containing only the geometry. If the 3MF of the selection already exists, it is kept as a .old backup.
  • This selection's 3MF: the usual choice, selected by default when it exists. When it does not exist yet, the most recent 3MF of the project folder that contains an object with the same name is selected instead (for example the 3MF of several objects, when you export one of them alone), so its settings are not lost.
  • The other 3MF files of the project folder, most recent first.
  • The last 8 bases used in other folders (remembered from one session to the next), shown with their folder and date, so that several "Body.3mf" from different projects can be told apart. Hover over a line to see its full path.
  • Browse… picks a 3MF anywhere, for example in another project.

Each 3MF of the list shows its thumbnail: the preview image saved in the file by the slicer (plate image for QIDIStudio / Bambu / Orca, thumbnail for Cura / SuperSlicer / FreeCAD). It is only read from the file, so it costs nothing; a 3MF without a preview image simply has no thumbnail.

Below the list, the macro shows the name the 3MF will be saved as and explains what the chosen base will do: for which objects the existing settings are kept, which objects are new (they get the general settings), and whether the base has no slicer settings at all. The text turns orange when object settings may not be reused (no object of the base has a selected name, or "No base" while the 3MF of the selection exists). The base file itself is never modified; if the 3MF of the selection already exists and another base is chosen, it is backed up first (.old file).

From the base, the macro always keeps the general settings: printer, filament (type, temperatures, cooling… and all the filaments of a multi-color printer) and print profile (layer height, speeds, walls, default infill and supports…). The settings of an object (its own infill, walls, layer height, supports, filament, modifiers…) are kept only for the objects matched by name. Objects of the base that match no selected object are removed; new objects get the general settings and the first filament.

Settings applied to faces and modifiers

Some print settings are attached to specific faces of an object: enforced or blocked supports, seams, colors (and other per-face data). They, as well as modifiers and extra parts, are tied to the old geometry and cannot be kept when it changes. If some would be lost, the macro tells you which objects are concerned and asks you to Continue or Cancel (the 3MF is then left unchanged).

Objects whose geometry has not changed in FreeCAD since the last export are left exactly as they are in the slicer: their settings applied to faces, modifiers, copies and position are all kept, and the warning only lists the objects that really changed. For example, with Housing_Lid.3mf, modifying only the Housing keeps the enforced supports of the Lid. (Changing the precision or the angular tolerance changes the mesh, so all objects are then replaced. With Do not recover slicer position/rotation checked, all objects are replaced and placed as in FreeCAD.)

Mesh fineness and export time

Very small values make the mesh huge, and FreeCAD is frozen while it is computed. Before meshing, the macro quickly estimates the number of triangles and the time needed (from a few coarse test meshes, in less than a second). If the mesh would take more than about 30 seconds or have more than a million triangles, it asks first: Continue or Back to options to choose coarser values.

The Mesh fineness panel of the options window holds the Precision (LinearDeflection, in mm) and the Angular tolerance (AngularDeflection, in degrees); their tooltips explain them. On the right, Export time shows the estimated time for the selected objects, with the number of triangles and the 3MF size below. It is computed when the window opens and updated live while you change the values; it turns orange above the warning limits.

Optimize fineness chooses the finest precision and angular tolerance whose estimated export fits in the Target export time (remembered between sessions), keeping the ratio between the two values. It never goes below 0.01 mm and 2°: below that, the printed part does not change (0.4 mm nozzle, 0.1 to 0.2 mm layers), only the file and the time grow. You can still type finer values yourself.

The time estimate adjusts itself to your computer: after each export, the real meshing time is compared with the estimate and a correction factor is kept in the .ini file.

Noms de fichiers d'exportation

Les exportations utilisent le nom affiché de l'objet sélectionné (son « Label » dans l'arborescence de FreeCAD), dans le même répertoire que le document FreeCAD enregistré. Par exemple, sélectionner « Housing » crée « Housing.3mf » et, si cette option est activée, « Housing.stl ». Sélectionner « Lid » crée « Lid.3mf » et « Lid.stl ». Chaque objet dispose de ses propres paramètres d'impression 3MF et de ses propres sauvegardes. Sélectionnez un objet et exécutez la macro, puis répétez l'opération pour l'objet suivant.

Pour un corps de PartDesign, la sélection d'une face ou d'une arête dans la vue 3D, ou d'une fonction telle qu'un « Pad » ou une « Pocket » dans l'arborescence, entraîne l'exportation de l'intégralité du corps sous son étiquette. La sélection de plusieurs fonctions d'un même corps est considérée comme un seul objet. Les objets situés en dehors d'un corps conservent leur propre étiquette et leur propre géométrie.

Les caractères incompatibles avec les noms de fichiers sont remplacés par des traits de soulignement. Les noms qui se chevauchent au sein d'un même document (même après normalisation ou ignorance de la casse) se voient ajouter le nom interne de l'objet en suffixe. Les suffixes temporaires ou de sauvegarde liés au flux de travail, ainsi que les noms de périphériques Windows, sont également modifiés afin d'éviter tout conflit. Utilisez des identifiants distincts et stables : le renommage d'un objet modifie le nom de son fichier d'exportation. Les objets provenant de documents différents mais situés dans le même dossier doivent également posséder des identifiants distincts.

Les exportations existantes portant le nom du projet ne sont pas renommées automatiquement. Pour réutiliser leurs paramètres d'impression, sélectionnez l'ancien fichier .3mf dans le champ « 3MF file for print parameters » lors de la première exportation d'une pièce. Enregistrez les modifications apportées par la suite dans le logiciel de découpage dans le nouveau fichier .3mf de cette pièce.

Cette fonction prend en charge l'exportation séparée d'objets 3D contenus dans un même document ; elle ne divise pas chacun des contours d'une esquisse ni les solides à l'intérieur d'un objet sélectionné.

Slicer path

The slicer path must be the slicer program itself (on Windows, its .exe file): a part file such as a .3mf or .stl is refused. On Windows, the Browse… button of the slicer line only lists programs, so that it is not confused with the Browse… button of the base 3MF.

Notes techniques

  • La géométrie est extraite du document FreeCAD actif.
  • Les fichiers .3mf sont utilisés à la place des fichiers .stl afin de conserver les métadonnées d'impression.
  • Les paramètres d'impression sont enregistrés dans le fichier .3mf, situé dans le même répertoire que le document FreeCAD.
  • Compatible avec la plupart des logiciels de découpage prenant en charge le format .3mf : testé avec QidiSlicer, QidiStudio, Cura, PrusaSlicer, OrcaSlicer, Bambu Studio, Anycubic, Creality.
  • Non compatible avec les logiciels de découpage qui ne génèrent pas de fichiers 3MF contenant les paramètres d'impression (par exemple, ideaMaker, FlashPrint). Pour les autres logiciels de découpage, n'hésitez pas à essayer — cela devrait fonctionner. Sinon, veuillez ouvrir un ticket sur GitHub.
  • La macro peut être configurée pour exécuter d'autres commandes, telles que la mise en marche de l'imprimante à l'aide d'une prise intelligente connectée.

History

Cette macro est la remplaçante de la macro 3d_printer_workflow.

La macro 3D_Printer_Workflow était déjà capable de produire des exportations fluides et sans facettes. Sa principale limitation était qu'elle reposait sur des fichiers STL, qui ne peuvent pas stocker les paramètres de découpage ou d'impression.

Cette macro utilise des fichiers .3mf, ce qui permet d'enregistrer et de réutiliser tous les paramètres d'impression.

Afin de conserver les fonctions essentielles de la macro précédente, cette version offre également une option d'exportation STL avec des paramètres de tessellation ajustables, permettant une génération fluide des maillages, comme auparavant.

Utilisation

Plus d'informations sur https://github.com/2cv001/3D_printer_3mf_workflow

Discussion

Anglais : https://forum.freecad.org/viewtopic.php?t=102503

Français : https://forum.freecad.org/viewtopic.php?t=103419

Script

Icône de la barre d'outils

Code

ver 00.07 2026/11/26 by 2cv001 3D_Printer_3mf_Workflow.FCMacro

Téléchargement