Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Layers ON/OFF automatically

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
aqdam1978
583 Views, 5 Replies

Layers ON/OFF automatically

Hi,

 

I know that for layers ON/OFF in current open dwg file, I should use:

[I just want to On/Off for my "STAMP" layer]

 

(COMMAND "LAYER" "ON" "STAMP" "")

(COMMAND "LAYER" "OFF" "STAMP" "")

 

but I have more than 150 dwg file and I should open all of dwgs one by one and setting ON/OFF for STAMP layer for every drawing and it takes so much time! 😞

 

is there any solution for my question?

I just want to select files and LISP program set the STAMP layer to ON or OFF value.

 

can anybody help me?

 

Thanks.

 

5 REPLIES 5
Message 2 of 6
pbejse
in reply to: aqdam1978


@aqdam1978 wrote:

Hi,

 

I know that for layers ON/OFF in current open dwg file, I should use:

[I just want to On/Off for my "STAMP" layer]

 

(COMMAND "LAYER" "ON" "STAMP" "")

(COMMAND "LAYER" "OFF" "STAMP" "")

 

but I have more than 150 dwg file and I should open all of dwgs one by one and setting ON/OFF for STAMP layer for every drawing and it takes so much time! 😞

 

is there any solution for my question?

I just want to select files and LISP program set the STAMP layer to ON or OFF value.

 

can anybody help me?

 

Thanks.

 


 

On or Off? which one is it?  On if its off? and vice versa?

 

Message 3 of 6
aqdam1978
in reply to: pbejse

Hi pbejse,

 

the first step is OFF.

 

In fact I need two lisp program, one for OFF and one for ON!

But there are 99% similiar!

if I have OFF lisp, so I will have ON lisp too!

 

Thanks,

Message 4 of 6
pbejse
in reply to: aqdam1978


@aqdam1978 wrote:

Hi pbejse,

 

 

In fact I need two lisp program, one for OFF and one for ON!

But there are 99% similiar!

if I have OFF lisp, so I will have ON lisp too!

 

Thanks,


We can use ODBX. only "drawback" is you loose the thumbnail preview. but its not a big deal. when you open the file and save you will get it back

 

These are the supporting sub funcitons

 

(defun Get_Folder (/  sObj cFold fobj oval sto fto)
  	(setq sObj (vla-getInterfaceObject
                	(vlax-get-acad-object)"Shell.Application")
        		cFold(vlax-invoke-method sObj 'BrowseForFolder 0 "Select Folder for Layer Files" 512))
			(vlax-release-object sObj)
			(setq fObj(vlax-get-property cFold 'Self)
            			oVal (vlax-get-property fObj 'Path))
			(foreach sto (vl-directory-files oval "*.dwg")
			  	(setq fto (cons (strcat oval "\\" sto)  fto))
			  )
		(vlax-release-object cFold)
      		(vlax-release-object fObj)
	 	fto
	 		)
(defun _OnOffLayer (ln doc m)
      (if (not (vl-catch-all-error-p (setq la (vl-catch-all-apply 'vla-item
									(list (vla-get-layers doc) ln)))))
          	(vlax-put la 'Layeron m))
      			      			)
(defun _Odbx  (fileNames ln m)
      (cond ((and
                   (setq myDoc
                              (vla-GetInterfaceObject
                                    (vlax-Get-Acad-Object)
                                    (strcat
                                          "ObjectDBX.AxDbDocument."
                                          (substr (getvar 'AcadVer)
                                                  1
                                                  2))))
                   (foreach
                          File  Filenames
                         (if (not (vl-catch-all-apply
                                        'vla-Open
                                        (list myDoc file)))
                               (progn
                                     (_OnOffLayer
                                           ln
                                           myDoc
                                           m)
                                     (vla-saveas myDoc File)
                                     )
                               )
                               T
                         )
                   (vl-catch-all-apply
                         'vlax-Release-Object
                         (list myDoc))
                   )
             )
            )
      )
(vl-load-com)

 

 and this are the commands

 

(defun c:ons ( / Files)
	(if (setq files (Get_Folder))
      (_odbx files "STAMP" -1))
      (princ)
      )

(defun c:ofs ( / Files)
	(if (setq files (Get_Folder))
      (_odbx files "STAMP" 0))
      (princ)
      )

 

You can change the layer name to your liking

 

HTH

 

 

Message 5 of 6
aqdam1978
in reply to: pbejse

Hi Pbejse,

 

As usual your program is GREAT!

Excellecnt!

 

Thank you so much.

 

Message 6 of 6
pbejse
in reply to: aqdam1978


@aqdam1978 wrote:

Thank you so much.

 


You are welcome. 🙂

Glad i could help

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost