Skip to content, Skip to search


TrakEM2 Scripting

1,571 bytes added, 03:19, 6 April 2011
Set the radius of all balls of all Ball objects in a project
ballOb.repaint(True, None)
= Generate 3D meshes =
=== Generate a 3D mesh for an AreaList ===
This script illustrates how to bypass the 3D Viewer to generate meshes from an AreaList and then export the data in Wavefront format. The script exports an AreaList that has been selected in the front Display.
To export all selected objects, loop through the <i>Display.getSelected()</i>.
To export all arealists, loop through <i>Display.getFront().getLayerSet().getZDisplayables(AreaList)</i>.
<source lang="python">
from ini.trakem2.display import Display
from javax.vecmath import Color3f
from customnode import WavefrontExporter, CustomTriangleMesh
from import StringWriter
from ij.text import TextWindow
# Get the selected AreaList
arealist = Display.getSelected()[0]
# Create the triangle mesh with resample of 1 (no resampling)
# CAUTION: may take a long time. Try first with a resampling of at least 10.
resample = 1
triangles = arealist.generateTriangles(1, resample)
# Prepare a 3D Viewer object to provide interpretation
color = Color3f(1.0, 1.0, 0.0)
transparency = 0.0
mesh = CustomTriangleMesh(triangles, color, transparency)
# Write the mesh as Wavefront
name = "arealist-" + str(
m = {name : mesh}
meshData = StringWriter()
materialData = StringWriter()
materialFileName = name + ".mtl", materialFileName, meshData, materialData)
# Show the text of the files in a window
# then you save it with "File - Save"
TextWindow(".obj", meshData.toString(), 400, 400)
TextWindow(materialFileName, materialData.toString(), 400, 400)
Emailconfirmed, uploaders