NI multisim COM interface not accessible - python

I am trying to open and run a multisim simulation from python using the multisim COM interface.
from research I understand multisim has a COM interface that can be accessed from any other program using any language.
here's an example of it working (partially) with MATLAB
however, I cannot get it to work with python. when I try to open the API I get an error.
here's the Python code, I am using the win32com module:
import win32com.client as win
win.Dispatch("MultisimInterface.MultisimApp")
however, I get a "class not registered" error. the full message is:
Traceback (most recent call last):
File "C:\Users\mizra\AppData\Local\Programs\Python\Python39\lib\site-packages\win32com\client\dynamic.py", line 86, in _GetGoodDispatch
IDispatch = pythoncom.connect(IDispatch)
pywintypes.com_error: (-2147221021, 'Operation unavailable', None, None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
win.Dispatch("MultisimInterface.MultisimApp")
File "C:\Users\mizra\AppData\Local\Programs\Python\Python39\lib\site-packages\win32com\client\__init__.py", line 117, in Dispatch
dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch, userName, clsctx)
File "C:\Users\mizra\AppData\Local\Programs\Python\Python39\lib\site-packages\win32com\client\dynamic.py", line 106, in _GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File "C:\Users\mizra\AppData\Local\Programs\Python\Python39\lib\site-packages\win32com\client\dynamic.py", line 88, in _GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(
pywintypes.com_error: (-2147221164, 'Class not registered', None, None)
It appears for some reason multisim is not opening its API. I have tested the code and tried to open LABVIEW and Excel using the same code and it worked, so I don't know why it doesn't work with multisim.
is there a way to see which interfaces are registered and can be accessed on a given time? will it work better using another language? am I missing something on a much more basic level?
I would appreciate any help. thanks in advance

Related

win32com.client.Dispatch("Photoshop.Application") not working. win32com doesn't detect the installed Photoshop when it runs

When I try to run a script that opens up Adobe Photoshop 2022, I'm met with following errors:
Traceback (most recent call last):
File "C:\Users\XXXXX\AppData\Local\Programs\Python\Python37-32\lib\site-packages\win32com\client\dynamic.py", line 86, in _GetGoodDispatch
IDispatch = pythoncom.connect(IDispatch)
pywintypes.com_error: (-2147221005, 'Invalid class string', None, None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\XXXXX\XXXXX\XXXXX\XXXXX\Python\Autophoto\Autophoto.py", line 39, in <module>
psApp = win32com.client.Dispatch("Photoshop.Application")
File "C:\Users\XXXXX\AppData\Local\Programs\Python\Python37-32\lib\site-packages\win32com\client\__init__.py", line 117, in Dispatch
dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch, userName, clsctx)
File "C:\Users\XXXXX\AppData\Local\Programs\Python\Python37-32\lib\site-packages\win32com\client\dynamic.py", line 106, in _GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File "C:\Users\XXXXX\AppData\Local\Programs\Python\Python37-32\lib\site-packages\win32com\client\dynamic.py", line 89, in _GetGoodDispatch
IDispatch, None, clsctx, pythoncom.IID_IDispatch
pywintypes.com_error: (-2147221005, 'Invalid class string', None, None)
The win32com.client.Dispatch("Photoshop.Application") call used to work when an older version of Photoshop was installed, but since I've updated it to the latest version, the code no longer seems to work.
I've tried using the win32com tool to list all COM interfaces but this program seems to crash after a few seconds every time.
Any tips?
(The code is accessible via following link: https://github.com/samualon/Autophoto)

Exporting PPTx to PDF (issue using win32com or comtypes)

I'm having trouble executing part of a python (converting a PPTx to PDF, either with win32com or with comtypes):
obj = win32com.client.Dispatch('Powerpoint.Application')
obj.Visible = 1
doc = obj.Presentations.Open(file_name_ptx)
doc.SaveAs(file_name_pdf, FileFormat=32)
The python works perfectly if I run it from CMD, or even within sublime or equivalent. It also works if I run it through a window scheduled task.
However, it fails if it is run through another script, for example from another subprocessed python (either with POpen or with Run) or from php (using cmd_exe).
It also fails if that script is executed through a "remote" request (from another PC).
The failure always occurs in the same place, the script is not able to open the PPTx application:
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\win32com\client\dynamic.py", line 81, in _GetGoodDispatch
IDispatch = pythoncom.connect(IDispatch)
pywintypes.com_error: (-2147221021, 'Operacixf3n no disponible', None, None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "*******.PY", line 706, in
obj = win32com.client.Dispatch('Powerpoint.Application')
File "C:\ProgramData\Anaconda3\lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch
dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
File "C:\ProgramData\Anaconda3\lib\site-packages\win32com\client\dynamic.py", line 98, in _GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File "C:\ProgramData\Anaconda3\lib\site-packages\win32com\client\dynamic.py", line 83, in _GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
pywintypes.com_error: (-2147023584, 'Una sesixf3n de inicio especificada no existe. Es posible que haya finalizado.', None, None)
I have been looking for various solutions, I have tried with different modules, I have even tried to create a PowerShell file that converts PowerPoint to PDF and the exact same thing happens, if I run the PS1 from CMD it works perfectly, but if I run it remotely or through from another script, it fails for the exact same reason, it is unable to open an instance of PowerPoint.
I have also tried, remotely, to first activate the windows GUI (deactivate the user lock screen and access as if it were a real person) and then execute any script (PY, PS1, etc.), but still with the desktop properly open and without user lock screen the script fails at exactly the same point.
Would anyone know what the problem is and how to solve it?
Thank you.

Outlook Redemption 1st Step Problems

I am trying to work with Outlook Redemption using Python. Currently I am hitting an error just trying to get things working.
import win32com.client
session = win32com.client.Dispatch("Redemption.RDOSession")
However, I am getting this error.
Traceback (most recent call last):
File "Test.py", line 3, in <module>
session = win32com.client.Dispatch("Redemption.RDOSession")
File "C:\Python27\lib\site-packages\win32com\client\__init__.py", line 95, in
Dispatch
dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,c
lsctx)
File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 114, in
_GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 91, in _
GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.II
D_IDispatch)
pywintypes.com_error: (-2147221233, 'OLE error 0x8004010f', None, None)
I am pretty sure that I have Redemption installed correctly, along with MAPI, and the win32com package for python. I've double checked all three of their installations and nothing has changed.
I currently do not have Outlook or Exchange installed on this computer. Could this be the issue?
Has anyone else hit this error before?
The error is MAPI_E_NOT_FOUND. Most likely that means the MAPI system (Outlook) is not installed, or that it is of a wrong bitness different from that of your app.
What is the bitness of your app, Windows, and Outlook? Does the follwing apply? http://www.dimastr.com/redemption/faq.htm#ErrorCreatingRedemptionObject

win32com.client.Dispatch("Outlook.Application") error pywintypes.com_error: (-2147221005, 'Invalid class string', None, None)

I am on windows 7 and I have windows live installed.
Now when I am trying to run following code
import win32com.client
win32com.client.Dispatch("Outlook.Application")
I am getting following error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\win32com\client\__init__.py", line 95, in
Dispatch
dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,c
lsctx)
File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 108, in
_GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 85, in _
GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.II
D_IDispatch)
pywintypes.com_error: (-2147221005, 'Invalid class string', None, None)
I have another machine with windows xp and Outlook installed.
I ran the same code and I got the same error.
One more question.
How can I get the com of windows live on windows 7?
Any suggestions and comments will be appreciated.
This is an indication that Outlook is not installed. "windows live" or "outlook.com" would not help you.
I was having a similar error. Have you tried running makepy.py from win32com's folder to create entries for the different COMobject's you are using? Basically, win32com just treats all of applications you interact with as default COMobjects until you let it learn about the programs installed on your computer. You'll have to run makepy.py for each program you want to control with it.
After I ran it, I gained access to much more control for Outlook. It has opened other errors that I am working on correcting.
Also, if you take your comobject (comboject = win32com.client.Dispatch("Outlook.Application")) and look at comboject._prop_map_get_.keys() you'll see all the things you can use for that program.

Python / ADOX: 'The specified module could not be found.' (win32 extensions)

I'm running pywin32 for python 2.5.
I'm following the instructions for python ADO given at http://www.ecp.cc/pyado.html.
Creating an ADODB.Recordset object works fine. But when I try to create an ADOX.Catalog object I get an error:
>>> cat=win32com.client.Dispatch(r'ADOX.Catalog')
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "C:\Python25\lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch
dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
File "C:\Python25\lib\site-packages\win32com\client\dynamic.py", line 98, in _GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File "C:\Python25\lib\site-packages\win32com\client\dynamic.py", line 78, in _GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
com_error: (-2147024770, 'The specified module could not be found.', None, None)
Any ideas what I might be missing?
Solution: even though ADOX was showing up in the COM browser as an available library, it wasn't "registered" properly. Following the instructions here, I executed the following at the Start->Run prompt:
regsvr32 "C:\Program Files\Common Files\System\ado\msadox.dll"
Note that this is on a WinXP SP2 machine. I guess the registry had become corrupt somehow? In any case, I'm new to Windows programming so my explanation may be off, but maybe the fix will help someone.

Categories

Resources