DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Is it possible to call DIAdem from an external Python script?

Hello,

I was wondering if it is possible to call DIAdem and access the Application object from an externally launched python script.

 

Here's what I have tried so far:

import sys
import os

sys.path.append(R"C:\Program Files\National Instruments\DIAdem 2021")
os.add_dll_directory(R"C:\Program Files\National Instruments\DIAdem 2021")

import DIAdem

Simply appending the installation directory to sys.path is enougth to find the DIAdem module but throws a

FileNotFoundError: Could not find module 'GfSGPI.dll'

Adding the dll directory gets one line further, but then causes an acces violation:

Traceback (most recent call last):
  File "c:\_WIP_\DIAdem test\call_dd.py", line 7, in <module>
    import DIAdem
  File "C:\Program Files\National Instruments\DIAdem 2021\DIAdem.py", line 203, in <module>
    vp=GPI.TOCMDGet()
OSError: exception: access violation reading 0x0000000000000010

 

Now I was figuring, before I go poking around with dlls and ctypes I should ask if this use case is even possible / supported.

Or are Python scripts only supported when launched from within DIAdem?

0 Kudos
Message 1 of 8
(2,566 Views)

Hi maflAut, 

 

Just want to give a try on this.

Have you tried to first open DIAdem using Python?

 

I used the subprocess to open DIAdem. 

 

import subprocess
subprocess.Popen([r"C:\Program Files\National Instruments\DIAdem 2021\DIadem.exe"])​

This works. 
Then, the next logic is to check if the DIAdem is already running. 
If its already running, perhaps you can add the some Python code to access the Application object.
This is the idea I had but it worth trying out and see if it works. 

 

 

 

0 Kudos
Message 2 of 8
(2,430 Views)

Hello guserwin91,

thanks for the tip.

Unfortunately it doesn't seem to make a difference if the the application is running or not.

 

I also tried running the script with the Python distribution that is shipping with Diadem as well as with the official Python disttribution.

This doesn't make a difference either.

0 Kudos
Message 3 of 8
(2,413 Views)

Hi maflAut,

 

Can you show where can I find this script with the Python distribution that is shipping with Diadem as well so I can try to give a test? 

 

Regards

 

0 Kudos
Message 4 of 8
(2,406 Views)

You can find the included distribution in C:\Program Files\National Instruments\Shared\Skyline\Python.

0 Kudos
Message 5 of 8
(2,374 Views)

did anyone find a solution?

0 Kudos
Message 6 of 8
(1,858 Views)

Unfortunately no, but I got confirmation from official support, that this use case is not supported.

0 Kudos
Message 7 of 8
(1,852 Views)

Hello 

 

I had same problem with "Application" object when i tryed to implement this VBS Script in Python. 

After copule of weeks of try and error and with help of  some luck,  I manage to get my Python script  work.

 

Long story short... 

I've got working "Application" object  in external Python script by using: 

self.DIAdemApp=win32com.client.dynamic.Dispatch("DIAdem.TOCmd") 

insted of: 

Call oDIAdem.VariantVarget("Application",DIAdemApp)

 in VBS script example. 

Rest of Python script was rewriten as  one to one from example,  using comtypes library, using 'comtypes.client.CreateObject' to create 'TOCommand' object.

 

Hope this will help 

 

P.S

I was using Diadem 2021 and Python 3.8.6 

0 Kudos
Message 8 of 8
(1,742 Views)