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

How to draw Line Profile on invisible image?

Hi guys,

I  create an invisible image and I want to draw Line Profile on it .
But it pop up an error message about
'Unable to cast COM object of type 'MediaCy.IQL.Engine.McImageClass' to interface type 'MediaCy.IQL.Application.IMcDocument'.



[code]
Dim im As McImage = ThisApplication.ActiveImage
Dim invisible_im As McImage = im.Duplicate(mcImageCreateFlags.mcicfNotVisible) 'Create invisible image

With Measure.LineProfile.ProfileCommands.Add(Nothing)
     .ProfileType = LineProfile.ProfileTypes.Line
     .Points = New System.Collections.Generic.List(Of System.Drawing.PointF)
     .Points.Add(New System.Drawing.PointF(1689, 1116))
     .Points.Add(New System.Drawing.PointF(1952, 1116))
     .Angle = 0R
     .CreateEngine = true
     .Run(invisible_im) 'Draw Line Profile on invisible image
End With

Can I draw Line Profile  on invisible image?

Please help me to solve this annoying problem, thanks!

Answers

  • Options
    Hi Tony,

    Line Profile commands works with IMcDocument (visible image or image set) and will not work with invisible image. As workaround you can create McLines instance attached to invisible image (Ex: Dim lines As McLines = McApplication.ThisApplication.CreateOperator("McLines", MyInvisibleImage, "MYLines")) and use lines.Profiles to analyze edges.

    Thanks,
    Nikita. 
  • Options
    Hi Tony,

    With small modifications in the macro you can create invisible document and use it with the line profile commands:
        Public Function InvisibleDocument() As SimpleScript
            InvisibleDocument = New SimpleScript
            Dim im1, doc1, win1
            
            With Automate.ScriptingCommands.CodeCommand(InvisibleDocument)
                If .Run() Then
                    ' User Code Here
                    im1 = .Application.ActiveImage.Duplicate(mcImageCreateFlags.mcicfNotVisible) 'create invisible image
                    doc1 = .Application.Documents.Add(im1) 'create invisible document
                End If
            End With
    
            With Measure.LineProfile.ProfileCommands.RemoveAll(InvisibleDocument)
                .CreateEngine = True 'force to create line profile engine for invisible document
                .Run(doc1)
            End With
    
            With Measure.LineProfile.ProfileCommands.Add(InvisibleDocument)
                .Text = "Add Profile"
                .ProfileType = LineProfile.ProfileTypes.Line
                .Points = New System.Collections.Generic.List(Of System.Drawing.PointF)
                .Points.Add(New System.Drawing.PointF(10F,10F))
                .Points.Add(New System.Drawing.PointF(100F,100F))
                .Angle = 0R
                .Run(doc1)
            End With
    
            With Application.DocumentCommands.Show(InvisibleDocument)
                .Run(doc1, win1)'show document
            End With
    
        End Function

    Key modifications:

    1) create invisible document from the invisible image
    doc1 = .Application.Documents.Add(im1) 'create invisible document

    2) force to create line profile engine (.CreateEngine = True should be set on the first line profile command)
    .CreateEngine = True
    Remember to close invisible document to free up the memory. 

    Nikita.

  • Options
    Thanks Nikita, 

    This is of great help to me!
Sign In or Register to comment.