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

VB.NET / VS 2022 QUESTION . . .

2024-07-13-105315

All --

I would like to use VB.NET in VISUAL STUDIO 2022 to control IMAGE-PRO 11.

I have started a new VP PROJECT from scratch and I think I have a good start but . . .

The ERROR show below happens whether IP11 is running or not.


The IMAGE FILE is definitely in the the FILE named so I believe that there is an issue with VS2022 connecting with IP11.

What is the solution to this please?

Thanks.

-- Matt



Answers

  • Hi Matt,

    You have 2 options to interface with Image-Pro using .NET languages:
    • The most common and easiest way is to create an Add-in for Image-Pro, see https://forums.mediacy.com/discussion/comment/2684#Comment_2684 for details. In this case you are extending Image-Pro's capabilities with a dll which can contain additional logic as well as some new panels, ribbon controls, or dialogs for the UI.
    • The other option is to use the Automation Server for which you will find documentation in C:\Program Files\Media Cybernetics\Image-Pro 11\Help\Automation Server Help.chm. In that case your application would be using Image-Pro as an image analysis server.
    In reference to your posting, it looks like you are missing the add-in plumbing that will give you a valid reference to the application object. You will find some example of that in the discussion mentioned above.
  • edited July 15
    2024-07-15-165043

    Pierre --

    When I snapped the pic, the VS2022 SOLUTION / PROJECT had no notifications about bad McApplication not being declared so I believe that all of the REFERENCES had been added to the PROJECT.  The ERROR happened at RUN TIME and acted like VB could not connect with IP 11.1.

    I have the following in my SOLUTION / PROJECT


    Are there others needed for the basic communication that is attempted by the CODE shown?

    I will look at 2684 and do my best to connect my VB APP with IP11.1.

    I will reconnect here if that does not work.

    Thanks.

    -- Matt



  • 2024-07-15-172002

    Pierre --

    I have looked at 2684 and the ZIP FILE within it.

    When I open that PROJECT, the REFERENCES that it has are as shown here.



    These REFERENCES have a BROWN TRIANGLE with EXCLAMATION MARK within as do the MEDIACY REFERENCES in my SOLUTION now.

    I have GOOGLED for what the BROWN TRIANGLE means and am not having luck finding out.

    Is this something related to the X DRIVE STUFF that I remember as part of the linkage between VB and IP?

    Thanks.

    -- Matt




  • edited July 16
    Hi Matt,

    It means that the reference DLL cannot be found. The sample project, which Pierre pointed you to, has all reference dlls in X:\ location.

    so, please make sure that your X-drive is mapped correctly, as mentioned in the instructions.

    I've attached the addin sample project that is created for VS 2022.

    Regards,

    Yuri

  • 2024-07-16-112459

    Yuri --

    Thank you for your message.

    When I built the project there were no errors showing in the EDIT MODE so I thought I had all of the REFERENCES needed.

    I put the FILES that you provided in

        C:\xxyyzz\c:\XXYYZZ\2024-07-16-113626 -- YURI PREMIER VB CODE

    I created an

        x.bat

    as shown in the SCREEN CAPTURE below.

    The SCREEN CAPTURE also shows that all of the REFERENCES seem happy but an error appears after START that I believe is due to VS2022 attempting to write a file into the IP11.1 FOLDER.   

    Does X need to be a FOLDER that just contains the DLLS / LIBRARIES?

    Thanks.

    -- Matt


  • edited July 16
    Matt,

    Yes, VS will copy some files there, so you must make the folder "C:\Program Files\Media Cybernetics\Image-Pro 11" writable.

    You can also debug your addin directly from Visual Studio setting Startup program as X:\Image-Pro.exe


    Yuri
  • 2024-07-16-160949

    Yuri --

    Thank you for that additional information.

    When the VB CODE PROJECT is compiled, does the FOLDER that is set up as an X DRIVE during development need to be an X DRIVE for the COMPILED CODE to run correctly and does it need to have SECURITY set up the same way?

    Thanks.

    -- Matt




  • edited July 16
    2024-07-16-173735

    Yuri --

    My USER LIST looks different than your.

    My USER NAME is not on the LIST (see below).

    In a DOS CMD WINDOW, after typing SET, my LOGIN / USER INFO shows as

    USERNAME=mbatc
    USERPROFILE=C:\Users\mbatc

    and that is also shown in

    COMPUTER MANAGEMENT +
    LOCAL USERS AND GROUPS +
    USERS

    Also . . .

    I am hoping to have a VB APP that is not an IMAGE-PRO ADDIN.

    I would like it to be run from WINDOWS if possible.

    Is there an example of that type of VB PROJECT available?

    I have another APP that was created from

        

    and I am hoping to connect that APP to IMAGE-PRO.

    I appreciate your guidance on this.

    Thanks.

    -- Matt





  • Hi Matt,

    X-drive mapping is done only for convenience during the development, you could also use "C:\Program Files\Media Cybernetics\Image-Pro 11" instead, but you'd had to change it in a lot of places. For runtime, you just copy your DLL and the Addin file to IP folder and run Image-Pro.

    Try to google and find a way to make a folder writable. I did it directly from the Properties dialog.

    There is some plumbing, which is required to connect an app to Image-Pro, which is implemented in the test project I attached. You should use it as an example to create Image-Pro addins.

    Pierre also mentioned a possibility to use "automation server", it uses a different way of connecting a custom app to Image-Pro. Check the help file he mentioned and see if it suits you better, samples are in C:\Program Files\Media Cybernetics\Image-Pro 11\Automation\Samples folder.

    Regards,

    Yuri

  • 2024-07-17-132759

    Yuri --

    Thank you for the suggestion about the AUTOMATION SERVER.  I think that may the missing link between the VB APP and IMAGE-PRO.

    I did a search on AUTOMATION SERVER on the IMAGE-PRO FORUM and found several DISCUSSIONS.

    I will dig into this later today.

    Thanks again.

    -- Matt



  • 2024-07-17-194847

    Yuri and Pierre --

    The following CODE gives me a list of the PROCESSES that are running and the PRODUCT NAME associated with them.

    •     Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    •         ' Get all the processes running on the local computer
    •         Dim processes As Process() = Process.GetProcesses()
    •         ' Iterate through each process and display its name
    •         For Each proc As Process In processes
    •             Try
    •                 ' Get the FileVersionInfo for the process
    •                 Dim fileVersionInfo As FileVersionInfo = proc.MainModule.FileVersionInfo
    •                 ' Display the product name
    •                 Debug.Print("Process Name: " & proc.ProcessName & " | Product Name: " & fileVersionInfo.ProductName)
    •             Catch ex As Exception
    •                 ' Handle the case where the process might not have access to the file info
    •                 Debug.Print("Process Name: " & proc.ProcessName & " | Product Name: N/A")
    •             End Try
    •         Next
    •     End Sub

    That LIST includes

    • Process Name: Image-Pro | Product Name: Image-Pro 64-bit

    when IP 11.1 is running.

    When I put

    • Image-Pro 64-bit

    into

    •         Try
    •             '_session = New Session("Image-Pro Premier 9.2 64-bit", 60)
    •             '_session = New Session("Image-Pro Premier 3D 9.2 64-bit", 60)
    •             _session = New Session("Image-Pro 64-bit", 60)
    •         Catch ex As Exception
    •             MsgBox("2" & " -- " & ex.Message)
    •             MsgBox("2" & " -- " & ex.ToString)
    •             Debug.Print("2" & " -- " & ex.ToString)
    •         End Try

    as the PRODUCT NAME in the PARAMETER LIST for the NEW SESSION, VS2022 does not seem to like the PRODUCT NAME.

    What is the proper PRODUCT NAME for IMAGE-PRO 11.1 please?

    Thanks.

    -- Matt






  • Hi Matt,

    For Image-Pro 11.1 the line is:

            _session = New Session("Image-Pro 11.1 64-bit", 60)

    Regards,

    Yuri
  • edited July 18
    2024-07-18-091632

    Yuri --

    Thank you for that information.

    The STRING "Image-Pro 11.1 64-bit" is specific to IP 11.1.

    If that string is written into a VB APP, then that APP would not work with IP 11.2 etc etc etc right?

    Would you and your team consider making that STRING more GENERIC so that an APP does not need to be modified to work with near future versions of IP 11?

    I can make something like an INI FILE that allows that STRING to be changed out side of the .EXE of a VB APP for future versions of IP right now.

    Also . . .

    How would I discover the STRING "Image-Pro 11.1 64-bit" via WINDOWS USER INTERFACE or VB CODE?

    Thanks again.

    -- Matt






  • edited July 18
    Hi Matt,

    We need to know precisely which executable to run, hence the specific version. You can get to that using this code:

    Imports System
    Imports Microsoft.Win32

    Module Program
        Sub Main()
            Dim localKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64)
            Dim appsKey = localKey.OpenSubKey("SOFTWARE\Media Cybernetics\IQ Family")
            For Each app As String In appsKey.GetSubKeyNames()
                Debug.Print(app)
            Next
        End Sub
    End Module

  • 2024-07-18-162559

    Pierre --

    Thank you for that additional information.

    I will work with it later today.

    Thanks again.

    -- Matt


  • 2024-07-18-190208

    All --

    I am not having good luck connecting a VB APP to IP 11.1 using VS2022.

    The SCREEN SHOT shown below seems to show that there is an issue trying to create the connection with IP 11.1 using "_session".

    I think I have packaged the SOLUTION shown below in a ZIP FILE 

        AAA FOLDER FOR FORUM -- 2024-07-18-191742.zip

    attached to this discussion.

    Will you folks look at this and see if you can help me make the connection between a VB APP and IP please?

    Thanks.

    -- Matt





  • Matt,

    The sample project is setup to build in the Image-Pro folder, if you want to keep it separate you just need to create an Automation folder in your project output folder and copy the assembly MediaCy.Automation.Server.dll in that folder.


  • 2024-07-19-105115

    Pierre --

    If I understand your message, my PROJECT FOLDER should have a BIN FOLDER that contains a DEBUG FOLDER that contains an AUTOMATION FOLDER that contains MediaCy.Automation.Server.dll.

    Making this change to the PROJECT in

        AAA FOLDER FOR FORUM -- 2024-07-18-191742.zip

    will resolve the issue with the

        _session =

    currently on

        LINE 24

    of

        FORM1.VB

    I will give this a shot later today.

    Thanks.

    -- Matt




  • edited July 19
    2024-07-19-134009

    Pierre --

    I followed your instructions as I understood them.

    The DLL FILE is now in the FOLDER that was discussed.  That is shown HERE.



    When I run the APP the _SESSION = on LINE 24 still generates an issue.

        Exception thrown: 'System.IO.FileNotFoundException' in MediaCy.Automation.Proxy.dll

    There is a good REFERENCE to
       
        MediaCy.Automation.Proxy

    shown on the right side of the SCREEN CAPTURE below.



    Will you give this another look please.

    Also . . .

    I thought that the ZIP FILE that I sent yesterday was a COMPLETE SOLUTION / PROJECT.  It turns out that the SAVE AS that I did to create the

        AAA FOLDER FOR FORUM

    did not put everything needed for the SOLUTION / PROJECT into the FORUM FOLDER

    There was a lot of "stuff" in the AAA FOLDER yesterday that was making a ZIP of that FOLDER very large.

    I found the CLEAN SOLUTION FEATURE of VS2022 today and now I can send you the AAA FOLDER via ZIP FILE.

    Please find

        AAA FOLDER -- 2024-07-19-134941.zip

    linked to this discussion.

    -- EDIT --

    I just saw some information via COPILOT that might be helpful.  Here is s SCREEN SHOT.



    I think I have done 1 and 2.  3 should not be required on a computer running IP 11.1 I think (This may be what you had me do with the AUTOMATION FOLDER).  4 and 5 are a bit of a mystery to me regarding this error.  I tried 6.

    I hope this information is helpful.

    Thank you for your assistance.

    -- Matt





  • Matt, I am sorry, there was a typo in my last message, the file needed in that Automation folder is MediaCy.Automation.dll as shown on the screenshot.
  • 2024-07-22-083525

    Pierre --

    Thank you for that guidance.

    I will try to implement your directions later today.

    Would you be able to open the PROJECT / SOLUTION in the ZIP FILE sent on 19-JUL-2024 to see if that is all that is needed to connect this PROJECT / SOLUTION to IP 11.1 please?

    Thanks.

    -- Matt




  • I checked your zip file and although it would connect to Image-Pro it will fail to access the application object.

    The automation server allows you to remotely run commands in Image-Pro, however it does not give you access to the McApplication object (see the sample project C:\Program Files\Media Cybernetics\Image-Pro 11\Automation\Samples\VB.NET\MediaCy.Automation.Samples.VBClient for details).

    If this is what you are looking for then you need to build an add-in as we had originally suggested.
  • 2024-07-22-205218

    Pierre --

    Thank you for this information.

    I believe that the ability to "run commands in IMAGE-PRO" is the PRIMARY GOAL.

    I do not understand the consequences or limitations that come with not having access to the McApplication Object.

    Thank you for directing me to


    I will look into this ASAP.

    Thanks again.

    -- Matt



  • edited August 2
    2024-08-02-153008

    Pierre and All --

    I have been working with the EXAMPLE code in my computer at

        C:\Program Files\Media Cybernetics\Image-Pro 11\Automation\Samples\VB.NET

    I copied that FOLDER to another FOLDER so that the ORIGINAL would remain unchanged.

    I resolved the REFERENCE ISSUES and the OUTPUT FOLDER ISSUE.

    There still seems to be an issue with

        _session = New Session("Image-Pro 11.1 64-bit", 60)

    in

        BackgroundWorker1_DoWork

    My version of BackgroundWorker1_DoWork is:

        Private Sub BackgroundWorker1_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork

            Debug.Print("-- BackgroundWorker1_DoWork -- START --")

            '_session = New Session("Image-Pro 10.0 64-bit", 60)
            '_session = New Session("Image-Pro 11.1 64-bit", 60)

            Try
                _session = New Session("Image-Pro 11.1 64-bit", 60)
            Catch ex As Exception
                Debug.Print("---- Exception Message: " & ex.Message)
                Debug.Print("---- Exception Message: " & ex.Message)
                Debug.Print("---- Stack Trace: " & ex.StackTrace)
                Debug.Print("---- Source: " & ex.Source)
            End Try

            Debug.Print("-- BackgroundWorker1_DoWork -- END --")

        End Sub

    Here is a SCREEN CAPTURE of VS2022 when this problem happens




    The TEXT OUTPUT from the DEBUG.PRINT COMMANDS is below.

    Will you direct me how to resolve this so my VS2022 / VB.NET PROJECT can control IP 11 please?

    Thanks.

    -- Matt

    **** FROM VS2022 OUTPUT WINDOW ****

    -- BackgroundWorker1_DoWork -- START --
    'MediaCy.Automation.Samples.VBClient.exe' (CLR v4.0.30319: MediaCy.Automation.Samples.VBClient.exe): Loaded 'C:\Compile Output\MediaCy.Automation.Server.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'MediaCy.Automation.Samples.VBClient.exe' (CLR v4.0.30319: MediaCy.Automation.Samples.VBClient.exe): Loaded 'C:\windows\assembly\GAC\Extensibility\7.0.3300.0__b03f5f7f11d50a3a\Extensibility.dll'. Module was built without symbols.
    'MediaCy.Automation.Samples.VBClient.exe' (CLR v4.0.30319: MediaCy.Automation.Samples.VBClient.exe): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel\v4.0_4.0.0.0__b77a5c561934e089\System.ServiceModel.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'MediaCy.Automation.Samples.VBClient.exe' (CLR v4.0.30319: MediaCy.Automation.Samples.VBClient.exe): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_MSIL\SMDiagnostics\v4.0_4.0.0.0__b77a5c561934e089\SMDiagnostics.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'MediaCy.Automation.Samples.VBClient.exe' (CLR v4.0.30319: MediaCy.Automation.Samples.VBClient.exe): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Serialization\v4.0_4.0.0.0__b77a5c561934e089\System.Runtime.Serialization.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'MediaCy.Automation.Samples.VBClient.exe' (CLR v4.0.30319: MediaCy.Automation.Samples.VBClient.exe): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Internals\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Internals.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'MediaCy.Automation.Samples.VBClient.exe' (CLR v4.0.30319: MediaCy.Automation.Samples.VBClient.exe): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_32\System.Transactions\v4.0_4.0.0.0__b77a5c561934e089\System.Transactions.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'MediaCy.Automation.Samples.VBClient.exe' (CLR v4.0.30319: MediaCy.Automation.Samples.VBClient.exe): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'MediaCy.Automation.Samples.VBClient.exe' (CLR v4.0.30319: MediaCy.Automation.Samples.VBClient.exe): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_32\System.Web\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Web.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    Exception thrown: 'System.Reflection.TargetInvocationException' in mscorlib.dll
    ---- Exception Message: Exception has been thrown by the target of an invocation.
    ---- Exception Message: Exception has been thrown by the target of an invocation.
    ---- Stack Trace:    at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
       at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
       at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
       at System.ServiceModel.Description.TypeLoader.GetKnownTypes(Object[] knownTypeAttributes, ICustomAttributeProvider provider)
       at System.ServiceModel.Description.TypeLoader.UpdateOperationsWithInterfaceAttributes(ContractDescription contractDesc, ContractReflectionInfo reflectionInfo)
       at System.ServiceModel.Description.TypeLoader.LoadContractDescriptionHelper(Type contractType, Type serviceType, Object serviceImplementation)
       at System.ServiceModel.ChannelFactory`1.CreateDescription()
       at System.ServiceModel.ChannelFactory.InitializeEndpoint(Binding binding, EndpointAddress address)
       at System.ServiceModel.ChannelFactory`1..ctor(Binding binding, EndpointAddress remoteAddress)
       at System.ServiceModel.ChannelFactory`1.CreateChannel(Binding binding, EndpointAddress endpointAddress)
       at MediaCy.Automation.Server.Connect(String uri, String exepath, Int32 timeout)
       at MediaCy.Automation.Proxy.Session..ctor(String product, Int32 timeout)
       at MediaCy.Automation.Samples.VBClient.Form1.BackgroundWorker1_DoWork(Object sender, DoWorkEventArgs e) in C:\Users\mbatc\Desktop\MediaCy.Automation.Samples.VBClient\Form1.vb:line 101
    ---- Source: mscorlib
    -- BackgroundWorker1_DoWork -- END --








  • 2024-08-02-170257

    All --

    I believe that I found and resolved the ISSUES that were keeping the EXAMPLE CODE in

        C:\Program Files\Media Cybernetics\Image-Pro 11\Automation\Samples\VB.NET

    from working with IP 11.1 via VISUAL STUDIO 2022.

    The ISSUES that I identified and addressed were:

    1. REFERENCES using the X DRIVE
      -- I resolved this by modifying the HINTPATH for the MEDIACY REFERENCES to
      "C:\Program Files\Media Cybernetics\Image-Pro 11\"
      See below.
      -- I changed the PROJECT COMPILE BUILD OUTPUT PATH from X:\ to
      "Compile Output\"
      See below.
    2. I modified SUBROUTINE "BackgroundWorker1_DoWork" in the manner shown below.
    3. I added an APPLICATION FOLDER to the COMPILE OUTPUT FOLDER that VS2022 created.
      This was needed by the
      "_session = New Session("Image-Pro 11.1 64-bit", 60)"
      statement in "BackgroundWorker1_DoWork"

    With those modifications, the VB APP was able to connect with and control IP 11 to perform the steps in "btnRun_Click".  This is shown here.



    I hope that this information is helpful to others in the IMAGE-PRO USER GROUP.

    I very much appreciate all the help on this and the other challenges that I have had with IP.

    -- Matt



    -- 1 --


        <Reference Include="MediaCy.Addins.Measurements, Version=3.1.0.0, Culture=neutral, processorArchitecture=MSIL">
          <SpecificVersion>False</SpecificVersion>
          <HintPath>C:\Program Files\Media Cybernetics\Image-Pro 11\MediaCy.Addins.Measurements.dll</HintPath>
        </Reference>
        <Reference Include="MediaCy.Automation.Proxy">
          <HintPath>C:\Program Files\Media Cybernetics\Image-Pro 11\\MediaCy.Automation.Proxy.dll</HintPath>
        </Reference>
        <Reference Include="MediaCy.Automation.Server">
          <HintPath>C:\Program Files\Media Cybernetics\Image-Pro 11\\MediaCy.Automation.Server.dll</HintPath>
        </Reference>
        <Reference Include="MediaCy.Commands.Features, Version=3.1.0.0, Culture=neutral, processorArchitecture=MSIL">
          <SpecificVersion>False</SpecificVersion>
          <HintPath>C:\Program Files\Media Cybernetics\Image-Pro 11\MediaCy.Commands.Features.dll</HintPath>
        </Reference>
        <Reference Include="MediaCy.Commands.Overlays, Version=3.1.0.0, Culture=neutral, processorArchitecture=MSIL">
          <SpecificVersion>False</SpecificVersion>
          <HintPath>C:\Program Files\Media Cybernetics\Image-Pro 11\MediaCy.Commands.Overlays.dll</HintPath>
        </Reference>
        <Reference Include="MediaCy.IQL.Application, Version=3.1.0.0, Culture=neutral, processorArchitecture=MSIL">
          <SpecificVersion>False</SpecificVersion>
          <HintPath>C:\Program Files\Media Cybernetics\Image-Pro 11\MediaCy.IQL.Application.dll</HintPath>
        </Reference>




    -- 2 --


        Private Sub BackgroundWorker1_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork

            Debug.Print("-- BackgroundWorker1_DoWork -- START --")

            '_session = New Session("Image-Pro 10.0 64-bit", 60)
            '_session = New Session("Image-Pro 11.1 64-bit", 60)

            Try
                _session = New Session("Image-Pro 11.1 64-bit", 60)
            Catch ex As Exception
                Debug.Print("---- Exception Message: " & ex.Message)
                Debug.Print("---- Exception Message: " & ex.Message)
                Debug.Print("---- Stack Trace: " & ex.StackTrace)
                Debug.Print("---- Source: " & ex.Source)
            End Try

            Debug.Print("-- BackgroundWorker1_DoWork -- END --")

        End Sub


    -- 3 --

    MediaCy.Automation.Samples.VBClient + MMB\Compile Output\Automation












Sign In or Register to comment.