New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple instances of Autocad #520
Comments
I now found the following: https://stackoverflow.com/questions/63562678/how-to-reference-the-com-objects-of-all-the-running-excel-application-instances |
Upon examining the C# code, moniker seems to be relevant. Here are the relevant code snippets:
However, as I am not well-versed in C#, I hope that those who proficient in both Python and C# provide further insights. |
Unfortunately, I have no ideas what I'm trying now to rewrite the following code from here from pywin32 to comtypes: from pythoncom import (
CreateBindCtx as create_bind_context_com_interface,
IID_IDispatch as dispatch_com_interface_iid,
GetRunningObjectTable as get_running_object_table_com_interface,
)
from win32com.client import (
Dispatch as dispatch,
)
def get_excel_instances():
'''
Returns a list of the running Microsoft Excel application
instances as component object model (COM) objects.
'''
running_object_table_com_interface = get_running_object_table_com_interface()
bind_context_com_interface = create_bind_context_com_interface()
excel_application_class_clsid = '{00024500-0000-0000-C000-000000000046}'
excel_application_clsid = '{000208D5-0000-0000-C000-000000000046}'
excel_instance_com_objects = []
for moniker_com_interface in running_object_table_com_interface:
display_name = moniker_com_interface.GetDisplayName(bind_context_com_interface, None)
if excel_application_class_clsid not in display_name:
continue
unknown_com_interface = running_object_table_com_interface.GetObject(moniker_com_interface)
dispatch_com_interface = unknown_com_interface.QueryInterface(dispatch_com_interface_iid)
dispatch_clsid = str(object=dispatch_com_interface.GetTypeInfo().GetTypeAttr().iid)
if dispatch_clsid != excel_application_clsid:
continue
excel_instance_com_object = dispatch(dispatch=dispatch_com_interface)
excel_instance_com_objects.append(excel_instance_com_object)
return excel_instance_com_objects
excel_instances = get_excel_instances()
input() My code: import ctypes
get_running_object_table = ctypes.oledll.ole32.GetRunningObjectTable Now I need to pass 2 parameters to |
The By referring to this, it should be possible to define a subclass that inherits from Moreover, when searching GitHub with |
Is there an update on this issue? |
Sorry, your last answer was still difficult for me. A few days ago I found this article how to use ctypes to work with Win32 API. After this excellent article, I have a much better understanding of your answer. Now I decided to learn a basics of C programming language, because I still have a poor C knowledge to use ctypes and comtypes efficiently. I steel not sure how to model As for now using this answer from StackOverflow is the best way to solve this problem, so we can close this issue. Alternatively, you could create a function in comtypes that finds all instances. Anyway, it's interesting topic how to solve this using ctypes/comtypes and I hope I'll be able to do this in the future. |
Your attempt is wonderful. I'm not familiar with C language either, and these are unknown territories for me. If you could write a description of the usecase and tests, I can make resources to review your PR. For sharing difficulties and technical consultations, I think we should keep this issue open. |
Hello!
I know, that if Autocad is already running, we can use
comtypes.client.GetActiveObject
:But what to do, if multiple instances of Autocad is running?
I found the code to solve this issue, but it's in C#:
I know it's possible to translate the C# code above to Python, but I don't know C# to do so. Anybody know it to translate, please?
The text was updated successfully, but these errors were encountered: