Skip to content

Instantly share code, notes, and snippets.

@rondreas
Created March 3, 2020 13:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rondreas/a40dfc7d5edc75b7faa5488a2093315f to your computer and use it in GitHub Desktop.
Save rondreas/a40dfc7d5edc75b7faa5488a2093315f to your computer and use it in GitHub Desktop.
Script to create a mesh cube using Modo TD SDK
# python
# -*- coding: utf-8 -*-
import modo
def create():
""" Modo TD SDK example of creating a cube item,
Not recommended but one can run this as a fire-and-forget like..
@cube.py
in modo command prompt.
Or one can import it and run like..
>>> import cube
>>> cube.create()
ASCII Figure, Cube vertex positions and coordinate
directions.
+Y
-X
4 -Z
5. ´|`~.
|`~. | `6
| `7|´ ´|
| .~|0 |
1´ | `~. |
`~. | .`2
+Z `3´
+X
-Y
"""
mesh = modo.Scene().addItem('mesh', name="Cube")
vertices = [ # List of vertex positions for a cube,
(-0.5, -0.5, -0.5), # 0 <- indices,
(-0.5, -0.5, 0.5), # 1
( 0.5, -0.5, -0.5), # 2
( 0.5, -0.5, 0.5), # 3
(-0.5, 0.5, -0.5), # 4
(-0.5, 0.5, 0.5), # 5
( 0.5, 0.5, -0.5), # 6
( 0.5, 0.5, 0.5), # 7
]
polygons = [ # Polygons takes a list of vert indices,
(0, 2, 3, 1), # -Y
(4, 5, 7, 6), # +Y
(2, 6, 7, 3), # +X
(0, 1, 5, 4), # -X
(1, 3, 7, 5), # +Z
(0, 4, 6, 2) # -Z
] # index order is important to make the polygon face
# the right direction.
# enter the context so it's safe to edit meshes,
with mesh.geometry as geo:
for vertex in vertices:
geo.vertices.new(vertex)
for polygon in polygons:
geo.polygons.new(polygon)
return mesh
if __name__ == '__main__':
create()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment