Mesh Scripting: Difference between revisions

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



== Gui related stuff ==
== Gui related stuff ==

Revision as of 14:46, 26 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 an file

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

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

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 an 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 Algorithems

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.