Hi
Adapted from one of my lisp
;;;=================================================================
;;;
;;; LAY.LSP V1.00
;;;
;;; Déverrouiller tous les calques de tous les dessins d'un répertoire
;;;
;;; Copyright (C) Patrick_35
;;;
;;;=================================================================
(defun c:lay(/ att ava bl dbx express fic lay lst obj rep s tot ver
*errlay* msgbox dirbox ouvrir_dessin_dbx)
;;;---------------------------------------------------------------
;;;
;;; Gestion des erreurs
;;;
;;;---------------------------------------------------------------
(defun *errlay* (msg)
(or (member (strcase msg) '("FUNCTION CANCELLED" ""QUIT / EXIT ABORT"" "FONCTION ANNULEE" "QUITTER / SORTIR ABANDON"))
(princ (strcat "\nErreur : " msg))
)
(vla-endundomark doc)
(setq *error* s)
(princ)
)
;;;---------------------------------------------------------------
;;;
;;; Message
;;;
;;;---------------------------------------------------------------
(defun msgbox (Titre Bouttons Message / Reponse WshShell)
(setq WshShell (vlax-create-object "WScript.Shell"))
(setq Reponse (vlax-invoke WshShell 'Popup Message 0 Titre (itoa Bouttons)))
(vlax-release-object WshShell)
Reponse
)
;;;---------------------------------------------------------------
;;;
;;; Choix du répertoire
;;;
;;;---------------------------------------------------------------
(defun dirbox(/ bas cdl rep)
(if (setq cdl (vlax-create-object "Shell.Application"))
(progn
(and (setq rep (vlax-invoke cdl 'browseforfolder 0 "Choose a directory to process all the drawings and unlock all layers" 512 ""))
(setq rep (vlax-get-property (vlax-get-property rep 'self) 'path))
)
(vlax-release-object cdl)
)
)
rep
)
;;;---------------------------------------------------------------
;;;
;;; Ouvrir un dessin via ObjectDbx
;;;
;;;---------------------------------------------------------------
(defun Ouvrir_dessin_dbx(dwg / dbx doc lan rel)
(and (setq dwg (findfile dwg))
(progn
(vlax-for doc (vla-get-documents (vlax-get-acad-object))
(and (eq (strcase (vla-get-fullname doc)) (strcase dwg))
(setq dbx doc lan T)
)
)
(and (not dbx)
(setq dbx (vlax-create-object (if (< (setq rel (atoi (getvar "ACADVER"))) 16)
"ObjectDBX.AxDbDocument"
(strcat "ObjectDBX.AxDbDocument." (itoa rel))
)
)
)
(vla-open dbx dwg)
)
)
)
(list dbx lan)
)
;;;---------------------------------------------------------------
;;;
;;; Routine principale
;;;
;;;---------------------------------------------------------------
(vl-load-com)
(setq s *error*
*error* *errlay*
)
(if (eval 'acet-ui-progress-done)
(setq express T)
)
(if (setq rep (dirbox))
(if (setq lst (vl-directory-files rep "*.dwg" 1))
(foreach fic lst
(if (setq dbx (ouvrir_dessin_dbx (strcat rep "/" fic)))
(progn
(setq tot (vla-get-count (vla-get-layers (car dbx)))
ava 0
)
(and express
(acet-ui-progress-init "" tot)
)
(princ (strcat "\n Work in " fic))(princ)
(vlax-for lay (vla-get-layers (car dbx))
(and (eq (vla-get-lock lay) :vlax-true)
(vla-put-lock lay :vlax-false)
)
(and express
(setq ava (1+ ava))
(acet-ui-progress-safe ava)
)
)
(and express
(acet-ui-progress-done)
)
(or (cadr dbx)
(progn
(princ " ...Save")(princ)
(vla-saveas (car dbx) (strcat rep "/" fic))
(vlax-release-object (car dbx))
)
)
(princ " ...OK")(princ)
)
(princ (strcat "\n Unable to read file " fic))
)
)
(msgbox "LAY" 64 (strcat "No drawing in " rep))
)
)
(setq *error* s)
(princ)
)