Mesh Scripting: Difference between revisions

From FreeCAD Documentation
Line 14: Line 14:
mesh = Mesh.mesh()
mesh = Mesh.mesh()


You can also create an object from an file
You can also create an object from a file


mesh = Mesh.mesh('D:/temp/Something.stl')
mesh = Mesh.mesh('D:/temp/Something.stl')


What file formats you can use to build up a mesh is noted [[Feature_list#IO|hier]].
What file formats you can use to build up a mesh is noted [[Feature_list#IO|here]].


Or create it out of a set of triangles described by their corner points:
Or create it out of a set of triangles described by their corner points:
Line 30: Line 30:
planarMeshObject = Mesh.mesh(planarMesh)
planarMeshObject = Mesh.mesh(planarMesh)


The Mesh-Kernel takes care about creating an topological correct data structure by sorting
The Mesh-Kernel takes care about creating a topological correct data structure by sorting
coincident points and edges together.
coincident points and edges together.



Revision as of 11:03, 27 September 2007

Introduction

First of all you have to import the Mesh module:

import Mesh

After that you have access to the Mesh module and the Mesh class which facilitate the functions of the FreeCAD C++ Mesh-Kernel.

Creation and Loading

To create an empty mesh object just use the standard constructor:

mesh = Mesh.mesh()

You can also create an object from a file

mesh = Mesh.mesh('D:/temp/Something.stl')

What file formats you can use to build up a mesh is noted here.

Or create it out of a set of triangles described by their corner points:

planarMesh = [
# triangle 1
[-0.5000,-0.5000,0.0000],[0.5000,0.5000,0.0000],[-0.5000,0.5000,0.0000],
#triangle 2
[-0.5000,-0.5000,0.0000],[0.5000,-0.5000,0.0000],[0.5000,0.5000,0.0000],
]
planarMeshObject = Mesh.mesh(planarMesh)

The Mesh-Kernel takes care about creating a topological correct data structure by sorting coincident points and edges together.

Later on you will see how you can test and examine mesh data.

Modeling

Examining and Testing

Write your own Algorithms

Exporting

You can even write the mesh to a python module:

m.write("D:/Develop/Projekte/FreeCAD/FreeCAD_0.7/Mod/Mesh/SavedMesh.py")
import SavedMesh
m2 = Mesh.mesh(SavedMesh.faces)

Gui related stuff

Odds and Ends

An extensive, ought hard to use, source of Mesh related scripting are the unit test scripts of the Mesh-Module. In this unit tests literally all methods are called and all properties/attributes are tweaked. So if you bold enought, take a look at the Unit Test module.