Jump to content

Close Drawing1.dwg


CadFrank

Recommended Posts

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 :ouch:

Link to comment
Share on other sites

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 by ReMark
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

(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)

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...