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

Issue with "ThisApplication.ActiveImage.SpatialCalibration"

2019-10-04-110303

All --

Back in 2017 I created an IMAGE-PRO APP that was originally installed and has been running on an IP 9.1 32 BIT system.  The owner of the app would like to move the APP to a WIN 10 64 BIT SYSTEM running IP 9.2 but there seems to be an issue.

Embedded within the CODE is

        Dim MyTempCalibUnits As String
        Dim MyTempCalibPixelSize As Single

        'Learn the SPATIAL CALIBRATION INFO for this IMAGE
        If (ThisApplication.ActiveImage.SpatialCalibration IsNot Nothing) _
            Then

                MyTempCalibUnits = _
                    ThisApplication.ActiveImage.SpatialCalibration.UnitAbbrev
                MyTempCalibPixelSize = _
                    ThisApplication.ActiveImage.SpatialCalibration.PixelSizeX
            Else

                MyTempCalibUnits = _
                    "pix"
                MyTempCalibPixelSize = _
                    1

            End If

This section of code runs properly on the 9.1 32 BIT SYSTEM (and on my WIN 7 / IP 10 SYSTEM) but it does not run properly on the customer's WIN 10 / IP 9.2 SYSTEM.

The issue seems to be that IP 9.2 does not fully recognize

    "ThisApplication.ActiveImage.SpatialCalibration"

even though SpatialCalibration is a choice after typing ThisApplication.ActiveImage. in the PROJECT WORKBENCH.

Please see the images below for the version of IP 9.2, the ERROR, and the DEPENDENCIES that were exported out of the APP that was problematic on the customer's computer.

I created a V1C version of this APP and I specifically added

    import MediaCy.IQL.Features.dll

to the CODE and that did not resolve the issue.

I also performed an

    IMPORT
    +
    ADD ALL MEDIA CYBERNETICS REFERENCES 

within the EDIT + DEPENDENCIES on the customer's computer and that seemed to mangle some of the CODE related to the CAMERA because it will not load properly after the ADD ALL.

We have thrown away the V1C version of the APP and reverted back to the V1B version that seems to have an issue with the

    "ThisApplication.ActiveImage.SpatialCalibration"

Your guidance on a resolution for this would be much appreciated.

By the way, the PROJECT / APP loads without error and runs properly until it hits an instance of

    "ThisApplication.ActiveImage.SpatialCalibration"

Thanks.

-- Matt

*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-





Best Answer

  • edited October 2019 Answer ✓
    Hi Matt,

    Thanks for the IPX, I checked it and found the problem. The issues was that you closed active image and have not activated other image, so ThisApplication.ActiveImage on line 442 was Nothing, which through an error. You have MDICommands.TileVertically command, which in MDI mode activated image after tiling, but in SDI mode that command has no effect, so nothing changed there. 

    One of the solutions to fix the problem is to add a line that activates proper image, before you check spatial calibration, like this:
            With Adjust.ImageCommands.Close(Nothing)
                .Run(image1)
            End With
    
            'make the Canvas image active
            With Application.DocumentCommands.Activate(Nothing)
                .Run(image2, doc2)
            End With
    
    '        'Connect with the NEW IMAGE 'YG: don't need these commands
    '        With Application.DocumentCommands.ActiveImage(Nothing)
    '            .Run(image2)
    '        End With
    '
    '        With Application.DocumentCommands.Active(Nothing)
    '            .Run(doc2)
    '        End With
    
    
            'Trigger the TILE function to make this image as big as possible
            Application.MDICommands.TileVertically(Nothing).Run()
    
            Dim MyTempCalibUnits As String
            Dim MyTempCalibPixelSize As Single
    
            'Learn the SPATIAL CALIBRATION INFO for this IMAGE
            If (ThisApplication.ActiveImage.SpatialCalibration IsNot Nothing) _
                Then
    ...

    After that the macro works properly,

    Regards,

    Yuri

