Beena Posted May 13, 2010 Posted May 13, 2010 I have more than 120 drawings, but I want to freeze particular layer in all drawings, do you have any lisp to run all drawings in onetime. Quote
ReMark Posted May 13, 2010 Posted May 13, 2010 What you are trying to do would require a script file that would go out and get each drawing, open it, freeze the layer, save the drawing, close it and move on to the next drawing. It is impossible to do this to all 120 drawing at one time. Are all the drawings stored in the same folder? Quote
MSasu Posted May 13, 2010 Posted May 13, 2010 There are many batch processing routines in this forum - just locate one and modify it to suit your needs. Regards, Quote
The Buzzard Posted May 13, 2010 Posted May 13, 2010 I have more than 120 drawings, but I want to freeze particular layer in all drawings, do you have any lisp to run all drawings in onetime. Check out this thread. There is an excellent script writer by Lee Mac here called WSCRIPT.lsp: http://www.cadtutor.net/forum/showthread.php?t=44206&highlight=WSCRIPT+LISP Quote
Freerefill Posted May 13, 2010 Posted May 13, 2010 You could also take a look at the Batch Engine in my signature, though I'm sure Lee has done a better job than myself. Quote
JeepMaster Posted May 13, 2010 Posted May 13, 2010 8)Funny how when someone have a very simple problem, no one actually post the exact solution. Yet when someone have a very complicated problem, people jump in and post their solutions...just saying:D Beena, there's a very simple solution. It seems like everyone here want you to dig a little and find your own solution and learn something in the mean time. Ask again if you need more direction. Quote
Lee Mac Posted May 13, 2010 Posted May 13, 2010 Here is another (faster) way to approach it using ObjectDBX. This code will process all drawings in a directory (and subdirectories): (defun c:Test ( / layString ) (setq layString "#") (Mac-ODBX (function (lambda ( x ) (vlax-for lay (vla-get-layers x) (if (wcmatch (vla-get-name lay) layString) (vl-catch-all-apply (function vla-put-freeze) (list lay :vlax-true) ) ) ) ) ) nil t ) (princ) ) ;;;¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,;;; ;;;ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,¤º°`°º¤;;; ;; ;; ;; ;; ;; --=={ ObjectDBX Base Program }==-- ;; ;; ;; ;; Provides a shell through which a LISP may operate on multiple drawings in a ;; ;; folder/sub-folders. ;; ;; ;; ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=;; ;; ;; ;; AUTHOR: ;; ;; ;; ;; Copyright © Lee McDonnell, January 2010. All Rights Reserved. ;; ;; ;; ;; { Contact: Lee Mac @ TheSwamp.org, CADTutor.net } ;; ;; ;; ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=;; ;; ;; ;; ARGUMENTS: ;; ;; ;; ;; foo ~ a function taking a single argument (the Document Object), and ;; ;; following the 'rules' of ObjectDBX: ;; ;; ;; ;; - No SelectionSets (ssget,ssname etc.) ;; ;; - No Command calls ;; ;; - No *Ent Methods (entget,entmod etc.) ;; ;; - No Access to System Variables (vla-Set/GetVariable, etc) ;; ;; ;; ;; dwgLst ~ [Optional] A list of dwg filepaths to process, if nil, program ;; ;; will display BrowseForFolder dialog. ;; ;; ;; ;; save ~ [boole] if True, drawing will be saved after function evaluation. ;; ;; ;; ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=;; ;; ;; ;;;¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,;;; ;;;ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,¤º°`°º¤;;; (defun Mac-ODBX (foo dwgLst save / *error* ObjRelease Get_Subs DirDialog ObjectDBXDocument DBX DBXDOC DOCLST DWGLST ERR FILE FILEPATH FLAG FOLDER PATH RESULT SUBS) (vl-load-com) (setq *acad (cond (*acad) ((vlax-get-acad-object))) *adoc (cond (*adoc) ((vla-get-ActiveDocument *acad)))) ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=;; (defun *error* (msg) (ObjRelease (list dbx dbxdoc)) (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **"))) (princ) ) ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=;; (defun ObjRelease (lst) (mapcar (function (lambda (x) (if (and (eq (type x) 'VLA-OBJECT) (not (vlax-object-released-p x))) (vl-catch-all-apply (function vlax-release-object) (list x) ) ) ) ) lst ) ) ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=;; (defun Get_Subs (folder / file) ;; CAB (mapcar (function (lambda (x) (setq file (strcat folder "\\" x)) (cons file (apply (function append) (get_subs file))) ) ) (cddr (vl-directory-files folder nil -1)) ) ) ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=;; (defun DirDialog (msg dir flag / Shell Fold Path) ; Lee Mac ~ 07.06.09 (setq *acad (cond (*acad) ((vlax-get-acad-object)))) (setq Shell (vla-getInterfaceObject *acad "Shell.Application") Fold (vlax-invoke-method Shell 'BrowseForFolder (vla-get-HWND *acad) msg flag dir)) (vlax-release-object Shell) (if Fold (progn (setq Path (vlax-get-property (vlax-get-property Fold 'Self) 'Path ) ) (vlax-release-object Fold) (and (= "\\" (substr Path (strlen Path))) (setq Path (substr Path 1 (1- (strlen Path)))) ) ) ) Path ) ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=;; (defun ObjectDBXDocument (/ acVer) (setq *acad (cond (*acad) ((vlax-get-acad-object)))) (vla-GetInterfaceObject *acad (if (< (setq acVer (atoi (getvar "ACADVER"))) 16) "ObjectDBX.AxDbDocument" (strcat "ObjectDBX.AxDbDocument." (itoa acVer)) ) ) ) ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=;; (if (setq dwgLst (cond (dwgLst) ( (setq Path (DirDialog "Select Directory to Process" nil 0)) (initget "Yes No") (setq subs (cond ((getkword "\nProcess SubDirectories? <Yes> : ")) ("Yes"))) (apply (function append) (vl-remove 'nil (mapcar (function (lambda (Filepath) (mapcar (function (lambda (Filename) (strcat Filepath "\\" Filename) ) ) (vl-directory-files Filepath "*.dwg" 1) ) ) ) (append (list Path) (apply (function append) (if (= "Yes" subs) (Get_Subs Path)) ) ) ) ) ) ) ) ) (progn (vlax-for doc (vla-get-Documents *acad) (setq DocLst (cons (cons (strcase (vla-get-fullname doc)) doc ) DocLst ) ) ) (setq dbxdoc (ObjectDBXDocument)) (foreach dwg dwgLst (setq flag (and (setq dbx (cdr (assoc (strcase dwg) DocLst) ) ) ) ) (and (not flag) (setq Err (vl-catch-all-apply (function vla-open) (list dbxdoc dwg)) dbx dbxdoc)) (if (or flag (not (vl-catch-all-error-p Err))) (progn (setq Result (cons (cons dwg ((eval foo) dbx)) Result ) ) (if save (vla-saveas dbx dwg)) ) (princ (strcat "\n** Error Opening File: " (vl-filename-base dwg) ".dwg **")) ) ) ) ) (ObjRelease (list dbx dbxdoc)) Result ) The highlighted part should be a WildCard string specifying the layers you wish to freeze. The drawback of using ObjectDBX is that you will lose the drawing thumbnail until you next save the drawing manually. Type 'test' to invoke the function. If you have any trouble with it, let me know, Lee 1 Quote
The Buzzard Posted May 13, 2010 Posted May 13, 2010 Hey Lee, I am not sure if its a bug, But once running your program on a directory and freezing layer 0 . I tried to go in to the layer manager and got this: Invalid option keyword. Command: *Cancel* Command: '_layer After a few tries I finally got in and it will not allow me to thaw the layer. Quote
alanjt Posted May 13, 2010 Posted May 13, 2010 Hey Lee,I am not sure if its a bug, But once running your program on a directory and freezing layer 0 . I tried to go in to the layer manager and got this: Invalid option keyword. Command: *Cancel* Command: '_layer After a few tries I finally got in and it will not allow me to thaw the layer. I know this sounds crazy, but is "0" your current layer? Quote
Lee Mac Posted May 13, 2010 Posted May 13, 2010 Perhaps its the current layer? I put an error trap in there to allow for the attempted freezing of the current layer, but I suppose a quick check would be better. Perhap ODBX allows you to freeze the current layer Quote
alanjt Posted May 13, 2010 Posted May 13, 2010 Yes, but what does that mean? If the current layer is frozen (can happen with Entmod), you can't thaw it until you make a different layer current. Perhaps its the current layer? I put an error trap in there to allow for the attempted freezing of the current layer, but I suppose a quick check would be better. Perhap ODBX allows you to freeze the current layer Entmod will allow you to freeze the current layer. That's interesting that vla will through ODBX but fail in active/open drawing. Quote
The Buzzard Posted May 13, 2010 Posted May 13, 2010 If the current layer is frozen (can happen with Entmod), you can't thaw it until you make a different layer current. Entmod will allow you to freeze the current layer. That's interesting that vla will through ODBX but fail in active/open drawing. OK that fixed it, Thanks Quote
Lee Mac Posted May 13, 2010 Posted May 13, 2010 Entmod will allow you to freeze the current layer. That's interesting that vla will through ODBX but fail in active/open drawing. Oh, I didn't realise you could do it with entmod - I knew that vla would (or rather 'should' fail)... but interesting that it doesn't with ODBX. Problem is, no ActiveLayer property through ODBX, and no access to CLAYER either Quote
The Buzzard Posted May 13, 2010 Posted May 13, 2010 What does it mean when you cannot grab your viewports? Quote
The Buzzard Posted May 13, 2010 Posted May 13, 2010 Ok, I shut down the drawing and restarted it and I can now grab the viewports. Quote
alanjt Posted May 13, 2010 Posted May 13, 2010 Ok, I shut down the drawing and restarted it and I can now grab the viewports. If your viewports are on the Defpoints layer and you freeze the "0" layer, you will not be able to select them. Actually, that goes for anything on the Defpoints layer. 'Generally' a regen and swap from model and back to paper will refresh everything, but as you noticed, a restart can be required sometimes. Quote
alanjt Posted May 13, 2010 Posted May 13, 2010 Oh, I didn't realise you could do it with entmod - I knew that vla would (or rather 'should' fail)... but interesting that it doesn't with ODBX. Problem is, no ActiveLayer property through ODBX, and no access to CLAYER either Yeah, I realized it when I wrote my LayerFreeze routine a couple years ago (all in entmod - didn't know VLA then). Mine will set to "0" if I try and freeze the current layer, but if I try and freeze "0" and it's current, it just freeze it. I thought about coding around it, but I've never had a reason to freeze the "0" layer. Quote
The Buzzard Posted May 13, 2010 Posted May 13, 2010 Yeah, I realized it when I wrote my LayerFreeze routine a couple years ago (all in entmod - didn't know VLA then). Mine will set to "0" if I try and freeze the current layer, but if I try and freeze "0" and it's current, it just freeze it. I thought about coding around it, but I've never had a reason to freeze the "0" layer. I just ran the code to see what would happen, I did not expect this. Everything is OK now. Quote
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.