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
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
+
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
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
0
Best 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
0
Answers
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
When you will create an IPX file, all files should be added, so please send me IPX.
Thanks,
Yuri
VIEW RIBBON + WORKSPACE + DOCKING (causes error)
or
VIEW RIBBON + WORKSPACE + MDI (no error)
- Work with V1B in only the MDI MODE
- Receive a V1C version that works in both MDI and DOCKING MODE
Thanks again.(via YOUR CODE)
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