Layers On LISP

Layers On LISP

More8927
Contributor Contributor
1,905 Views
6 Replies
Message 1 of 7

Layers On LISP

More8927
Contributor
Contributor

Hi, 

 

I am trying to write a simple lisp that can turn a set of layers on.  I keep running into a nil error.  The set is generated by a seperate program that will generate the lsp and run it as part of a script. That said it would be best if I can leave layer list variable in an easy to generate format, but I am not against changing it if I need to. 

 

;;; TURNS ON LAYERS LISTED BELOW
(defun c:FADJ ()
(setq stuff '("05" "02" "Named Layer"))
(foreach stuff
(command "-layer" "_on" stuff)
)
)

 

Thanks,

 

Michael

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

Kent1Cooper
Consultant
Consultant
Accepted solution

You don't have the arguments right in the (foreach) function, if 'stuff' is a list, and you need to complete the Layer command.  Change:

 

(foreach stuff
  (command "-layer" "_on" stuff)
)

 

to something like:

 

(foreach lay stuff
  (command "-layer" "_on" lay "")
)

Kent Cooper, AIA
Message 3 of 7

Shneuph
Collaborator
Collaborator

This seems to do what you're asking for.

 

(defun c:FADJ ()
(setq stuff '("05" "02" "Named Layer"))
(foreach x stuff
(command "-layer" "_on" x "")
)
)
---sig---------------------------------------
'(83 104 110 101 117 112 104 64 71 109 97 105 108 46 99 111 109)
Message 4 of 7

Shneuph
Collaborator
Collaborator

http://i.imgur.com/avqILfJ.gif  <---Kent  Smiley Happy

---sig---------------------------------------
'(83 104 110 101 117 112 104 64 71 109 97 105 108 46 99 111 109)
0 Likes
Message 5 of 7

ВeekeeCZ
Consultant
Consultant

I would recommend not to run -layer command multiply - because each layer has its own step while you using _layerp to return to previous layerstate. You would probably expect, that this will be done in one step.

 

You can achieve that with following approach:
-layer on "05" on "02" on "Named Layer" ""

 

or convert your list to comma delimited string. Then it would look like this:
-layer on "05,02,Named Layer" ""

 

You can choose...

 

 

Spoiler
(defun c:FADJ ()
  (setq stuff '("05" "02" "Named Layer"))
  (if stuff
    (progn
      (command "_-layer")
      (foreach lay stuff
	(command "_on" lay))
      (command)))
  (princ)
)


(defun c:FADJ2 ( / lays)
  (setq stuff '("05" "02" "Named Layer"))
  (setq lays "")
  (foreach lay stuff
    (setq lays (strcat lay "," lays)))
  (command "_-layer" "_on" lays "")
  (princ)
)

 

 

Message 6 of 7

hmsilva
Mentor
Mentor

@ВeekeeCZ wrote:

I would recommend not to run -layer command multiply - because each layer has its own step while you using _layerp to return to previous layerstate. You would probably expect, that this will be done in one step.

 

You can achieve that with following approach:
-layer on "05" on "02" on "Named Layer" ""

 

or convert your list to comma delimited string. Then it would look like this:
-layer on "05,02,Named Layer" ""

 

You can choose... 


1+

 

or

 

(defun c:FADJ3 nil
    (setq stuff '("05" "02" "Named Layer"))
    (command "_-layer" "_on" (apply 'strcat (mapcar '(lambda (x) (strcat x ",")) stuff)) "")
    (princ)
)

 

Henrique

EESignature

0 Likes
Message 7 of 7

Kent1Cooper
Consultant
Consultant

Yet another way to go about it, which with a large enough number of Layers could be noticeably faster than using a Layer command [especially if separate Layer commands] in one or more (command) functions, would be to substitute the non-negative color number into the entity data for each Layer as an object from the Layer table:

 

(foreach lay stuff

  (setq ldata (entget (tblobjname "layer" lay)))
  (entmod (subst (cons 62 (abs (cdr (assoc 62 ldata)))) (assoc 62 ldata) ldata))

); foreach

Kent Cooper, AIA