CadFrank Posted September 15, 2016 Share Posted September 15, 2016 Hello, I'm using AutoCAD 2011. I'm trying to close Drawing1.dwg when I open and existing drawing. I've come up with this code but it's sending me an error : (setq acadobject (vlax-get-Acad-Object)) (setq documentcollection (vla-get-documents acadobject)) (vlax-for <doc> documentcollection (if (eq (getvar 'dwgname) "Drawing1.dwg") (vla-close (vla-item <doc> "Drawing1.dwg") :vlax-False) ) ) Help me please Quote Link to comment Share on other sites More sharing options...
ReMark Posted September 15, 2016 Share Posted September 15, 2016 (edited) Why not just kill off Drawing1 altogether via the STARTUP system variable? Startup options are: 0 - Displays the Select Template dialog box, or uses a default drawing template file set in the Options dialog box, on the Files tab. 1 - Starts without opening a drawing template file, and displays the Startup or the Create New Drawing dialog box. 2 - Starts without opening a drawing template file. If available in the application a custom dialog box is displayed. Edited September 15, 2016 by ReMark Quote Link to comment Share on other sites More sharing options...
CadFrank Posted September 15, 2016 Author Share Posted September 15, 2016 Well I tried that and it still pops up the drawing1.dwg for some reason The problem is when I open a drawing that is already created the drawing1.dwg keeps opening Quote Link to comment Share on other sites More sharing options...
BlackBox Posted September 15, 2016 Share Posted September 15, 2016 Curious that the sysvar isn't working for you. In any event, you cannot invoke the Close() Method on a Document if it is the ActiveDocument, without raising an 'error: Automation Error. Drawing is busy'... You can switch to another document, and subsequently Close() Drawing1 (which has some implicit tasks if being done programmatically before you attempt to Close() Drawing1). Slight mod to your original code: (vlax-for doc (vla-get-documents (vlax-get-acad-object)) (if (= (vla-get-name doc) "Drawing1.dwg") (vla-close doc :vlax-False) ) ) Now, *IF* you have VBA installed, you can call this, as mentioned in this thread: (command "VBASTMT" (strcat "AutoCAD.Application.Documents.Item(\"Drawing1.dwg\").Close")) HTH Quote Link to comment Share on other sites More sharing options...
ronsingh78 Posted September 15, 2016 Share Posted September 15, 2016 (vla-close (vla-item (vla-get-documents (vlax-get-acad-object)) "Drawing1.dwg") :vlax-false "Drawing1.dwg") pass the lisp code form other drawing (not drawing1.dwg, else you will get drawing busy error) Quote Link to comment Share on other sites More sharing options...
CadFrank Posted September 15, 2016 Author Share Posted September 15, 2016 Thanks alot guys, I'll see what I can make of your incites. Regards. Quote Link to comment Share on other sites More sharing options...
StevJ Posted September 15, 2016 Share Posted September 15, 2016 I use this in my acaddoc.lsp file: (if (= (Getvar "Dwgname") "Drawing1.dwg")(command "close" "Y")) Steve Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.