Difference between revisions of "TrakEM2 Scripting"

(Starting ...)
 
Line 17: Line 17:
 
>>> print imp.width, imp.height
 
>>> print imp.width, imp.height
 
2048 2048
 
2048 2048
 +
</source>
 +
 +
 +
=== Access the Layer and Selection of a Display ===
 +
 +
<source lang="python">
 +
>>> front = Display.getFront()
 +
>>> layer = front.getLayer()
 +
>>> layer_set = front.getLayerSet()
 +
>>> sel = front.getSelection()
 +
>>> print sel.getSelected().size()
 +
10
 +
>>> print sel.isEmpty()
 +
0
 +
</source>
 +
 +
In Jython, 1 is True and 0 is False
 +
 +
=== Lock all selected objects ===
 +
<source lang="python">
 +
for d in Display.getFront().getSelected():
 +
  d.setLocked(True)
 
</source>
 
</source>

Revision as of 21:40, 28 October 2009

Examples in Jython

Get the instance of a selected image

>>> p = Display.getFront().getActive()
>>> print p
090504_0314_ex0768.mrc z=0.0 #67398


Obtain the ImagePlus of a selected image

>>> p = Display.getFront().getActive()
>>> imp = p.getImagePlus()
>>> print imp.width, imp.height
2048 2048


Access the Layer and Selection of a Display

>>> front = Display.getFront()
>>> layer = front.getLayer()
>>> layer_set = front.getLayerSet()
>>> sel = front.getSelection()
>>> print sel.getSelected().size()
10
>>> print sel.isEmpty()
0

In Jython, 1 is True and 0 is False

Lock all selected objects

for d in Display.getFront().getSelected():
  d.setLocked(True)