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

Create Image Set

Hello

I made a mask image from an image with Z, Timepoint and channels. The resulting mask image doesn't maintain any of the dimension information so I want to recreate it. I copied the following code from the help files which looks like it should recreate the z dimension and I was going to adapt it to include timepoints and channels.

Public Function CreateSetFromFrames()
Dim aSet As McImageSet

If ThisApplication.ActiveImage Is Nothing Then
MsgBox "No Image"
Exit Function
End If

Set aSet = ImageSets.Add("SampleSet")
Dim theLoc As New McImageSetLocations
Dim i As Integer
Dim theFrame As McFrame
For i = 0 To 34
theLoc.RemoveAll            ' get ready for next location
theLoc.Add mcImageSetDimensions.mcisdChannel, 0  ' adding Channel 0
theLoc.Add mcImageSetDimensions.mcisdZ, i        ' and this Z position
' note that while we are adding site 0 in this loop, we don't really have to specify that
' because a position of zero is assumed for any unspecified dimensions
Set theFrame = ThisApplication.ActiveImage.Frame(i)
theFrame = ThisApplication.ActiveImage.Frame(i)
aSet.AddFrame theFrame, theLoc
Next i

End Function

The problem is that I get an Invalid Instruction error for Set aSet = ImageSets.Add("SampleSet") and I can't figure out what is wrong as adding End Set doesn't solve it. So the question is am I on the right track with this code and if yes what should I do with the Set error.

Regards

David

Best Answer

  • edited October 2014 Answer ✓
    Hi David,

    One more change has to be made converting VBA macros to .NET: add "ThisApplication." in front of global objects.
    Also ImageSets now is a property of ThisApplication.Engine. I modified your macro to make it work:

        Public Function CreateSetFromFrames()
            If ThisApplication.ActiveImage Is Nothing Then
                MsgBox "No Image"
                Exit Function
            End If
    
            Dim aSet As McImageSet
            aSet = ThisApplication.Engine.ImageSets.Add("SampleSet")
            Dim theLoc As New McImageSetLocations
            Dim i As Integer
            Dim theFrame As McFrame
            For i = 0 To ThisApplication.ActiveImage.FrameCount-1
                theLoc.RemoveAll            ' get ready for next location
                theLoc.Add mcImageSetDimensions.mcisdChannel, 0  ' adding Channel 0
                theLoc.Add mcImageSetDimensions.mcisdZ, i        ' and this Z position
                ' note that while we are adding site 0 in this loop, we don't really have to specify that
                ' because a position of zero is assumed for any unspecified dimensions
                theFrame = ThisApplication.ActiveImage.Frame(i)
                aSet.AddFrame theFrame, theLoc
            Next i
            'make the set visible
            ThisApplication.Windows.Add(aSet)
        End Function
    

    I tested it with Heart.seq demo sequence.

    Yuri

Answers

  • edited October 2014
    Hi David,

    These samples were written in old VBA languge, the current macro language uses .NET syntax, so you should just remove "Set" from the code:
    aSet = ImageSets.Add("SampleSet")
    Yuri
  • Hello Yuri

    I tried that but it complains about Expecting a valid data type (eg integer)

    David

  • Thanks Yuri, that works

    David

Sign In or Register to comment.