Author Topic: entmod not working  (Read 2947 times)

0 Members and 1 Guest are viewing this topic.

jlogan02

  • Bull Frog
  • Posts: 327
entmod not working
« 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
J. Logan
ACAD 2018

I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10

ronjonp

  • Needs a day job
  • Posts: 7526
Re: entmod not working
« Reply #1 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))))
« Last Edit: November 08, 2019, 12:05:04 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

tombu

  • Bull Frog
  • Posts: 288
  • ByLayer=>Not0
Re: entmod not working
« Reply #2 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)))
Tom Beauford P.S.M.
Leon County FL Public Works - Windows 7 64 bit AutoCAD Civil 3D

jlogan02

  • Bull Frog
  • Posts: 327
Re: entmod not working
« Reply #3 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???   
J. Logan
ACAD 2018

I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10

ronjonp

  • Needs a day job
  • Posts: 7526
Re: entmod not working
« Reply #4 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.            )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

jlogan02

  • Bull Frog
  • Posts: 327
Re: entmod not working
« Reply #5 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.
J. Logan
ACAD 2018

I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: entmod not working
« Reply #6 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.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

BIGAL

  • Swamp Rat
  • Posts: 1396
  • 40 + years of using Autocad
Re: entmod not working
« Reply #7 on: November 08, 2019, 08:27:54 PM »
This is were vl is so much easier (vla-put-layer obj newlayer) and to understand.
A man who never made a mistake never made anything