Home Image-Pro Automation (Macros, Apps, Reports)

Different behavior of program code on different Windows 10 worksations

Hi everyone,

multi-channel (czi) images with 3 - 5 channels are used. The app activates a defined channel. Another function can be used to determine whether a measurement is present on the active channel. To do this, a measurement must be drawn in by the user with the measurement tools. This works correctly on some workstations and not at all on others. 

Windows 10 Build 19045.3996 and Image Pro 10 Build 10.0.15.7533 are used on the workstations.

Program code for activating a specific channel:
    Public Sub SetChannel()
        If ThisApplication.ActiveImage Is Nothing Then Exit Sub

        Dim iSelectedChannel As Integer = 0
        ' set selected channel when imageset
        iSelectedChannel = InputBox("Set Channel to Activate:", "Set Channel", iSelectedChannel)

        With MediaCy.Automation.View.ImageSetViewCommands.Options(Nothing)
            .ViewLocation = New MediaCy.IQL.Sets.McImageSetLocations
            .ViewLocation.Add(MediaCy.IQL.Sets.mcImageSetDimensions.mcisdChannel, iSelectedChannel)
            .Run(ThisApplication.ActiveWindow)
        End With
    End Sub

Program code for checking whether measurement is available:
    Public Sub MeasurementAvailableOnImage()
        Dim bAvail As Boolean = True
        Dim img As McImage = Nothing
        Dim md As Mediacy.Addins.Measurements.McMMData = Nothing

        Try
            img = ThisApplication.ActiveImage
            md = img.MeasurementsData

            If md.SubFeatures.Count=0 Then bAvail = False
            md = Nothing
        Catch ex As System.Exception
            MsgBox(ex.Message)
            Exit Sub
        End Try

        MsgBox "Measurement Available: " & bAvail & vbLf & "Diplayname: " & img.DisplayName
    End Sub

Why are there different behaviors? Is this perhaps related to the installed .NET frameworks? What else can I try? How can I fix the problem?

Thank you in advance
Friedrich




Best Answer

  • Answer ✓
    Hi Friedrich,

    Thank you for the image. The image is VLI, but if the computer has enough memory, it is loaded as normal image set.
    In IP10, the command that updates the set location is not working for VLI images, so I modified your macro to handle VLI differently:
        Public Sub SetChannel()
            Dim iSelectedChannel As Integer = 0
            ' set selected channel when imageset
            iSelectedChannel = InputBox("Set Channel to Activate:", "Set Channel", iSelectedChannel)
            If ThisApplication.ActiveDocument Is Nothing Then Exit Sub
            Dim dataType As mcDocumentType = ThisApplication.ActiveDocument.DataType
    
            If  dataType = mcDocumentType.mcdtVeryLargeSet Then
                'VLI
                Dim view As Mediacy.Viewers.Set.McSetLocationViewBase = ThisApplication.ActiveWindowEx.DocumentView
                Dim ViewLocation = New MediaCy.IQL.Sets.McImageSetLocations
                ViewLocation.Add(MediaCy.IQL.Sets.mcImageSetDimensions.mcisdChannel, iSelectedChannel)
                view.UpdateView(ViewLocation)'VLI
            Else
                'ImageSetView
                With MediaCy.Automation.View.ImageSetViewCommands.Options(Nothing)
                    .ViewLocation = New MediaCy.IQL.Sets.McImageSetLocations
                    .ViewLocation.Add(MediaCy.IQL.Sets.mcImageSetDimensions.mcisdChannel, iSelectedChannel)
                    .Run(ThisApplication.ActiveWindow)
                End With
            End If
    
        End Sub
    The macro will change the active channel (though it doesn't update the toolbar).
    Please test the macro.

    Also, as I mentioned earlier, you can increase the limit for VLI (e.g. to 75%),



    so these images will be opened as normal image set (not VLI) and your old macro will work properly.

    Regards,

    Yuri

Answers

  • Hi Friedrich,

    I don't think it's related to Windows or .NET framework.
    The issue might be related to the Composite view or active channel. Image-Pro 10 doesn't support measurements on Composite view of image sets, so you must switch the Composite mode of the set viewer off (maybe you already do that). Another issue might be related to updating ThisApplication.ActiveImage after changing the channel programmatically.

    Here are 3 macros that print image name using different methods (ActiImage, SelectedData, ImageSet):

        Public Sub PrintActiveImageName
            Debug.Print(ThisApplication.ActiveImage.Name)
        End Sub
    
        Public Sub PrintSelectedImageName
            Debug.Print(ThisApplication.SelectedData.Image.Name)
        End Sub
    
        Public Sub PrintCurrentChannelImageName
            Debug.Print(ThisApplication.SelectedData.ImageSet.GetSourceAtLocation(ThisApplication.SelectedData.ImageSet.GetCurrentLocation(),MediaCy.IQL.Sets.mcImageSetLocationMatchTypes.mcislmtExact).Image.Name)
        End Sub
    

    You can test all 3 of them to check which one returns the name of the active channel and use in the MeasurementAvailableOnImage macro to set "img".

    Regards,

    Yuri


  • Hi Yuri,

    yes, I turned off the composite view. Great, "ThisApplication.SelectedData.Image" works  for the function MeasurementAvailableOnImage. PrintCurrentChannelImageName returns an error:



    What else can I try regarding the SetChannel procedure?

    Best,
    Friedrich

  • edited February 1
    Hi Friederich,

    The error means that one of the properties in that function is Nothing, it has to be debugged, but if you found that SelectedData returns you the right image, you can just use that function as:
    img = ThisApplication.SelectedData.Image
    Also, I see from the screenshot that your image is VLI (Very Large Image). Is that image you are going to measure?
    Note, that VLI images can be opened and a normal image or a VLI depending on the amount of free memory available on the computer.
    You can tweak application options to load VLI as normal image:



    Yuri
  • Hi Yuri,

    exactly, the multi-channel images are opened as VLIs. The assignment to the variable "img" works correctly.

    What does not yet work is the activation of a channel with the following program code:

        Public Sub SetChannel()
            Dim iSelectedChannel As Integer = 0
            ' set selected channel when imageset
            iSelectedChannel = InputBox("Set Channel to Activate:", "Set Channel", iSelectedChannel)
    
            With MediaCy.Automation.View.ImageSetViewCommands.Options(Nothing)
                .ViewLocation = New MediaCy.IQL.Sets.McImageSetLocations
                .ViewLocation.Add(MediaCy.IQL.Sets.mcImageSetDimensions.mcisdChannel, iSelectedChannel)
                .Run(ThisApplication.ActiveWindow)
            End With
        End Sub
    This is the problem that does not work yet.

    Thanks.
    Best,
    Friedrich
  • Hi Friedrich,

    I have to check with that particular set. Can you please send me the test image? Click here to upload files.

    Yuri
  • Hi Yuri,

    I uploaded a zipped file.

    Best,
    Friedrich
  • Hi Yuri,

    okay, now I have understood the issue. The macro works as expected.

    Thank you.
    Best,
    Friedrich
Sign In or Register to comment.