Extract String values from result table with Python gives NAN

Dear List,
I’m writing a python script to import points in TrakEM2 as balls.
I’m starting with point names and coordinates listed in a result table.
I can obtain int or float numbers but the name column return NAN.
In ImageJ macro language the getResultString should be used, is it the same in jython?
I’ve looked through examples and forums but I could not find any hints…

from ij.measure import ResultsTable
from ij import IJ

rt = ResultsTable.getResultsTable()
xA = rt.getColumn(rt.getColumnIndex('X'))
yA = rt.getColumn(rt.getColumnIndex('Y'))
zA = rt.getColumn(rt.getColumnIndex('Z'))
Label = rt.getColumn(rt.getColumnIndex('Name'))

for name,x,y,z in zip(Label,xA,yA,zA):
	print(name,x,y,z)

thank you for your help

Federico

Hello Federico -

Try replacing

Label = rt.getColumn(rt.getColumnIndex('Name'))

with

Label = rt.getColumnAsVariables ('Name')

(See ResultsTable.getColumnAsVariables().)

Label will now be an array of ij.macro.Variable, and these
apparently know how to turn themselves into strings (when they
are strings) when you print them.

Just for fun, you could also use

zA= rt.getColumnAsVariables ('Z')

and these Variables will turn themselves into numbers (or at
least string representations of numbers) when you print them.

Thanks, mm

1 Like

Dear Mountain man
A mountain of thanks, It worked perfectly!!
Thank you also for the link, I will learn how to use those pages…
ciao

Federico