TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: GDF on July 13, 2009, 11:12:40 AM
-
I have this function in my next and previous drawing routine. The problem is that it is buggy and doesnot always work, thus locking up AutoCAD. Anybody have any ideas?
;;;Here is another one that will close all open documents except the current one.
;;;by Peter Jamtgaard
(defun ARCH:Close_All (/ DOCOBJ FULL)
(vl-load-com)
(vlax-for
DOCOBJ (vla-get-documents (vlax-get-acad-object))
(setq FULL (strcat (vla-get-path DOCOBJ) "\\" (vla-get-name DOCOBJ)))
(if (= (vla-get-active DOCOBJ) :vlax-false)
(if (vl-catch-all-error-p
(vl-catch-all-apply
'(lambda (X) (vla-close X :vlax-true FULL))
(list DOCOBJ)))
(princ (strcat "\nCan not close drawing "
FULL
" with active command in progress:")))))
(princ))
-
Here is mine. Pretty much the same thing, but mine doesn't try and save them. It hasn't locked up my Acad though.
(defun c:CloseAllButActive(/ tmpList)
(vl-load-com)
(vlax-for item (vla-get-documents (vlax-get-acad-object))
(if (= (vla-get-active item) :vlax-false)
(if (vl-catch-all-error-p (vl-catch-all-apply 'vla-close (list item :vlax-false)))
(setq tmpList (cons item tmpList))
)
)
)
(foreach item tmpList
(prompt (strcat "\n Drawing could not be closed \"" (vla-get-name item) "\"."))
)
(princ)
)
-
Thanks Tim, seems tobe working pecrfectly. I'm using it with your routines: "MyNext" and MyPrevious".
I use these two routines all of the time. Thanks for sharing them.
-
Thanks Tim, seems tobe working pecrfectly. I'm using it with your routines: "MyNext" and MyPrevious".
I use these two routines all of the time. Thanks for sharing them.
I use them all the time also. Good to hear that are still worth using. You're welcome Gary.
-
Ok you lisp guru's, is there a way to open drawings in a directory using Tim's "mynext" and "myprevious" without vba?
It would be great to have these functions for autocad 2010, since it does not support vba.
-
Here's two for you :-)
Open All Drawings in a Directory:
;; Open_all by Lee Mac
(defun c:open_all (/ path dwg)
(if (setq path (Directory-Dia "Select Directory: "))
(progn
(foreach dwg (mapcar
(function
(lambda (file)
(strcat path file)))
(vl-directory-files path "*.dwg" 1))
(if (vl-catch-all-error-p
(vl-catch-all-apply
(function
(lambda ( )
(vla-open
(vla-get-Documents
(vlax-get-acad-object)) dwg :vlax-false)))))
(princ (strcat "\n** " dwg " Failed to Open **")))))
(princ "\n*Cancel*"))
(princ))
(defun Directory-Dia (Message / sh folder folderobject result)
;; By Tony Tanzillo
(vl-load-com)
(setq sh (vla-getInterfaceObject
(vlax-get-acad-object) "Shell.Application"))
(setq folder (vlax-invoke-method sh 'BrowseForFolder
(vla-get-HWND
(vlax-get-Acad-Object)) Message 0))
(vlax-release-object sh)
(if folder
(progn
(setq folderobject (vlax-get-property folder 'Self)
result (vlax-get-property FolderObject 'Path))
(vlax-release-object folder)
(vlax-release-object FolderObject)
(if (/= (substr result (strlen result)) "\\")
(setq result (strcat result "\\"))
result))))
Open Latest Drawing in a Directory:
;; Open_last by Lee Mac
(defun c:open_last (/ path lst dwg)
(if (setq path (Directory-Dia "Select Directory: "))
(progn
(foreach dwg (mapcar
(function
(lambda (file)
(strcat path file)))
(vl-directory-files path "*.dwg" 1))
(setq lst
(cons
(list dwg (remove_nth (vl-file-systime dwg) 2)) lst)))
(if (vl-catch-all-error-p
(vl-catch-all-apply
(function
(lambda ( )
(vla-open
(vla-get-Documents
(vlax-get-acad-object))
(setq dwg (dSort lst)) :vlax-false)))))
(princ (strcat "\n** " dwg " Failed to Open **"))))
(princ "\n*Cancel*"))
(princ))
(defun Directory-Dia (Message / sh folder folderobject result)
;; By Tony Tanzillo
(vl-load-com)
(setq sh (vla-getInterfaceObject
(vlax-get-acad-object) "Shell.Application"))
(setq folder (vlax-invoke-method sh 'BrowseForFolder
(vla-get-HWND
(vlax-get-Acad-Object)) Message 0))
(vlax-release-object sh)
(if folder
(progn
(setq folderobject (vlax-get-property folder 'Self)
result (vlax-get-property FolderObject 'Path))
(vlax-release-object folder)
(vlax-release-object FolderObject)
(if (/= (substr result (strlen result)) "\\")
(setq result (strcat result "\\"))
result))))
; Stig
(defun remove_nth (lst i / a)
(setq a -1)
(vl-remove-if
(function
(lambda (n) (= (setq a (1+ a)) i))) lst))
(defun dSort (lst / lst)
(while
(progn
(cond ((not
(vl-remove-if 'null
(mapcar 'cadr lst)))
(setq lst nil))
((apply '=
(vl-sort
(mapcar 'caadr lst)
(function
(lambda (a b) (< a b)))))
(setq lst (mapcar
(function
(lambda (x)
(list (car x) (cdadr x)))) lst)))
(t (setq lst (caar lst)) nil))))
lst)
Enjoy :P
-
Thanks Lee
Here is the link to Tim's "Mynext" and "Myprevious" routines. These are the most used routines in our office.
It's just over my head to rework...Maybe I can nudge Tim Willey.
http://www.theswamp.org/index.php?topic=21986.0
-
Are the routines I posted not suitable for your purpose?
-
Do the .Net ones not work anymore? My .Net stuff works in '09, but haven't tried in '10.
-
Are the routines I posted not suitable for your purpose?
Lee
Thanks for your routines.
Please refer to Tim's routines which open the next or previous drawings in the current directory.
While you have a drawing open in the current directory, you can open the next drawing and so on.
Very useful for scrolling to the next drawing without having to go with the open command or without having to browse.
-
Do the .Net ones not work anymore? My .Net stuff works in '09, but haven't tried in '10.
Hi Tim
May have to refresh my bad memory. I think I remember them, but have not used them.
I think they should work. That right they are the dll routine taht has to be registered.
I will give them a try.
-
Do the .Net ones not work anymore? My .Net stuff works in '09, but haven't tried in '10.
Hi Tim
May have to refresh my bad memory. I think I remember them, but have not used them.
I think they should work. Can you post the link to your routines?
They are the ones in the link you posted. The ones you should be using are the .Net ones, not the Lisp ones. IIRC that is.
-
Are the routines I posted not suitable for your purpose?
Lee
Thanks for your routines.
Please refer to Tim's routines which open the next or previous drawings in the current directory.
While you have a drawing open in the current directory, you can open the next drawing and so on.
Very useful for scrolling to the next drawing without having to go with the open command or without having to browse.
I see -
They sound like some top-class functions - nice one Tim :-)
-
Tim, yes they work, I had to revise the reg code to the following:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\SOFTWARE\Autodesk\AutoCAD\R18.0\ACAD-8001:409\Applications\NextPrev18\Groups]
"Support"="Support"
[HKEY_CURRENT_USER\SOFTWARE\Autodesk\AutoCAD\R18.0\ACAD-8001:409\Applications\NextPrev18]
"DESCRIPTION"="Next Previous Drawing in the Directory"
"LOADCTRLS"=dword:00000004
"LOADER"="C:\\Arch_Custom\\Support\\NextPrev18.dll"
"MANAGED"=dword:00000001
[HKEY_CURRENT_USER\SOFTWARE\Autodesk\AutoCAD\R18.0\ACAD-8001:409\Applications\NextPrev18\Commands]
"MyNext"="MyNext"
"MyPrevious"="MyPrevious"
Thanks again Tim. Works perfectly in version 2010.
-
Thanks Lee. I also use them, and find them valuable.
Good to hear Gary. Thanks for confirming. That is the good time about .Net over ObjectArx. Don't have to recompile as often. :wink:
-
Ok you lisp guru's, is there a way to open drawings in a directory using Tim's "mynext" and "myprevious" without vba?
It would be great to have these functions for autocad 2010, since it does not support vba.
Acad 2010 doesn't support VBA?
-
Ok you lisp guru's, is there a way to open drawings in a directory using Tim's "mynext" and "myprevious" without vba?
It would be great to have these functions for autocad 2010, since it does not support vba.
Acad 2010 doesn't support VBA?
you have to install it, no longer standard.
-
Acad 2010 doesn't support VBA?
Autodesk will continue to support VBA now and into the foreseeable future in the AutoCAD product line. They have a transition plan to .NET and VSTA and expect to support VBA until research shows most customers have migrated their code (which could take years.)
At the moment Autodesk is offering VBA for download on their website, but I've read the 64bit version is very slow (haven't tried it).
VB(A) doesn't have a future because everyone is moving to 64bit and Microsoft doesn't support VB any more.
-
Here's two for you :-)
Open All Drawings in a Directory:
;; Open_all by Lee McDonnell
(defun c:open_all (/ path dwg)
(if (setq path (Directory-Dia "Select Directory: "))
(progn
(foreach dwg (mapcar
(function
(lambda (file)
(strcat path file)))
(vl-directory-files path "*.dwg" 1))
(if (vl-catch-all-error-p
(vl-catch-all-apply
(function
(lambda ( )
(vla-open
(vla-get-Documents
(vlax-get-acad-object)) dwg :vlax-false)))))
(princ (strcat "\n** " dwg " Failed to Open **")))))
(princ "\n*Cancel*"))
(princ))
(defun Directory-Dia (Message / sh folder folderobject result)
;; By Tony Tanzillo
(vl-load-com)
(setq sh (vla-getInterfaceObject
(vlax-get-acad-object) "Shell.Application"))
(setq folder (vlax-invoke-method sh 'BrowseForFolder
(vla-get-HWND
(vlax-get-Acad-Object)) Message 0))
(vlax-release-object sh)
(if folder
(progn
(setq folderobject (vlax-get-property folder 'Self)
result (vlax-get-property FolderObject 'Path))
(vlax-release-object folder)
(vlax-release-object FolderObject)
(if (/= (substr result (strlen result)) "\\")
(setq result (strcat result "\\"))
result))))
Open Latest Drawing in a Directory:
;; Open_last by Lee McDonnell
(defun c:open_last (/ path lst dwg)
(if (setq path (Directory-Dia "Select Directory: "))
(progn
(foreach dwg (mapcar
(function
(lambda (file)
(strcat path file)))
(vl-directory-files path "*.dwg" 1))
(setq lst
(cons
(list dwg (remove_nth (vl-file-systime dwg) 2)) lst)))
(if (vl-catch-all-error-p
(vl-catch-all-apply
(function
(lambda ( )
(vla-open
(vla-get-Documents
(vlax-get-acad-object))
(setq dwg (dSort lst)) :vlax-false)))))
(princ (strcat "\n** " dwg " Failed to Open **"))))
(princ "\n*Cancel*"))
(princ))
(defun Directory-Dia (Message / sh folder folderobject result)
;; By Tony Tanzillo
(vl-load-com)
(setq sh (vla-getInterfaceObject
(vlax-get-acad-object) "Shell.Application"))
(setq folder (vlax-invoke-method sh 'BrowseForFolder
(vla-get-HWND
(vlax-get-Acad-Object)) Message 0))
(vlax-release-object sh)
(if folder
(progn
(setq folderobject (vlax-get-property folder 'Self)
result (vlax-get-property FolderObject 'Path))
(vlax-release-object folder)
(vlax-release-object FolderObject)
(if (/= (substr result (strlen result)) "\\")
(setq result (strcat result "\\"))
result))))
; Stig
(defun remove_nth (lst i / a)
(setq a -1)
(vl-remove-if
(function
(lambda (n) (= (setq a (1+ a)) i))) lst))
(defun dSort (lst / lst)
(while
(progn
(cond ((not
(vl-remove-if 'null
(mapcar 'cadr lst)))
(setq lst nil))
((apply '=
(vl-sort
(mapcar 'caadr lst)
(function
(lambda (a b) (< a b)))))
(setq lst (mapcar
(function
(lambda (x)
(list (car x) (cdadr x)))) lst)))
(t (setq lst (caar lst)) nil))))
lst)
Enjoy :P
Can't open the "lt version" dwg.
-
I'm not sure this applies to the issue, but it works well for me.
;; JB 12/5/2008
;; Save and close all open documents.
(defun c:SaveCloseAll ( / *acad* ad)
(vl-load-com)
(setq *acad* (vlax-get-acad-object)
ad (vla-get-ActiveDocument *acad*)
)
(vlax-for x (vla-get-documents *acad*)
(if (not (equal x ad))
(progn
(vlax-invoke x 'Save)
(vlax-invoke x 'Close)
)
)
)
(command "._close" "yes")
) ;end
;------------------------------------
;shortcut
(defun c:SCA () (c:SaveCloseAll))
;------------------------------------
-
Thanks guys.
-
Here is mine. Pretty much the same thing, but mine doesn't try and save them. It hasn't locked up my Acad though.
(defun c:CloseAllButActive(/ tmpList)
(vl-load-com)
(vlax-for item (vla-get-documents (vlax-get-acad-object))
(if (= (vla-get-active item) :vlax-false)
(if (vl-catch-all-error-p (vl-catch-all-apply 'vla-close (list item :vlax-false)))
(setq tmpList (cons item tmpList))
)
)
)
(foreach item tmpList
(prompt (strcat "\n Drawing could not be closed \"" (vla-get-name item) "\"."))
)
(princ)
)
Chang:
(defun c:CloseAllButActive (/ tmpList)
(vl-load-com)
(vlax-for item (vla-get-documents (vlax-get-acad-object))
(if
(vl-catch-all-error-p
(vl-catch-all-apply
'vla-close
(list item :vlax-false)
)
)
(prompt (strcat "\n Drawing could not be closed \""
(vla-get-name item)
"\"."
)
)
)
)
(princ)
)
-
Here is my routine:
;;不保存关闭所有文档
(defun c:USave-CloseAll ( / ACADOBJ DOCS DOC)
(vl-load-com)
(SETVAR "SDI" 0)
(setq ACADOBJ (vlax-get-acad-object)
DOCS (vla-get-documents ACADOBJ)
DOC (vla-get-activedocument ACADOBJ)
)
(vlax-for d DOCS
(if (not (equal DOC d))
(vla-close d :vlax-false)
)
)
(command "vbastmt" "AcadApplication.activeDocument.close false ")
;;最后关闭当前活动的文档,这样就把所有的文档都关闭了 false 不保存关闭当前文档,true 保存然后关闭当前文档
(princ)
)
;;保存并关闭所有文档
(defun c:Save-CloseAll ( / ACADOBJ DOCS DOC)
(vl-load-com)
(SETVAR "SDI" 0)
(setq ACADOBJ (vlax-get-acad-object)
DOCS (vla-get-documents ACADOBJ)
DOC (vla-get-activedocument ACADOBJ)
)
(vlax-for d DOCS
(if (not (equal DOC d))
(vla-close d :vlax-true) ;_改为:vlax-true表示保存后关闭
)
)
(command "vbastmt" "AcadApplication.activeDocument.close true ")
;;最后关闭当前活动的文档,这样就把所有的文档都关闭了 false 不保存关闭当前文档,true 保存然后关闭当前文档
(princ)
)
-
2010 has this feature built right in. :roll: :evil: :lol:
-
I'm not sure this applies to the issue, but it works well for me.
;; JB 12/5/2008
;; Save and close all open documents.
(defun c:SaveCloseAll ( / *acad* ad)
(vl-load-com)
(setq *acad* (vlax-get-acad-object)
ad (vla-get-ActiveDocument *acad*)
)
(vlax-for x (vla-get-documents *acad*)
(if (not (equal x ad))
(progn
(vlax-invoke x 'Save)
(vlax-invoke x 'Close)
)
)
)
(command "._close" "yes")
) ;end
;------------------------------------
;shortcut
(defun c:SCA () (c:SaveCloseAll))
;------------------------------------
I want to take the theme of this post to ask:
Does anyone know how to close all drawings without saving?
-
I want to take the theme of this post to ask:
Does anyone know how to close all drawings without saving?
Using Joe's method:
(defun c:ca
( / app acd
) )
)
)
)
Or, simply the 'closeall' command (Express Tools).