Jump to content

can we Freeze/Unfreeze Layer in all DWG at once


Recommended Posts

Posted (edited)

Dear All

Is it possible that we can Freeze/Unfreeze any layer in multiple dwg at once, like if i want to Freeze Grid layer and in the same dwg i want to Unfreeze Grid1 layer can we do this at one move?

Edited by pmadhwal7
Posted (edited)

haven't tested it but maybe this works :

										
;;; this program can turn off the layer you enter.				
(defun c:lof ()       
  (vl-load-com)
  (setq dwgfile (getfiled "Select a drawing" "" "dwg" 0))
  (setq lay (getstring "\nENTER A LAYER TO TURN OFF:"))
  (setq cadver(substr (getvar "acadver") 1 2))                       ;; get cad version No.
  (setq id (strcat "objectdbx.AxDbDocument." cadver))           ;; creat prog id
  (setq dbx(vlax-create-object id))                                         ;; creat dbx object
  (vla-open dbx dwgfile)
  (setq layers (vla-get-layers dbx))                 ;; get layer collection set from dbx
  (if (not (vl-catch-all-error-p
    (setq vlay(vl-catch-all-apply 'vla-item (list layers lay)))))       ;; fild the specified layer in collection   
      (if (eq (vla-get-layeron vlay) :vlax-true)                          ;; check layer status         
        (vla-put-layeron vlay :vlax-false)  
      )   
    (print "THE LAYER NOT FOUND  ! ")
  )
  (vla-saveas dbx dwgfile)  
  (vlax-release-object dbx)
  (prin1)
)				

Edited by rlx
Posted
22 minutes ago, rlx said:

haven't tested it but maybe this works :


										
;;; this program can turn off the layer you enter.				
(defun c:lof ()       
  (vl-load-com)
  (setq dwgfile (getfiled "Select a drawing" "" "dwg" 0))
  (setq lay (getstring "\nENTER A LAYER TO TURN OFF:"))
  (setq cadver(substr (getvar "acadver") 1 2))                       ;; get cad version No.
  (setq id (strcat "objectdbx.AxDbDocument." cadver))           ;; creat prog id
  (setq dbx(vlax-create-object id))                                         ;; creat dbx object
  (vla-open dbx dwgfile)
  (setq layers (vla-get-layers dbx))                 ;; get layer collection set from dbx
  (if (not (vl-catch-all-error-p
    (setq vlay(vl-catch-all-apply 'vla-item (list layers lay)))))       ;; fild the specified layer in collection   
      (if (eq (vla-get-layeron vlay) :vlax-true)                          ;; check layer status         
        (vla-put-layeron vlay :vlax-false)  
      )   
    (print "THE LAYER NOT FOUND  ! ")
  )
  (vla-saveas dbx dwgfile)  
  (vlax-release-object dbx)
  (prin1)
)				

 

Its working but It's just turning off and also only in one dwg and, actually i want to freeze the layer and unfreeze the layer by mistake i was return off...sorry

 

Posted


(defun GetShellFolder ( m / f s) (if (and (setq s (vlax-create-object "Shell.Application"))
  (setq f (vlax-invoke s 'browseforfolder 0 m 0 "")))(setq f (vlax-get-property (vlax-get-property f 'self) 'path))
     (setq f nil))(vl-catch-all-apply 'vlax-release-object (list s))
  (if f (strcat (vl-string-right-trim "\\" (vl-string-translate "/" "\\" f)) "\\")))

(defun alf (f) (setq f (vl-string-right-trim "\\" (vl-string-translate "/" "\\" f)))
  (append (mapcar '(lambda (x) (strcat f "\\" x)) (vl-directory-files f "*.dwg" 1)) (if T (apply
   'append (mapcar '(lambda (x)(if (not (wcmatch x "`.,`.`."))(alf (strcat f "\\" x))))(vl-directory-files f nil -1))))))

; layer off
(defun c:loff ( / f lay lst dbx layers vlay)
  (if (and (setq f (GetShellFolder "Select folder with dwg to switch off layer"))
           (setq lay (getstring "\nLayer name to turn off : ")) (vl-consp (setq lst (alf f))))
    (progn
      (setq dbx (vlax-create-object (strcat "objectdbx.AxDbDocument." (substr (getvar "acadver") 1 2))))
      (foreach dwgfile lst
        (vla-open dbx dwgfile)
        (setq layers (vla-get-layers dbx))
        (if (not (vl-catch-all-error-p (setq vlay (vl-catch-all-apply 'vla-item (list layers lay)))))
          (if (eq (vla-get-layeron vlay) :vlax-true)(vla-put-layeron vlay :vlax-false))
          (print (strcat "\nLayer " lay " not found in " dwgfile))
        )
        (vla-saveas dbx dwgfile)
      )
    )
  )
  (vl-catch-all-apply 'vlax-release-object (list dbx))
  (princ)
)

; layer freeze
(defun c:lfrz ( / f lay lst dbx layers vlay)
  (if (and (setq f (GetShellFolder "Select folder with dwg to switch off layer"))
           (vl-consp (setq lst (alf f)))
           (setq freeze_me (getstring "\nLayer name to freeze : "))
           (setq thaw_me (getstring "\nLayer name to thaw : ")))
    (progn
      (setq dbx (vlax-create-object (strcat "objectdbx.AxDbDocument." (substr (getvar "acadver") 1 2))))
      (foreach dwgfile lst
        (vla-open dbx dwgfile)
        (setq layers (vla-get-layers dbx))
        (if (not (vl-catch-all-error-p (setq vlay (vl-catch-all-apply 'vla-item (list layers freeze_me)))))
          (if (eq (vla-get-freeze vlay) :vlax-false) (vla-put-freeze vlay :vlax-true))
          (print (strcat "\nLayer " freeze_me " not found in " dwgfile)))
        (if (not (vl-catch-all-error-p (setq vlay (vl-catch-all-apply 'vla-item (list layers thaw_me)))))
          (if (eq (vla-get-freeze vlay) :vlax-true)(vla-put-freeze vlay :vlax-false))
          (print (strcat "\nLayer " thaw_me " not found in " dwgfile)))
        (vla-saveas dbx dwgfile)
      )
    )
  )
  (vl-catch-all-apply 'vlax-release-object (list dbx))
  (princ)
)

untested

Posted
23 minutes ago, rlx said:

 


(defun GetShellFolder ( m / f s) (if (and (setq s (vlax-create-object "Shell.Application"))
  (setq f (vlax-invoke s 'browseforfolder 0 m 0 "")))(setq f (vlax-get-property (vlax-get-property f 'self) 'path))
     (setq f nil))(vl-catch-all-apply 'vlax-release-object (list s))
  (if f (strcat (vl-string-right-trim "\\" (vl-string-translate "/" "\\" f)) "\\")))

(defun alf (f) (setq f (vl-string-right-trim "\\" (vl-string-translate "/" "\\" f)))
  (append (mapcar '(lambda (x) (strcat f "\\" x)) (vl-directory-files f "*.dwg" 1)) (if T (apply
   'append (mapcar '(lambda (x)(if (not (wcmatch x "`.,`.`."))(alf (strcat f "\\" x))))(vl-directory-files f nil -1))))))

; layer off
(defun c:loff ( / f lay lst dbx layers vlay)
  (if (and (setq f (GetShellFolder "Select folder with dwg to switch off layer"))
           (setq lay (getstring "\nLayer name to turn off : ")) (vl-consp (setq lst (alf f))))
    (progn
      (setq dbx (vlax-create-object (strcat "objectdbx.AxDbDocument." (substr (getvar "acadver") 1 2))))
      (foreach dwgfile lst
        (vla-open dbx dwgfile)
        (setq layers (vla-get-layers dbx))
        (if (not (vl-catch-all-error-p (setq vlay (vl-catch-all-apply 'vla-item (list layers lay)))))
          (if (eq (vla-get-layeron vlay) :vlax-true)(vla-put-layeron vlay :vlax-false))
          (print (strcat "\nLayer " lay " not found in " dwgfile))
        )
        (vla-saveas dbx dwgfile)
      )
    )
  )
  (vl-catch-all-apply 'vlax-release-object (list dbx))
  (princ)
)

; layer freeze
(defun c:lfrz ( / f lay lst dbx layers vlay)
  (if (and (setq f (GetShellFolder "Select folder with dwg to switch off layer"))
           (vl-consp (setq lst (alf f)))
           (setq freeze_me (getstring "\nLayer name to freeze : "))
           (setq thaw_me (getstring "\nLayer name to thaw : ")))
    (progn
      (setq dbx (vlax-create-object (strcat "objectdbx.AxDbDocument." (substr (getvar "acadver") 1 2))))
      (foreach dwgfile lst
        (vla-open dbx dwgfile)
        (setq layers (vla-get-layers dbx))
        (if (not (vl-catch-all-error-p (setq vlay (vl-catch-all-apply 'vla-item (list layers freeze_me)))))
          (if (eq (vla-get-freeze vlay) :vlax-false) (vla-put-freeze vlay :vlax-true))
          (print (strcat "\nLayer " freeze_me " not found in " dwgfile)))
        (if (not (vl-catch-all-error-p (setq vlay (vl-catch-all-apply 'vla-item (list layers thaw_me)))))
          (if (eq (vla-get-freeze vlay) :vlax-true)(vla-put-freeze vlay :vlax-false))
          (print (strcat "\nLayer " thaw_me " not found in " dwgfile)))
        (vla-saveas dbx dwgfile)
      )
    )
  )
  (vl-catch-all-apply 'vlax-release-object (list dbx))
  (princ)
)

 

untested

 

Many Many Many Many.....∞ thanks sir..............

 

 

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