Part ShapeFromMesh: Difference between revisions

From FreeCAD Documentation
(Expanded the scripting section with a complete example)
(Marked this version for translation)
Line 19: Line 19:
}}
}}


==Introduction==
==Introduction== <!--T:14-->


<!--T:3-->
<!--T:3-->
The {{Button|[[Image:Part_ShapeFromMesh.svg|16px]] [[Part_ShapeFromMesh|Part ShapeFromMesh]]}} command creates a shape from a [[Mesh|mesh object]]. Mesh objects have limited editing capabilities in FreeCAD, converting them to [[Shape|shapes]] will allow their use with many more tools in FreeCAD.
The {{Button|[[Image:Part_ShapeFromMesh.svg|16px]] [[Part_ShapeFromMesh|Part ShapeFromMesh]]}} command creates a shape from a [[Mesh|mesh object]]. Mesh objects have limited editing capabilities in FreeCAD, converting them to [[Shape|shapes]] will allow their use with many more tools in FreeCAD.


==Usage==
==Usage== <!--T:15-->


<!--T:4-->
<!--T:4-->
Line 35: Line 35:
Analyzing and repairing of the mesh, if needed, should be done manually before launching {{Button|[[File:Part_ShapeFromMesh.svg|16px]] [[Part_ShapeFromMesh|ShapeFromMesh]]}}. Appropriate tools for this task are available in the [[File:Workbench_Mesh.svg|24px]] [[Mesh_Workbench|Mesh Workbench]].
Analyzing and repairing of the mesh, if needed, should be done manually before launching {{Button|[[File:Part_ShapeFromMesh.svg|16px]] [[Part_ShapeFromMesh|ShapeFromMesh]]}}. Appropriate tools for this task are available in the [[File:Workbench_Mesh.svg|24px]] [[Mesh_Workbench|Mesh Workbench]].


<!--T:16-->
After creation of a [[Shape|Shape]], it may be useful to use {{Button|[[Part_ConvertToSolid|Convert to solid]]}} (necessary for [[Part_Boolean|boolean operations]]) and {{Button|[[File:Part_RefineShape.svg|16px]] [[Part_RefineShape|Refine shape]]}}.
After creation of a [[Shape|Shape]], it may be useful to use {{Button|[[Part_ConvertToSolid|Convert to solid]]}} (necessary for [[Part_Boolean|boolean operations]]) and {{Button|[[File:Part_RefineShape.svg|16px]] [[Part_RefineShape|Refine shape]]}}.


== Links ==
== Links == <!--T:17-->


<!--T:18-->
* [https://www.youtube.com/watch?v=5lwENZeNiNg&feature=youtu.be Edit STL Files In FreeCAD] video by AllVisuals4U.
* [https://www.youtube.com/watch?v=5lwENZeNiNg&feature=youtu.be Edit STL Files In FreeCAD] video by AllVisuals4U.


==Scripting== <!--T:13-->
==Scripting== <!--T:13-->


<!--T:19-->
Creating a [[Shape|Shape]] from a [[Mesh|Mesh]] can be done by using the {{incode|makeShapeFromMesh}} method from a [[Part_TopoShape|Part TopoShape]]; you need to specify the source mesh and tolerance, and assign the result to a new [[Part_Feature|Part Feature]] object.
Creating a [[Shape|Shape]] from a [[Mesh|Mesh]] can be done by using the {{incode|makeShapeFromMesh}} method from a [[Part_TopoShape|Part TopoShape]]; you need to specify the source mesh and tolerance, and assign the result to a new [[Part_Feature|Part Feature]] object.


<!--T:20-->
Notice that the mesh must be recalculated before it is converted to a Shape, otherwise there won't be topology information, and the conversion won't be successful.
Notice that the mesh must be recalculated before it is converted to a Shape, otherwise there won't be topology information, and the conversion won't be successful.



Revision as of 21:05, 18 September 2020

Part ShapeFromMesh‏‎

Menu location
Part → Create shape from mesh...
Workbenches
Part
Default shortcut
None
Introduced in version
-
See also
ConvertToSolid, RefineShape, PointsFromMesh

Introduction

The Part ShapeFromMesh command creates a shape from a mesh object. Mesh objects have limited editing capabilities in FreeCAD, converting them to shapes will allow their use with many more tools in FreeCAD.

Usage

  1. Select the mesh object in the tree view.
  2. Go to the menu, Part → Create shape from mesh.
  3. A popup-menu will ask for the tolerance for sewing shape; the default value is 0.1.
  4. A shape from the mesh object is created as a separate new object.

Analyzing and repairing of the mesh, if needed, should be done manually before launching ShapeFromMesh. Appropriate tools for this task are available in the Mesh Workbench.

After creation of a Shape, it may be useful to use Convert to solid (necessary for boolean operations) and Refine shape.

Links

Scripting

Creating a Shape from a Mesh can be done by using the makeShapeFromMesh method from a Part TopoShape; you need to specify the source mesh and tolerance, and assign the result to a new Part Feature object.

Notice that the mesh must be recalculated before it is converted to a Shape, otherwise there won't be topology information, and the conversion won't be successful.

import FreeCAD as App
import Part

doc = App.newDocument()
mesh = doc.addObject("Mesh::Cube", "Mesh")
mesh.recompute()

solid = doc.addObject("Part::Feature", "Shape")
shape = Part.Shape()
shape.makeShapeFromMesh(mesh.Mesh.Topology, 0.1)

solid.Shape = shape
solid.Placement.Base = App.Vector(15, 0, 0)
solid.purgeTouched()
doc.recompute()