Establishing directory for batch processing

Hi all,

I have the code for batch processing from a directory from one of the demos.  However, when running the code it keeps coming up with an error when it begins the code:

If gDirStart = "" Then                        'Error is in this line
gDirStart = "C:\"
End If

The error I am getting is Expecting an existing scalar var.

There is a comment before this line of code stating

' Make certain we have a reasonable starting point. This code is
' only executed the first run after macro compilation. If you have
' a desired standard starting point, initialize the directory
' search here.

Am I supposed to be running something first to set the directory? 

Thanks,

Jena

Best Answer

  • Accepted Answer
    Jena,

    I don't see declaration of gDirStart in your code (that causes the error).
    Please be sure that you have the following declaration either before or inside your sub:

    Dim gDirStart As String

    Yuri

Answers

  • Hi Jena,

    If you are talking about Batch_Process.ipm macro and you get error on line 80, then it might be something wrong with the macro or IPP version as it works properly in my tests in IPP 7.0.1.

    What version of IP Plus do you use? Have you modified the macro yourself (or Copy/Pasted to your own macro)? If yes, check that gDirStart is defined (it's defined on line 67 in the demo macro).

    Yuri

  • It's in the beginning of the code.  It won't go past line 13 when running in trace mode.  I copied the code from another computer that is also running batch processing.  The code works on the other computer.  That code was put together by a coworker a couple years ago so I was not sure if there was another step I was missing.  Below is the entire code I copied.  We have the latest version on both computers 7.0.1.

    Sub ProcessDirectory()
    '<c><s>B
    ' Scan through and process all files in a directory
     Dim IName As String*255
     Dim fName As String
     Dim workStr As String
     Dim docID As Integer

     ' Make certain we have a reasonable starting point. This code is
     ' only executed the first run after macro compilation. If you have
     ' a desired standard starting point, initialize the directory
     ' search here.
     If gDirStart = "" Then
      gDirStart = "C:\"
     End If

     ' Get a file name in the desired directory
     workStr = GetFilePath("", "*", gDirStart, _
           "Select a file in the desired directory", 0)

     ' Check to make certain the user did not cancel
        If workStr = "" Then
         Exit Sub
        End If

        ' Close all open images prior to processing (this can be removed if desired)
     ret = IpAppCloseAll()

     ' Extract the directory name from the full file name
        gDirStart = Left(workStr, InStrRev(workStr, "\"))

     ' Clear the output for work purposes
        DebugClear
        ret = IpOutputClear()

     ' Call a setup routine ***
     ' Insert your setup call here
     ret = IpDcShow(1)
     ret = IpDcMeasList(DC_LOAD,"C:\Measurements_List.dcl")
     ret = IpBlbSetFilterRange(BLBM_MEANFERRET, 11.81237, 1771.8558)' this range constrains particles to 2-300um for the 20_045NA objective
     ret = IpDcSet(DC_AUTO, 0)
     ' Look for standard files, no directories or system files.
        ' See the 'Dir' command help for details
        fName = Dir(gDirStart + "*.*", 32)

        While fName <> ""
         ' Print out the file name and its attributes
         Debug.Print GetAttr(gDirStart + fName); " "; fName

         ' Load the image
         docID = IpWsLoad(gDirStart + fName, "")

         ' Don't process if there is a failure loading
         If docID >= 0 Then
          ' Call processing routine here ***
          ' The document ID and file name are sent here
          ' in case the processing routine needs them.
          'DoStuff docID, gDirStart + fName
    Dim fileName As String, dirName As String
     Dim extension As String, baseName As String
     Dim name_Script As String, name_Image As String
     Dim delim As Integer
     fileName = fName 'GetFilePath(, , , , 0)
     If fileName = "" Then Exit Sub
     ' Chop up the file name using searches for "." and "\" delimiters
     Debug.Print "fileName: "; vbTab; fileName
     delim = InStrRev(fileName, ".")
     Debug.Print "delim: "; vbTab; delim
     extension = Right(fileName, Len(fileName)- delim)
     Debug.Print "extension: "; vbTab; extension
     baseName = Left(fileName, delim - 1)
     Debug.Print "baseName: "; vbTab; baseName
     delim = InStrRev(fileName, "\")
     Debug.Print "delim: "; vbTab; delim
     dirName = Left(fileName, delim)
     Debug.Print "dirName: "; vbTab; dirName
     ' Build new file names for later use
     name_Script = gDirStart + baseName + "_outlines" + "." + "scl"
     name_Image = gDirStart + baseName + "_outlines" + "." + extension
    Debug.Print "name_Script: "; vbTab; name_Script
    Debug.Print "name_Image: "; vbTab; name_Image
    Debug.Print ""

    ret = IpSCalSelect("20x")
     ret = IpFftHiPass(30, 10, 1)
     ret = IpBlbSetAttr(BLOB_CLEANBORDER,1)
     ret = IpBlbCount()
     ret = IpBlbUpdate(0)
     ret = IpDcUpdate(DC_FETCH)
     ret = IpBlbSaveOutline(name_Script)
     ret = IpSnap()
     ret = IpWsSaveAs(name_Image,"JPG")
     ret = IpDocClose()


          ' Close the initial image
          ret = IpAppSelectDoc(docID)
          ret = IpDocClose()
      Else
       Debug.Print "Error loading "; gDirStart + fName
      End If

         ' Get the next file name
         fName = Dir()
        Wend

     ' Call a finish routine ***
     ret = IpDcSaveData("C:\Desktop\IP_Coding\Data.txt",  S_Y_AXIS + S_X_AXIS)
        ' Let the user know that we've finished
        ret = IpMacroStop("All images in directory processed.", MS_MODAL)


    What I am trying to do is have batch processing with the code I received from you previously about counting an object then setting that as an area of interest and counting and classifying objects inside the aoi.  Then saving that data removing the aoi and closing the image.  Open another image and perform the same tasks.

  • That may be why it was seeing it as a scalar var! Thanks!

Sign In or Register to comment.