Jump to content

Close a drawing through a LISP


Steven P

Recommended Posts

Good afternoon,

I have been 'upgraded' to include linking my AutoCAD to projectwise (Document management database / software if you don't use it). Every time you close a drawing it will check projectwise to see if it was opened through it - if so I get options to check the drawing check in and so on, if not AutoCAD acts normaly.

 

I have a LISP routine that will batch process other lisp routnes (not perfect but it sort of works) and projectwise is causing an unhadled access error when this LISP routine tries to close a drawing (my routine opens, process, saves as required and closes each drawing in turn)

 

I am using a standard 'close' command - is there another method to close a drawing in a LISP routine that projectwise won't recognise as being 'close', I tried VLA-CLOSE, but couldn't get that to work, unless I am doing something wrong.

 

Many thanks

 

 

 

 

(note my code isn't tidy so I am reluctant to post it here - it wold take you far longer than it should to read it I think till I have made it nce, but will post parts f it if necessary)

Link to comment
Share on other sites

I tried VLA-CLOSE, but couldn't get that to work, unless I am doing something wrong.
Usually if you do something wrong, it doesn't work, it comes in pair ;P

(vla-Close (vla-get-ActiveDocument (vlax-get-acad-object)) :vlax-false);save changes flag

 

I am using a standard 'close' command - is there another method to close a drawing in a LISP routine that projectwise won't recognise as being 'close'

project wise won't recognize as being close? I'm not sure what you mean by that, but one thing you have to note is that the lisp "lives" in a drawing, and if you close the drawing in which the lisp is running, the execution stops right away, literally. It is like sawing a branch you are sitting on. If you do it on the incorrect side, the job gets done, but there are side effects. You cannot continue afterward, no matter what, I'm pretty sure local variables don't go out of scope and garbage collection won't do its job, and some Acad's variables/flags don't get resetted properly. Few years ago I made a routine to close a drawing and reopen it in read only, so I could open dwg readonly by double clicking in explorer to avoid having to manually browse from Acads open dialog and if I used it 32 times in a cad session I ended up having to close cad, as it gave a popup telling that I could not open more that 32 drawings simultaneously in a session. For cad it was as if the dwgs were never closed, no matter the method used (command, vl-cmdf, command-s, vla-close, vla-sendcommand, vla-quit...

 

Closing the containing lisp file execution is not a 100% watertight perfectly working solution. Don't expect that to run endlessly/in a batch.

Link to comment
Share on other sites

directors cut from my rlxbatch appie :

 

 

;--- Close ---------------------------------------------- Begin Close Utilities ------------------------------------------------- Close ---

(defun RlxBatch_CloseAllButCurrent (/ dwg )
 (vlax-for dwg (vla-get-Documents (vlax-get-acad-object))
   (if    (= (vla-get-Active dwg) :vlax-False)
     (if (= (vla-get-ReadOnly dwg) :vlax-true)
   (vla-close dwg :vlax-False)
   (vl-catch-all-apply (function (lambda ()(if (/= (getvar "dwgtitled") 0)(vla-save dwg))(vla-close dwg :vlax-False))))
     )
   )
 )
)

(defun quit_all ( / dwg)
(vlax-for dwg (vla-get-Documents (vlax-get-acad-object)) (if (= (vla-get-active dwg) :vlax-false)(vla-close dwg :vlax-false)))
(command-s "._close" "_y")
)

(defun close_all ( / dwg ) (vlax-for dwg (vla-get-Documents (vlax-get-acad-object))(vla-close dwg :vlax-True)))

;--- Close ----------------------------------------------- End Close Utilities -------------------------------------------------- Close ---

Link to comment
Share on other sites

Thanks so far, I still can't get it to work this morning so will have another look at everything going on before this, and if its OK will ask more questions later?

Link to comment
Share on other sites

Thanks so far, I still can't get it to work this morning so will have another look at everything going on before this, and if its OK will ask more questions later?

I'm wondering how/what exactly Project wise monitors autocad... and my guess is that no matters the method used (command, vl-cmdf, command-s, vla-close, vla-sendcommand, vla-quit it still is as if the dwgs were never closed. The only achievable way would be to do "just" everything up to the save in lisp, and invite the user to close the drawing himself. Feel free to keep us posted if you find something new.

Link to comment
Share on other sites

  • 2 weeks later...

Thanks Jef, I hadn't tried command-s but that sort of works (why that does and not the other options, I have no idea but it worked)

(as for the rest of my routine, it opens the drawings one after another, performs whatever needs to be done, then closes them all when they're all been modified - think that's just my code I need to alter)

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...