Processing on Datacollector
Hi There
I have this macro (with A LOT of help from Yuri), that generates data in the datacollector, The processed images are not visible - the same goes for the datacollector. That saves my a lot of time when running as a batch. After batch processing are have a small script that empties the datacollector into Excel for further calculations. It would nice to make the Excel VBA coding directly in ImagePro, again to save time and trouble.
I have been experimenting a little and this line in my macro:
I have this macro (with A LOT of help from Yuri), that generates data in the datacollector, The processed images are not visible - the same goes for the datacollector. That saves my a lot of time when running as a batch. After batch processing are have a small script that empties the datacollector into Excel for further calculations. It would nice to make the Excel VBA coding directly in ImagePro, again to save time and trouble.
I have been experimenting a little and this line in my macro:
Public Function FD_Measure(doc1 As Object) As SimpleScript FD_Measure = New SimpleScript - bla bla bla - bla bla bla - bla bla bla
Call DoSomething() End Function Then made this simple sub routine: Private Sub DoSomething() Debug.Print Now() End Sub It works!:-))) But here comes the question - In this DoSomething, how can I access the data in the datacollector. Loop through them, put them in arrays etc etc. I have all that code from Excel VBA. I need something like (in mumbo-jumbo language): For i 1 to Number_Of-lines_in-Datacolletor myParamx(i) = Parameter1_In_Collector(i) myParamy(i) = Parameter2_In_Collector(i) Next
Does it make any sence!? - Torben
0
Answers
-
Hi Torben,
The data in DataCollecter is saved as System.Data.DataSet (see https://msdn.microsoft.com/en-us/library/system.data.dataset(v=vs.110).aspx ).
Here is a sample macro that shows how to print one of the tables to Output window (you can use Debug.Print instead).Public Sub PrintDCdata 'get Data Collector doc (global) Dim dcDoc As MediaCy.Addins.DataCollector.McDataCollectorDocument=MediaCy.Addins.DataCollector.McDataCollectorAddin.ThisAddin.Document 'get data collector data as DataSet Dim ds As System.Data.DataSet=dcDoc.Data 'get the first table Dim dt As System.Data.DataTable=ds.Tables(0) Dim s As String="" ThisApplication.Output.Show 'print column names Dim col As System.Data.DataColumn For Each col In dt.Columns s+=col.Caption & vbTab Next ThisApplication.Output.PrintMessage(s)'can be used instead of Debug.Print 'print data For Each row As System.Data.DataRow In dt.Rows s="" For Each col In dt.Columns s+=row(col).ToString & vbTab Next ThisApplication.Output.PrintMessage(s) Next End Sub
The data from Output window can be sent to Excel using context menu.
Yuri0 -
That's also (a kind of magic). It gives data from the "Image" tab of the datacollectpor. The datacollector has as tab called "Measurements" how do I get the data from that?
-Torben0 -
The macro uses the first table Tables(0), if your Measurement table is second then you should change the macro to get Tables(1):
Dim dt As System.Data.DataTable=ds.Tables(1)
Yuri0 -
Thank you - Makes sence. But something fishy is still going on. I am trying to pickup data into arrays like this, why doesn't that work? I know it´s not really elegant, but the other parts of the VBA code expects arrays like this:
Public Sub PrintDCdata 'get Data Collector doc (global) Dim dcDoc As MediaCy.Addins.DataCollector.McDataCollectorDocument=MediaCy.Addins.DataCollector.McDataCollectorAddin.ThisAddin.Document Dim tmp(1000,5) As Double Dim r As Integer Dim c As Integer 'get data collector data as DataSet Dim ds As System.Data.DataSet=dcDoc.Data 'get the first table Dim dt As System.Data.DataTable=ds.Tables(1) Dim s As String="" ThisApplication.Output.Show 'print column names Dim col As System.Data.DataColumn For Each col In dt.Columns s+=col.Caption & vbTab Next r=0 c=0 ThisApplication.Output.PrintMessage(s)'can be used instead of Debug.Print 'print data For Each row As System.Data.DataRow In dt.Rows r+=1 s="" For Each col In dt.Columns c+=1 s+=row(col).ToString & vbTab tmp(r,c) = row(col) Next ThisApplication.Output.PrintMessage(s) Next 'Debug.Print r.ToString & vbTab & c.ToString End Sub
0 -
Hi Torben,
You have to reset column index in the beginning of every row. Add c=0 to row loop.
Yuri0 -
You are absolutely right. A strange thing happens when I do the batch (because it actually works now). It enter your function twice; I have put in a debug.print now to tell me about it. Whats the explanation and how to avoid that?Public Function FD_Measure(doc1 As Object) As SimpleScriptFD_Measure = New SimpleScriptDim image1Dim docList1 = New List(1), doc3, image2bla bla bla.....PrintDCdataEnd FunctionPublic Sub PrintDCdata'get Data Collector doc (global)Dim dcDoc As MediaCy.Addins.DataCollector.McDataCollectorDocument=MediaCy.Addins.DataCollector.McDataCollectorAddin.ThisAddin.DocumentDim tmp(1000,10) As DoubleDim r As IntegerDim c As IntegerDim i As IntegerDim k As Integer'get data collector data as DataSetDim ds As System.Data.DataSet=dcDoc.DataIf ds.Tables.Count < 2 Then Exit Sub'get the first tableDim dt As System.Data.DataTable=ds.Tables(1)Dim s As String=""'ThisApplication.Output.Show'print column namesDim col As System.Data.DataColumnFor Each col In dt.Columnss+=col.Caption & vbTabNextr=0'ThisApplication.Output.PrintMessage(s)'can be used instead of Debug.Print'print dataFor Each row As System.Data.DataRow In dt.Rowsr+=1s=""c=0For Each col In dt.Columnsc+=1s+=row(col).ToString & vbTab'tmp(r,c) = row(col)tmp(r,c) = Val(row(col).ToString)Next'ThisApplication.Output.PrintMessage(s)NextFor i = 1 To rFor k=1 To c'Debug.Print tmp(i,k)NextNext'Debug.Print r.ToString & vbTab & c.ToStringDebug.Print NowEnd Sub0
-
The issue is that when your function has type of SimpleScript it's executed twice, when it's loaded (for variable parsing) and when it runs. All user code inside SimpleScript must be placed inside CodeCommand, like this:
With Automate.ScriptingCommands.CodeCommand(FD_Measure) If .Run() Then ' User Code Here PrintDCdata End If End With
You can search the forum for CodeCommand to see more examples.
Yuri0 -
Ahhh makes sense - I thoug it was something like that - Thank you...again:-))0
Categories
- All Categories
- 961 Image-Pro v9 and higher
- 9 Image-Pro FAQs
- 18 Image-Pro Download & Install
- 448 Image-Pro General Discussions
- 486 Image-Pro Automation (Macros, Apps, Reports)
- 20 AutoQuant Deconvolution
- 2 AutoQuant Download & Install
- 18 AutoQuant General Discussions
- 195 Image-Pro Plus v7 and lower
- 3 Image-Pro Plus Download & Install
- 106 Image-Pro Plus General Discussions
- 86 Image-Pro Plus Automation with Macros
- 19 Legacy Products
- 16 Image-Pro Premier 3D General Discussions
- 26 Image-Pro Insight General Discussions