Defining Events for AutoCad Document Objects

Defining Events for AutoCad Document Objects

Anonymous
Not applicable
729 Views
1 Reply
Message 1 of 2

Defining Events for AutoCad Document Objects

Anonymous
Not applicable

I am building an Interface to AutoCad using Python 3.9 with comtypes.py and have difficulty defining the events for a Document. Using ShowEvents for the AutoCad.Application is no problem, but doing the same for an activeDocument runs into problems, since there is no CLSID for the Document.

I have tried the following:

 

appObj = ctc.GetActiveObject('AutoCad.Application')
con = ctc.ShowEvents(appObj, interface=None)

# event found: _DAcadApplicationEvents_SysVarChanged
# event found: _DAcadApplicationEvents_NewDrawing
# ...
# event found: _DAcadApplicationEvents_LispCancelled
# event found: _DAcadApplicationEvents_WindowChanged

 

This works well and lists the event types as expected. But now I need to get the events for

the active Document. So I get the Object:

 

doc = appObj.ActiveDocument
con = ctc.ShowEvents(doc, interface=None)

# TypeError: cannot determine source interface

 

It is not an;e to find the Source Interface as it did with the Application.

I can try to define an interface, but the only one that is accepted is IDispatch

 

docItf = doc.QueryInterface(cta.IDispatch)
con = ctc.ShowEvents(doc, interface=docItf)
# AttributeError: 'POINTER(IDispatch)' object has no attribute '__mro__'

 

This means that it cannot find a proper Interface on an Instance of an object. It needs a Class.

But the only CLSID that is available is for the Application Class. I have tried using other GUIDs without success.

So my question is, how can I get the Events for a Document object or a ModelSpace object or other AutoCad objects? For C# there are many functions, but there does not seem to be an equivalent for Python.

 

Can somebody shed some light on this, please?

0 Likes
Accepted solutions (1)
730 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable
Accepted solution

By following the code in comtypes.py, I was able to find out how to do this and so answered my own question.

0 Likes