[python-win32] question about pywin32 and COM event again

wccppp wccppp at gmail.com
Fri Dec 9 19:11:40 CET 2005


Hello,

I'm learning to use python to automate AutoCAD and I was able to catch the
AutoCAD application event using the code below.  But I don't know if I can
catch the event from the active document (or drawing) or not.  The
AutoCAD.Application has a property of "ActiveDocument" which is the active
drawing opened.  The document has an event "BeginClose" which is what I'm
after.  I'd like to do some clean up before the drawing is closed.  Can
anyone give me guide?  Thank you very much!

import win32com.client
class ACADEvents:
    def OnEndOpen(self, fName):
        print "Drawing " + str(fName) + " opened..."
    def OnEndSave(self, fName):
        print "Drawing " + str(fName) + " saved..."
    def OnBeginCommand(self, cmdName):
        print "Beginning command " + str(cmdName) + "..."

acad = win32com.client.DispatchWithEvents("AutoCAD.Application", ACADEvents)
acad.WindowState = 3
acad.Visible = 1
dwgName = r"C:\AutoCAD\DWG\1.dwg"
doc = acad.Documents.Open(dwgName)
doc.Layers("0").LayerOn = False
doc.Save()
doc.Close()

--

Regards,
- wcc
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-win32/attachments/20051209/346ef979/attachment.htm


More information about the Python-win32 mailing list