Jump to content

To Freeze Layer


Beena

Recommended Posts

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

There are many batch processing routines in this forum - just locate one and modify it to suit your needs.

 

Regards,

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.:roll: Ask again if you need more direction.

Link to comment
Share on other sites

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

  • Like 1
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

zero.PNG

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

Entmod will allow you to freeze the current layer. That's interesting that vla will through ODBX but fail in active/open drawing.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

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.

Link to comment
Share on other sites

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.

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