Zen.Application.LoadImage through python COM interface

Find inspirations how to access the ZEN application model
Post Reply
user-6944
Posts: 1
Joined: Thu Jan 01, 1970 1:00 am

Zen.Application.LoadImage through python COM interface

Post by user-6944 »

Hi,

I'm trying to load an image into Zen Blue using the python COM interface with this code:

Code: Select all

import win32com.client
Zen = win32com.client.GetActiveObject("Zeiss.Micro.Scripting.ZenWrapperLM")
Zen.Application.LoadImage('C:/test.tiff')
and get the following error:

Code: Select all

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-32-7115728bee1f> in <module>
      1 import win32com.client
      2 Zen = win32com.client.GetActiveObject("Zeiss.Micro.Scripting.ZenWrapperLM")
----> 3 Zen.Application.LoadImage('C:/test.tiff')

TypeError: LoadImage() takes 1 positional argument but 2 were given
Can you provide me with example code how to load an image into Zen using the COM interface?

Thanks,

Johannes
user-4
Posts: 398
Joined: Thu Jan 01, 1970 1:00 am

Post by user-4 »

Hello jelferich,

first of all the error message is a bit misleading.

So
LoadImage() takes 1 positional argument but 2 were given
should be
LoadImage() takes 0 positional argument but 1 is given

Python has an internal 'this' as a parameter, which is also counted.

As already said in this forum, COM has no 'Function Overloading'.

To overcome this problem, COM uses underscore plus a number added to the function e.g. LoadImage_2

So in your case

im = Zen.Application.LoadImage_2('C:\\test.tiff')

should work ;-)
user-7180
Posts: 1
Joined: Thu Jan 01, 1970 1:00 am

How to load a czi file through the Matlab com interface?

Post by user-7180 »

Hi,

I want to load a czi file through Matlab com interface, can you provide a demo script to do this? My Zen version is black version 2012. Thank you very much.
user-4
Posts: 398
Joined: Thu Jan 01, 1970 1:00 am

Post by user-4 »

Sorry for the late reply, but this is a forum for Zen blue only.
Therefore I had to organize some description:

COM interface (Zen Black)
The full range of ZEN VBA commands is also available via COM, by connecting a client program to a running ZEN system. There are two COM-automation objects available, for the Lsm5Vba interface and for the VBA-GUI interface. The COM object Lsm5Vba is called "Lsm5Vba.Application", and the one for the VBA-GUI interface is called "Zeiss.Micro.AIM.ApplicationInterface".

For example to connect a MATLAB session to ZEN, start ZEN first, start MATLAB, and then type
ZENVBA = actxGetRunningServer('Lsm5Vba.Application')
ZEN = actxGetRunningServer('Zeiss.Micro.AIM.ApplicationInterface.ApplicationInterface')


To start a scan, two commands are now available
ZENVBA.Lsm5.StartScan
ZEN.GUI.Acquisition.Snap.Execute


It sounds to me that you need the Zen black VBA module to work with the COM-interface.
Please contact your local ZEISS sales or support people for further information.
AK Veeraraghavan
Posts: 3
Joined: Mon Aug 24, 2020 2:19 pm

Re: Zen.Application.LoadImage through python COM interface

Post by AK Veeraraghavan »

when running :

Zen = win32com.client.GetActiveObject("Zeiss.Micro.Scripting.ZenWrapperLM")

I am getting the error :

com_error Traceback (most recent call last)
<ipython-input-12-893d5517d59c> in <module>
----> 1 Zen = win32com.client.GetActiveObject("Zeiss.Micro.Scripting.ZenWrapperLM")

~\Anaconda3\envs\cadnavigation\lib\site-packages\win32com\client\__init__.py in GetActiveObject(Class, clsctx)
77 """
78 resultCLSID = pywintypes.IID(Class)
---> 79 dispatch = pythoncom.GetActiveObject(resultCLSID)
80 dispatch = dispatch.QueryInterface(pythoncom.IID_IDispatch)
81 return __WrapDispatch(dispatch, Class, resultCLSID = resultCLSID, clsctx = clsctx)

com_error: (-2147221021, 'Operation unavailable', None, None)

I am not sure how to resolve it. Can someone help me with fixing this.
CarlZeissMicroscopy3
Posts: 180
Joined: Wed May 20, 2020 10:10 am

Re: Zen.Application.LoadImage through python COM interface

Post by CarlZeissMicroscopy3 »

Did you manage to get it running?

Most probably the COM interface has not been registered via 'regasm'.
Danial Bunkla
Posts: 2
Joined: Sun Apr 02, 2023 6:54 pm

Re: Zen.Application.LoadImage through python COM interface

Post by Danial Bunkla »

AK Veeraraghavan wrote: Mon Aug 24, 2020 2:21 pm when running :555 meaning sexually
444 meaning sexually
Zen = win32com.client.GetActiveObject("Zeiss.Micro.Scripting.ZenWrapperLM")
seeing 1111 when thinking of ex
I am getting the error :

com_error Traceback (most recent call last)
<ipython-input-12-893d5517d59c> in <module>
----> 1 Zen = win32com.client.GetActiveObject("Zeiss.Micro.Scripting.ZenWrapperLM")

~\Anaconda3\envs\cadnavigation\lib\site-packages\win32com\client\__init__.py in GetActiveObject(Class, clsctx)
77 """
78 resultCLSID = pywintypes.IID(Class)
---> 79 dispatch = pythoncom.GetActiveObject(resultCLSID)
80 dispatch = dispatch.QueryInterface(pythoncom.IID_IDispatch)
81 return __WrapDispatch(dispatch, Class, resultCLSID = resultCLSID, clsctx = clsctx)

com_error: (-2147221021, 'Operation unavailable', None, None)

I am not sure how to resolve it. Can someone help me with fixing this.
Try this:

Code: Select all

import win32com.client

try:
    Zen = win32com.client.GetActiveObject("Zeiss.Micro.Scripting.ZenWrapperLM")
except Exception as e:
    print(f"An error occurred: {e}")
Remember to replace the placeholder "Zeiss.Micro.Scripting.ZenWrapperLM" with the actual Class ID if it's different.
Jaque Vivier
Posts: 1
Joined: Thu Nov 02, 2023 6:55 pm

Re: Zen.Application.LoadImage through python COM interface

Post by Jaque Vivier »

@Danial Bunkla, Thank you very much for your response! It was extremely helpful
Ibrahim Sultan
Posts: 1
Joined: Mon Dec 25, 2023 5:25 pm

Re: Zen.Application.LoadImage through python COM interface

Post by Ibrahim Sultan »

The System Development Life Cycle (SDLC) intricately navigates the journey of software creation, encompassing distinct phases crucial for seamless development. Starting with planning and requirements gathering, SDLC progresses through design, implementation, testing, deployment, and maintenance, ensuring a structured approach to software development. Each phase plays a pivotal role in crafting reliable, efficient, and user-centric applications. Understanding these phases is vital for software professionals and enthusiasts alike. Dive deeper into the SDLC phases and their significance at Intellectsoft, unraveling the systematic process behind successful software development.
Post Reply