Answers

  • Hi Matt,

    Do you have ActiveImage opened? If not, it will throw an error as you have on line 442.
    Can you attach a sample project (IPX), so wee can test it?

    Thanks,

    Yuri
  • 2019-10-04-163646

    Yuri --

    There is definitely an image open.

    I cannot post the project on the forum but I can send it to you directly.

    I have not saved it as an IPX file.  Right now it is 2 VB FILES, 1 RESX FILE, and 1 IPP FILE.

    Would you like me to send those to you, group them into a ZIP FILE, or re-save it as an IPX FILE?

    -- Matt
  • Hi Matt,

    When you will create an IPX file, all files should be added, so please send me IPX.

    Thanks,

    Yuri


  • 2019-10-04-172104

    Yuri --

    I will attempt to save the PROJECT in an IPX FILE and then I will send you that file.

    I have another project open in front of me now so it will probably be about 30 minutes before I'll be able to change gears and do this.

    Thanks.

    -- Matt


  • 2019-10-04-182243

    Yuri --

    I have saved the PROJECT as an IPX FILE and I have sent it to you by E-MAIL.

    While typing up the E-MAIL, I found an OPTION within IP10 that makes the ERROR HAPPEN or NOT HAPPEN.

    That is

        VIEW RIBBON + WORKSPACE + DOCKING (causes error)

    or

        VIEW RIBBON + WORKSPACE + MDI (no error)

    I prefer the MDI MODE and I never tested the software in that MODE.

    The customer's first computer was set up by me and I must have set that MODE before I installed the APP.

    Hopefully there is a way to patch this up so that the DOCKING MODE will work.

    Thanks.

    -- Matt



  • 2019-10-07-101438

    Yuri --

    Thank you for your response.

    I do not understand why MY CODE works the in MDI MODE but not in the DOCKING MODE.  The issue seems to be somewhere within the subtleties of the differences between 3 functions with very similar names like ACTIVATE, ACTIVEIMAGE, and ACTIVE.

    If you could explain this sometime, that would be super.

    I will touch base with the customer to determine whether they want to:
    1. Work with V1B in only the MDI MODE
    2. Receive a V1C version that works in both MDI and DOCKING MODE
      (via YOUR CODE)
    Thanks again.

    -- Matt

  • Hi Matt,

    As I explained in my previous post, your code deleted active image, which made ActiveImage=Nothing.
    1. Apparently, as a side effect,  the command Application.MDICommands.TileVertically(Nothing).Run() running in MDI mode, activated an image (any), which also made you macro work without exception.
    2. The command Application.MDICommands.TileVertically(Nothing).Run() is ignored/does nothing (by design) in SDI mode, so no change to the state of active image, which stays as Nothing and causes an error on lines below. 

    Yuri
  • 2019-10-07-140254

    Yuri --

    Thank you for the additional information.

    I am still unclear on what is causing the error.

    As shown in the error, when run in the DOCKING (SDI?) MODE, the issue with

        "ThisApplication.ActiveImage.SpatialCalibration"

    shows itself to me and the customer in LINE 442 (see below).

    In MY CODE, LINES 426 through 433 are an meant to make the NEW (CANVAS) IMAGE the ACTIVE IMAGE.

    Your information says that when in the SDI MODE, no change in the state of the active image happens when the TILE COMMAND is run.  This makes me unclear on why the ACTIVATE performed in 426 through 433 doesn't give 442 the connection it needs to the image.

    I guess some of this boils down to what is the difference between MY CODE
            'Connect with the NEW IMAGE 
            With Application.DocumentCommands.ActiveImage(Nothing)
                .Run(image2)
            End With
    
            With Application.DocumentCommands.Active(Nothing)
                .Run(doc2)
            End With
    that does not properly set up the ACTIVE IMAGE and YOUR CODE
            'make the Canvas image active
            With Application.DocumentCommands.Activate(Nothing)
                .Run(image2, doc2)
            End With
    that does seem to set up the ACTIVE IMAGE properly so that that the

        "ThisApplication.ActiveImage.SpatialCalibration"

    is recognized?

    I have created a V1C version of the APP and I have used YOUR .ACTIVATE CODE instead of MY .ACTIVEIMAGE and .ACTIVATE CODE and the APP now works whether in the MDI MODE or DOCKING / SDI MODE.

    Thanks for the working to resolve and explain this issue.

    -- Matt


    V1B CODE  (DOES NOT WORK IN DOCKING / SDI MODE)




    V1C CODE  (WORKS IN DOCKING / SDI MODE)



Sign In or Register to comment.