calculate table columns

In this subforum specific Topics concerning ZEN Core, e.g workbenches, are discussed
Post Reply
Julien Toquant
Posts: 23
Joined: Fri May 29, 2020 1:54 pm

calculate table columns

Post by Julien Toquant »

Hi,

I would like to use table calculations in ZEN Core OAD (I didn't find any example in the forum on this topic).

First with columns:

[Column1 (table1) / Column1 (table2)] * 100

And with lines:

Sum or average of all lines of a table into a new table.

Thanks for your help.
CarlZeissMicroscopy3
Posts: 180
Joined: Wed May 20, 2020 10:10 am

Re: calculate table columns

Post by CarlZeissMicroscopy3 »

Hello Julien Toquant,

I would like to show some general approaches concerning tables.

In OAD you can use ZenTables, that are used within Zen, and you can use DataTables.

DataTables are one of the main approaches to work with data in .Net and ZenTables are based on DataTables.
Please have a look at DataTable and e.g. Calculate in the internet to get more information.

I hope that the following simple example is a solid basis to proceed.

Code: Select all

table = ZenTable()

table.Columns.Add("First", str)
table.Columns.Add("Second", int)
table.Columns.Add("Third", int)

table.Rows.Add('Test1', 1, 11)
table.Rows.Add('Test2', 2, 22)

print(table.Rows[0][0])
print(table.Rows[1][0])

dataTable = table.ToDataTable()
sum = dataTable.Compute("Sum(Second)", "")
print(sum)
Julien Toquant
Posts: 23
Joined: Fri May 29, 2020 1:54 pm

Re: calculate table columns

Post by Julien Toquant »

Thanks. That's a good start.
Could you also give me a code for dividing and multiplying values of two columns please?
BR
Julien
CarlZeissMicroscopy3
Posts: 180
Joined: Wed May 20, 2020 10:10 am

Re: calculate table columns

Post by CarlZeissMicroscopy3 »

Hello Julien Toquant,

I'm not sure, but do you mean something like

Code: Select all

table = ZenTable()

table.Columns.Add("First", str)
table.Columns.Add("Second", int)
table.Columns.Add("Third", int)
table.Columns.Add("Forth", int)

table.Rows.Add('Test1', 1, 11)
table.Rows.Add('Test2', 2, 22)

for row in table.Rows:
    row[3] = row[1] * row[2]
    print(row[3])
Julien Toquant
Posts: 23
Joined: Fri May 29, 2020 1:54 pm

Re: calculate table columns

Post by Julien Toquant »

Yes. that's what I meant.
Thanks a bunch.
Julien Toquant
Posts: 23
Joined: Fri May 29, 2020 1:54 pm

Re: calculate table columns

Post by Julien Toquant »

Another question: how do I get the output tables from image analysis used in a job ?
thanks.
CarlZeissMicroscopy3
Posts: 180
Joined: Wed May 20, 2020 10:10 am

Re: calculate table columns

Post by CarlZeissMicroscopy3 »

Hello Julien Toquant,

this is an example where you add a macro workbench after an analysis step in a job.

The idea is to catch the image and then extract the tables from the image, like:

Code: Select all

image = Zen.Application.ActiveWorkbench.GetDefaultInputValue()

RegionsTable = Zen.Analyzing.CreateRegionsTable(image)
Klasse1Table = Zen.Analyzing.CreateRegionTable(image, "Klasse1")

etc.
I hope this code snippet helps to demonstrate the idea in principle.
Julien Toquant
Posts: 23
Joined: Fri May 29, 2020 1:54 pm

Re: calculate table columns

Post by Julien Toquant »

Prefect.
Thanks!
Post Reply