TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: jlogan02 on November 08, 2019, 11:25:07 AM

Title: entmod not working
Post by: jlogan02 on November 08, 2019, 11:25:07 AM
My entmod doesn't seem to be working here.
Layer gets created with the -N suffix and color red but the selected object doesn't get moved to that new layer.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:ByToRed ( / e i l n s x )
  2.  (defun *error* (msg)
  3.     (if osm
  4.       (setvar 'osmode osm)
  5.     )
  6.     (if (not (member msg '("Function cancelled" "quit / exit abort")))
  7.       (princ (strcat "\nError: " msg))
  8.     )
  9.     (princ)
  10.   )
  11.   (if (setq s (ssget ":L"))
  12.       (repeat (setq i (sslength s))
  13.            (setq x (entget (ssname s (setq i (1- i))))
  14.                  l (assoc 8 x)
  15.                  n (strcat (cdr l) "-N")
  16.            )
  17.            (if (not (tblsearch "layer" n))
  18.                (progn
  19.                    (setq e (entget (tblobjname "layer" (cdr l))))
  20.                    (entmake (subst (cons 2 n) (assoc 2 e) (subst '(62 . 1) (assoc 62 e) e)))
  21.                        
  22.                           )
  23.            )
  24.            (entmod (subst (cons 8 n) 1 x))
  25.             )
  26.    )
  27.     (prompt "\nAll objects have been moved to new construction layer")
  28.  (princ)
  29. )

Something simple I'm sure. Well, not to me anyway.

J. Logan
Title: Re: entmod not working
Post by: ronjonp on November 08, 2019, 12:01:26 PM
My entmod doesn't seem to be working here.
Layer gets created with the -N suffix and color red but the selected object doesn't get moved to that new layer.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:ByToRed ( / e i l n s x )
  2.  (defun *error* (msg)
  3.     (if osm
  4.       (setvar 'osmode osm)
  5.     )
  6.     (if (not (member msg '("Function cancelled" "quit / exit abort")))
  7.       (princ (strcat "\nError: " msg))
  8.     )
  9.     (princ)
  10.   )
  11.   (if (setq s (ssget ":L"))
  12.       (repeat (setq i (sslength s))
  13.            (setq x (entget (ssname s (setq i (1- i))))
  14.                  l (assoc 8 x)
  15.                  n (strcat (cdr l) "-N")
  16.            )
  17.            (if (not (tblsearch "layer" n))
  18.                (progn
  19.                    (setq e (entget (tblobjname "layer" (cdr l))))
  20.                    (entmake (subst (cons 2 n) (assoc 2 e) (subst '(62 . 1) (assoc 62 e) e)))
  21.                        
  22.                           )
  23.            )
  24.            (entmod (subst (cons 8 n) 1 x))
  25.             )
  26.    )
  27.     (prompt "\nAll objects have been moved to new construction layer")
  28.  (princ)
  29. )

Something simple I'm sure. Well, not to me anyway.

J. Logan
Try this:
Code - Auto/Visual Lisp: [Select]
  1.       ;; This
  2.       (entmod (append x (list (cons 8 n))))
  3.       ;; Or this
  4.       (entmod (subst (cons 8 n) (assoc 8 x) x))
  5.       ;; (entmod (subst (cons 8 n) 1 x))
The red layer creation could be simplified to this too:
Code - Auto/Visual Lisp: [Select]
  1. (entmake (append e (list (cons 2 n) '(62 . 1))))
Title: Re: entmod not working
Post by: tombu on November 08, 2019, 12:07:43 PM
Change
Code: [Select]
(entmod (subst (cons 8 n) 1 x))to
Code: [Select]
(entmod (setq x (subst (cons 8 n) 1 x)))
Title: Re: entmod not working
Post by: jlogan02 on November 08, 2019, 12:12:38 PM
Thanks Ron,

      ;; Or this
     
Code - Auto/Visual Lisp: [Select]
  1. (entmod (subst (cons 8 n) (assoc 8 x) x))

What does the last ... x)) do here???   
Title: Re: entmod not working
Post by: ronjonp on November 08, 2019, 12:19:12 PM
Thanks Ron,

      ;; Or this
     
Code - Auto/Visual Lisp: [Select]
  1. (entmod (subst (cons 8 n) (assoc 8 x) x))

What does the last ... x)) do here???
See if you can figure it out :)
Code - Auto/Visual Lisp: [Select]
  1.            (setq x (entget (ssname s (setq i (1- i))))
  2.                  l (assoc 8 x)
  3.                  n (strcat (cdr l) "-N")
  4.            )
Title: Re: entmod not working
Post by: jlogan02 on November 08, 2019, 12:42:44 PM
Code - Auto/Visual Lisp: [Select]
  1. (setq x (entget (ssname s (setq i (1- i))))
  2.                  l (assoc 8 x)
  3.                  n (strcat (cdr l) "-N")
  4.            )


Code - Auto/Visual Lisp: [Select]
  1. (entmod (subst (cons 8 n) (assoc 8 x) x))

it references the items found by the user selection.
Title: Re: entmod not working
Post by: dgorsman on November 08, 2019, 03:24:33 PM
I usually put heavily nested statements on separate lines, so it's easier to follow the arguments.  Check the arguments required for the (subst ...) function, and what order they're in.
Title: Re: entmod not working
Post by: BIGAL on November 08, 2019, 08:27:54 PM
This is were vl is so much easier (vla-put-layer obj newlayer) and to understand.