pywin32 Illustrator Throwing Exception Error - matthewsjc1 - Aug-26-2021
I'm trying to use pywin32 to access Adobe Illustrator through COM. I'm able to access other apps like Photoshop and Excel fine, but no matter how I try to access Illustrator, it always throws the exception: (-2147221005, 'Invalid class string', None, None).
The code:
import win32com.client as win32com
illApp = win32com.Dispatch("Illustrator.Application")
I can use the same code with other COM apps and it works fine. Does anyone have any suggestions?
Thank you!
*PS This is my first post in this forum. I'm a long-time programmer (C/C++, .Net, etc) and recently started using Python for some projects at work. So far, I'm really liking it!
RE: pywin32 Illustrator Throwing Exception Error - Larz60+ - Aug-26-2021
Please show entire, unaltered error traceback . Please use bbcode error tag.
Use tags around code as well.
RE: pywin32 Illustrator Throwing Exception Error - matthewsjc1 - Aug-26-2021
(Aug-26-2021, 01:47 PM)Larz60+ Wrote: Please show entire, unaltered error traceback . Please use bbcode error tag.
Use tags around code as well.
import win32com.client as win32com
illApp = win32com.Dispatch("Illustrator.Application") Error: Message=(-2147221005, 'Invalid class string', None, None)
Source=C:\Users\jaredm\Desktop\Python COM Test\Python_COM_Test.py
StackTrace:
File "C:\Users\jaredm\Desktop\Python COM Test\Python_COM_Test.py", line 3, in <module>
illApp = win32com.Dispatch("Illustrator.Application")
I hope I did this right. I'm using VS2019 with Python 3.7.8
RE: pywin32 Illustrator Throwing Exception Error - matthewsjc1 - Aug-26-2021
I'm sorry. I'm new to this. I misunderstood what you meant. I ran trackback.print_tb() and got:
Error: ]Traceback (most recent call last):
File "C:\Users\jaredm\AppData\Local\Programs\Python\Python37\lib\site-packages\win32com\client\dynamic.py", line 81, 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\jaredm\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:\Users\jaredm\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "c:\program files (x86)\microsoft visual studio\2019\community\common7\ide\extensions\microsoft\python\core\debugpy\__main__.py", line 45, in <module>
cli.main()
File "c:\program files (x86)\microsoft visual studio\2019\community\common7\ide\extensions\microsoft\python\core\debugpy/..\debugpy\server\cli.py", line 430, in main
run()
File "c:\program files (x86)\microsoft visual studio\2019\community\common7\ide\extensions\microsoft\python\core\debugpy/..\debugpy\server\cli.py", line 267, in run_file
runpy.run_path(options.target, run_name=compat.force_str("__main__"))
File "C:\Users\jaredm\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 263, in run_path
pkg_name=pkg_name, script_name=fname)
File "C:\Users\jaredm\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "C:\Users\jaredm\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\jaredm\Desktop\Python COM Test\Python_COM_Test.py", line 3, in <module>
illApp = win32com.Dispatch("Illustrator.Application")
File "C:\Users\jaredm\AppData\Local\Programs\Python\Python37\lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch
dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
File "C:\Users\jaredm\AppData\Local\Programs\Python\Python37\lib\site-packages\win32com\client\dynamic.py", line 98, in _GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File "C:\Users\jaredm\AppData\Local\Programs\Python\Python37\lib\site-packages\win32com\client\dynamic.py", line 83, in _GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
pywintypes.com_error: (-2147221005, 'Invalid class string', None, None)
RE: pywin32 Illustrator Throwing Exception Error - matthewsjc1 - Aug-26-2021
Is this what you were asking for Larz60+?
RE: pywin32 Illustrator Throwing Exception Error - Larz60+ - Aug-26-2021
For the error, yes.
But there's more code?
Please read: https://python-forum.io/misc.php?action=help&hid=19
RE: pywin32 Illustrator Throwing Exception Error - matthewsjc1 - Aug-26-2021
I actually figured out the issue! Illustrator's installation was either corrupt or that version (24.0.2) doesn't register its COM correctly. I installed a copy of the newest version and everything works perfectly.
Thanks,
Jared
RE: pywin32 Illustrator Throwing Exception Error - Larz60+ - Aug-27-2021
Glad you solved the issue, thanks for sharing solution.
|