Not a script, but with this possibility, I am over 95% successful.neo2001 wrote: ↑Sat Nov 16, 2019 11:45 amI know Python and looking at the Python console in FreeCAD helps a lot to understand what's going on in the background.
Still, before trying this I wanted to ask how I should approach this and where to start:
Creating and exporting a mesh to STL format is something I do very often and it's always the same procedure:
1 - Select object(s) in the Combo View/Tree
2 - Go to the "Mesh Design" Workbench
3 - Select "Meshes" --> "Create Mesh from Shape..."
4 - Select "Standard" (Mesh Engine)
6 - Set 0.01 for Surface deviation
7 - Set 5° for angular deviation
8 - Press "OK"
9 - Right klick on the Mesh created and select "Export mesh..."
10 - Select always the same destination directory
11 - Select STL file type
12 - Replace the filename with the name of the current FreeCAD document
13 - Save the STL file
14 - Hide everything besides the created mesh to review it
14 - Delete the mesh
15 - Switch back to the "Part Design" workbench
How would I start you do all this in a script? Or does creating a macro make more sense?
Code: Select all
# -*- coding: utf-8 -*- import FreeCAD import PartDesignGui import Mesh import MeshPartGui, FreeCADGui import MeshPart Gui.activateWorkbench("MeshWorkbench") FreeCADGui.runCommand('MeshPart_Mesher') # Opens dialog in sidebar (really needed?) __doc__ = FreeCAD.activeDocument() # Get active document __mesh__ = __doc__.addObject("Mesh::Feature", "Mesh") # Add (empty?) mesh object __part__ = __doc__.getObject("Pad001") # This somehow(TM) needs to return the object including all features (without knowing the names) __shape__ = __part__.Shape.copy(False) # Not sure what's going on here, yet... __shape__.Placement = __part__.getGlobalPlacement() # Get placement for putting the mesh exactly where the source geometry exists. # Convert to mesh # AngularDeflection's unit is Radians! Maybe use Math package to convert degrees... __mesh__.Mesh=MeshPart.meshFromShape(Shape=__shape__, LinearDeflection=0.01, AngularDeflection=0.0872665, Relative=False) __mesh__.Label="__doc__." # Somehow(TM) get the filename of the active document and name the mesh or set the name while exporting the STL file (where?) __mesh__.ViewObject.CreaseAngle=25.0 del __doc__, __mesh__, __part__, __shape__ # Cleaning up stuff Gui.getDocument("F450_gpsHolder_cup").getObject("Pad001").Visibility=Hide # Hide the other objects to show only the mesh, needs to work without hard coded names
Part-o-magic Exporter? https://forum.freecadweb.org/viewtopic. ... 50#p164011Bayesian wrote: ↑Wed Nov 20, 2019 10:14 amI tend to put these thing into Jupyter Notebook Cells, and just run the export commands from there. Also works with multiple models or multiple variants of the same model with different parameters.
I'm working on a different solution, based on FeaturePython objects in the tree. An STL export would then be an object, the parameters (which object, filename etc) would be represented by properties and the attachment would be used for modifying the placement. That way the export information can be saved to the FreeCAD file.