Freeze a common layer in all open drawings

Freeze a common layer in all open drawings

tfitzhardinge
Enthusiast Enthusiast
1,283 Views
6 Replies
Message 1 of 7

Freeze a common layer in all open drawings

tfitzhardinge
Enthusiast
Enthusiast

Hi

 

I'm new to scripting. Is there a way to freeze a common layer in all open drawings?

 

Thanks

0 Likes
Accepted solutions (1)
1,284 Views
6 Replies
Replies (6)
Message 2 of 7

pbejse
Mentor
Mentor

ALL common layers? or enable the user to select which of the common names will be frozen?

 

0 Likes
Message 3 of 7

tfitzhardinge
Enthusiast
Enthusiast

Thanks for your quick reply. Allow the user to specify a layer (which is common in all open drawings).

0 Likes
Message 4 of 7

pbejse
Mentor
Mentor

@tfitzhardinge wrote:

Thanks for your quick reply. Allow the user to specify a layer (which is common in all open drawings).


You need to download this function LM:listbox here--> Lee Mac | List box function 

 

Here's the general idea

 

(defun c:FCLDs ( / docs Alllayers docColl cnt ltfz )
	(setq Alllayers nil docColl nil);;<--- for debugging, you can remove this
	(vlax-map-Collection
	  (vla-get-documents (vlax-get-acad-object))
	  (function (lambda (itm / f lnm)
		      (setq docColl (cons itm docColl))
		      (vlax-for	l (Vla-get-layers itm)
			(setq Alllayers
			       (cond
				 ((setq
				    f (assoc (setq lnm (vla-get-name l)) Alllayers)
				  )
				  (cons	(list (car f) (cons l (cadr f)))
					(vl-remove f Alllayers)
				  )
				 )
				 ((cons (list lnm (list l)) Alllayers))
			       )
			)
		      )
		    )
	  )
	)
	(setq cnt (length docColl)
	       Alllayers (Vl-remove-if-not (function (lambda (ls)
				      (= (length (Cadr ls)) cnt))) Alllayers))
  	(setq ltfz (LM:listbox "Select layer name to freeze" (mapcar 'car Alllayers) 1))
  	(foreach itm ltfz
		   (foreach lay (cadr (assoc itm Alllayers))
		     (if (vl-catch-all-error-p
			     	(Vl-catch-all-apply 'vlax-put (list lay 'Freeze -1)))
		       (princ "\nLayer is current")
		  )
		)
	  )
	;; 	saving the file to reflect the changes  on the rest of the inactive drawings;;
  	(mapcar 'vla-save docColl)
  (princ)
  )

HTH 

0 Likes
Message 5 of 7

tfitzhardinge
Enthusiast
Enthusiast

Thanks for the solution. I'll try it out.

 

Is there was a lsp script solution to this. However I don't really know my options when it comes to scripting and coding options in autocad. Is it possible to run a lsp file with autocad commands through a batch file that targets drawings in a particle folder. I ran script pro 6 years ago and ran lsp file through it. I am under the impression that script pro doesn't receive any support.

0 Likes
Message 6 of 7

pbejse
Mentor
Mentor
Accepted solution

@tfitzhardinge wrote:

Thanks for the solution. I'll try it out.

 

Is there was a lsp script solution to this. However I don't really know my options when it comes to scripting and coding options in autocad. Is it possible to run a lsp file with autocad commands through a batch file that targets drawings in a particle folder. I ran script pro 6 years ago and ran lsp file through it. I am under the impression that script pro doesn't receive any support.


I see,  what you asked for, "in all open drawings", the posted code will do as you ask.

As for running through files on a folder. Yes Script pro is still in the mix

 

Try this.. https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/batch-freeze-thaw/td-p/6801628 

 

;;-------------------------------------------------------------------------------;;
;;                                  START Batch Freeze                           ;;
;;-------------------------------------------------------------------------------;;

 

 command:batchfreeze

 command:c:batchthaw

 

Try codes posted at post # 1 & 4

post # 1 : prompts the user for a specific layer

 

Command: BATCHFREEZE
Specify layer to freeze <exit>: *Cancel*

 

 

post # 4 : List of layers present on the current drawing

and another dialog to select the files.

 

dialog.PNG

 

HTH

 

 

 

0 Likes
Message 7 of 7

tfitzhardinge
Enthusiast
Enthusiast

@pbejse thank you so much for your assistance on this matter. I need to test out the solution but for now I'll accept the solution. I'll open it up if after I have done enough testing I have additional queries.

 

Thanks

0 Likes