Python-Script examples, creating meshes?

Hi…,

I am a part time scripter. :wink:

I want to write a script, which generates an array(e.g.10x10x10) of meshboxes cut by a sphere. The boxes should be approximated and not have more than 6 faces.

Where to find some Python-scripts to start creating mesh boxes (optimal plus defining normals).

Thank you for your time

Michael
www.flexiCAD.com

P.S.: I’ve cross-read the Python 101, but haven’t found ready script examples for meshes.

Hi @Michael_Meyer,

below is a simple script which makes the array of mesh boxes, each having 6 faces.

ArrayMeshBox.py (1.4 KB)

I’m not sure about the “cut by a sphere” part, maybe you can show an example.

_
c.

Hi clement,

wow, thank you very much for the script. This helps me a lot.

In the end I try to voxelize a sphere:

Thanks again

Michael

Hi Michael,

i’ve just created the array of mesh boxes as before and created a sphere from their bounding union. Then below script adds those mesh boxes to the document where the mesh box center is inside the sphere. You may check each mesh box vertex for containment for more accuracy if required:

ArrayMeshBox2.py (2.3 KB)

If you need this to work in the opposite way, eg. first selecting a sphere of a certain size then create the 10x10x10 mesh boxes inside, let me know.

_
c.

1 Like

Hi clement,

this is perfect.

Thanks you so much, have a nice weekend

Michael

1 Like