Python Forum
What's the meaning of dtype=mesh.Mesh.dtype?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What's the meaning of dtype=mesh.Mesh.dtype?
#1
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
Reply
#2
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)
Reply
#3
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Unable to understand the meaning of the line of code. jahuja73 0 360 Jan-23-2024, 05:09 AM
Last Post: jahuja73
Question Vertex(Contour) to mesh conversion JorgeRdz 1 767 Feb-06-2023, 02:00 AM
Last Post: Larz60+
  Csv writer meaning of quoting mg24 2 1,212 Oct-01-2022, 02:16 PM
Last Post: Gribouillis
  meaning of -> syntax in function definition DrakeSoft 5 2,052 Apr-09-2022, 07:45 AM
Last Post: DrakeSoft
  Operator meaning explanation Sherine 3 2,096 Jul-31-2021, 11:05 AM
Last Post: Sherine
  Extracting data without showing dtype, name etc. tgottsc1 3 4,594 Jan-10-2021, 02:15 PM
Last Post: buran
  parser.parse_args() meaning vinci 2 2,674 Oct-26-2020, 04:13 PM
Last Post: vinci
  Dtype STR but output in Shell still int? johnjfk 6 2,344 Oct-04-2020, 01:34 PM
Last Post: johnjfk
  How to resolve numpy ValueError: dtype.descr Py_veeran 0 1,887 Aug-18-2020, 06:46 PM
Last Post: Py_veeran
  What is the meaning of k in this function? giladal 3 2,791 Aug-15-2020, 12:32 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020