Home Image-Pro Plus Automation with Macros

Can't remove custom data from collector field

(Originally posted by Rik on 6/20/2013)

I am having a problem with the data collector.

I have written a macro that export measurement data to the data collector. To do that, the macro checks if there are columns defined, if not it will create one:

IpDcGet (DC_NUMCUSTCOL, 0, number_of_columns)
If number_of_columns = 0 Then
ColN1 = IpDcAddCol("Margination Index")
Else
IpDcGet (DC_CUSTCOLID, 0, ColN1)
End If

Now if I analyzed a few cells and exported the data from the data collector to excel, I run a second macro that should clear the data collector (both data and columns).

Sub reset_data_collector()
Dim number_of_columns As Long
Dim x As Integer
Dim ColN1 As Long
IpDcUpdate(DC_RESET)
IpDcGet(DC_NUMCUSTCOL, 0, number_of_columns)
For x = 0 To number_of_columns
IpDcGet (DC_CUSTCOLID, x, ColN1)
IpDcDeleteCol(ColN1)
Next x
IpDcUpdate(DC_RESET)
End Sub

Now the ipdcupdate ensures that all data is removed and I thought that IpDcDeleteCol(ColN1) would remove the measurement column. Unfortunately it does not.

The problem is that the next time I run the measurement macro again, a second measurement column is created. I also can't delete the columns by pressing the delete all button since these are custom columns. Also the layout tab still shows the custom measurements and can't be removed.

I must make a mistake here somewhere. Could someone tell me how to do this the correct way?

Comments

  • (Originally posted by YuriG on 6/20/2007)

    Hi Rik,

    I found old macro and tested it in IPP6.2. It adds and deletes custom columns correctly.

    Sub MyDataCollect()
                Dim ColN(120) As Long              ' variables to hold the column IDs
                Dim Snumobj(1) As Single
                Dim SNFeatures(1) As Single
                ret = IpDcShow(3)
    
                ColN(0) = IpDcAddCol("Image Name")' this is just a name, not a type
                ColN(1) = IpDcAddCol("Num Objects")' We can repeatedly do the following
                ColN(2) = IpDcAddCol("Num Features")
    
                ' Get number of objects
    			Dim numobj As Long
                ret = IpBlbGet(GETNUMOBJ, 0, 1, numobj)
    
                Snumobj(0) = CSng(numobj)
                SNFeatures(0) = 1'CSng(NFeatures)
    
                ' Write number of objects
                ret= IpDcAddSng(ColN(1), 0, 1, Snumobj(0))
    
                ' Write number of Features
                ret= IpDcAddSng(ColN(2), 0, 1, SNFeatures(0))
    
                ' Delete Columns
                ret = IpDcDeleteCol(ColN(0))
                ret = IpDcDeleteCol(ColN(1))
                ret = IpDcDeleteCol(ColN(2))
    End Sub
    
    



    You can compare it with your code.

     

  • (Originally posted by Rik on 6/20/2007)

    Thanks Yuri,

    I think I found the problem (maybe someone else encounters the same problem in the future). I used this script to remove the columns as stated above:

    IpDcUpdate(DC_RESET)
    '<- this line is causing the problem
    IpDcGet(DC_NUMCUSTCOL, 0, number_of_columns)
    For x = 0 To number_of_columns
    IpDcGet (DC_CUSTCOLID, x, ColN1)
    IpDcDeleteCol(ColN1)
    Next x
    IpDcUpdate(DC_RESET)
    End Sub

    I used IpDcUpdate(DC_RESET) twice to remove all entries from the data list. When I removed the first ipdcupdate occurrence, the script works.

    So it seems that when I remove all entries by IpDcUpdate(DC_RESET), it indeed removes all measurement data from the data list, but not the columns (since they are custom columns and need to be removed with IpDcDeleteCol). However the IpDcUpdate(DC_RESET) does something since IpDcGet (DC_CUSTCOLID, x, ColN1) does not return the appropriate column ID anymore.

    So problem solved by using IpDcUpdate(DC_RESET) after deleting the columns.

Sign In or Register to comment.