Python Forum

Full Version: What's the meaning of dtype=mesh.Mesh.dtype?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi there,

I'm trying to create STL files using python code and found the following sample:

from stl import mesh
import math
import numpy

# Create 3 faces of a cube
data = numpy.zeros(6, dtype=mesh.Mesh.dtype)

# Top of the cube
data['vectors'][0] = numpy.array([[0, 1, 1],
                                  [1, 0, 1],
                                  [0, 0, 1]])
data['vectors'][1] = numpy.array([[1, 0, 1],
                                  [0, 1, 1],
                                  [1, 1, 1]])
# Right face
data['vectors'][2] = numpy.array([[1, 0, 0],
                                  [1, 0, 1],
                                  [1, 1, 0]])
data['vectors'][3] = numpy.array([[1, 1, 1],
                                  [1, 0, 1],
                                  [1, 1, 0]])
# Left face
data['vectors'][4] = numpy.array([[0, 0, 0],
                                  [1, 0, 0],
                                  [1, 0, 1]])
data['vectors'][5] = numpy.array([[0, 0, 0],
                                  [0, 0, 1],
                                  [1, 0, 1]])
Now I'm wondering what's the exact meaning of dtype=mesh.Mesh.dtype. Looks like it assigns a data type to the list, however, I don't understand its structure. What's the meaning of the fist 'mesh', what's the meaning of the second 'Mesh' and what's the meaning of the 'dtype' in the expression. Could anybody given an explanation, please? I didn't find useful documentation for a beginners level.

Best regards
stl is a package
mesh is a sub-package of stl.
mesh.Mesh is probably a class. You can find out by asking Python. I'm not going to install stl just for this, so I'll use tkinter.ttk as an example.
Output:
>python Python 3.10.7 (tags/v3.10.7:6cc6b13, Sep 5 2022, 14:08:36) [MSC v.1933 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from tkinter import ttk >>> ttk <module 'tkinter.ttk' from 'C:\\Program Files\\Python310\\lib\\tkinter\\ttk.py'> >>> ttk.Checkbutton <class 'tkinter.ttk.Checkbutton'>
for stl.mess, start up the python interpreter and mport mesh from stl and ask python wht "mesh" is.
Output:
>>> from stl import mesh >>>mesh
You could even ask for help.
>>>help(mesh)
Do the same thing to learn more about Mesh.
Output:
>>>mesh.Mesh ... help(mesh.Mesh)
Thanks, that helped already. Meanwhile, I noticed that I am actually able to create some STL files without understanding the full details of the data structure.