Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Mentor
aqdam1978
Posts: 265
Registered: ‎11-05-2008
Message 1 of 6 (276 Views)
Accepted Solution

Layers ON/OFF automatically

276 Views, 5 Replies
01-25-2013 12:19 PM

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! :smileysad:

 

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.

 

*Expert Elite*
pbejse
Posts: 2,459
Registered: ‎11-24-2009
Message 2 of 6 (253 Views)

Re: Layers ON/OFF automatically

01-25-2013 09:00 PM 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! :smileysad:

 

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?

 

Mentor
aqdam1978
Posts: 265
Registered: ‎11-05-2008
Message 3 of 6 (250 Views)

Re: Layers ON/OFF automatically

01-25-2013 09:10 PM 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,

*Expert Elite*
pbejse
Posts: 2,459
Registered: ‎11-24-2009
Message 4 of 6 (242 Views)

Re: Layers ON/OFF automatically

01-25-2013 10:50 PM 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

 

 

Mentor
aqdam1978
Posts: 265
Registered: ‎11-05-2008
Message 5 of 6 (205 Views)

Re: Layers ON/OFF automatically

01-28-2013 07:00 AM in reply to: pbejse

Hi Pbejse,

 

As usual your program is GREAT!

Excellecnt!

 

Thank you so much.

 

*Expert Elite*
pbejse
Posts: 2,459
Registered: ‎11-24-2009
Message 6 of 6 (182 Views)

Re: Layers ON/OFF automatically

01-28-2013 10:01 PM in reply to: aqdam1978

aqdam1978 wrote:

Thank you so much.

 


You are welcome. :smileyhappy:

Glad i could help

 

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.