Hello,<br><br>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!
<br><br>import win32com.client<br>class ACADEvents:<br> def OnEndOpen(self, fName):<br> print "Drawing " + str(fName) + " opened..."<br> def OnEndSave(self, fName):<br> print "Drawing " + str(fName) + " saved..."
<br> def OnBeginCommand(self, cmdName):<br> print "Beginning command " + str(cmdName) + "..."<br><br>acad = win32com.client.DispatchWithEvents("AutoCAD.Application", ACADEvents)<br>
acad.WindowState = 3<br>acad.Visible = 1<br>dwgName = r"C:\AutoCAD\DWG\1.dwg"<br>doc = acad.Documents.Open(dwgName)<br>doc.Layers("0").LayerOn = False<br>doc.Save()<br>doc.Close()<br><br>-- <br><br>Regards,
<br>- wcc<br><br>