Author Topic: Enter causes routine to run on last items picked with unexpected results.  (Read 756 times)

0 Members and 1 Guest are viewing this topic.

jlogan02

  • Bull Frog
  • Posts: 327
After I run this once I hit an enter to run it again and pick other objects, but instead of allowing me to pick another entity it is running the routine a second time on the first set of entities and pushing them back to the original layer minus the -F.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:futlyr ( / i lyrname s x )
  2. (prompt "\nSelect Object to Set to -F Construction Layer")
  3.    (setq s (ssget ":L" '((8 . "S*"))))
  4.         (repeat (setq i (sslength s))
  5.         (setq x (entget (ssname s (setq i (1- i))))
  6.               lyrname (cdr (assoc 8 x))
  7.               n (strcat (substr lyrname 1 (- (strlen lyrname) 0)) "-F") ;;(strlen old_suffix)))))
  8.         )
  9.             (if (not (tblsearch "layer" n))
  10.               (progn (setq e (entget (tblobjname "layer" lyrname)))
  11.                (entmake (subst (cons 2 n) (assoc 2 e) (subst '(62 . 1) (assoc 62 e) e)))
  12.               )
  13.             )
  14.               (entmod (subst (cons 8 n) (assoc 8 x) x))
  15.           )  
  16.  
  17.   (prompt "\nAll objects have been moved to -F construction layer")
  18.   (princ)
  19. )
  20.  
  21. (c:futlyr)

J. Logan
ACAD 2018

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

mhupp

  • Bull Frog
  • Posts: 250
Their is nothing in the code to push them back (error handling?). All tho you can select things multiple times. ending up with layers like "layername-F-F-F"

Added a check to exclude items that are on a layer ending with "-F"
and gives a count of how many things have changed layers

Code - Auto/Visual Lisp: [Select]
  1. (defun c:futlyr (/ s layname x n i)
  2.   (prompt "\nSelect Object to Set to -F Construction Layer")
  3.   (setq i 0)
  4.   (setq s (ssget ":L" '((8 . "S*"))))
  5.   (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
  6.     (if (and (setq layname (cdr (assoc 8 (setq x (entget ent))))) (/= (substr layname (- (strlen layname) 1)) "-F"))
  7.       (progn
  8.         (if (not (tblsearch "layer" (setq n (strcat layname "-F"))))
  9.           (progn
  10.             (setq e (entget (tblobjname "layer" layname)))
  11.             (entmake (subst (cons 2 n) (assoc 2 e) (subst '(62 . 1) (assoc 62 e) e)))
  12.           )
  13.         )
  14.         (entmod (subst (cons 8 n) (assoc 8 x) x))
  15.         (setq i (1+ i))
  16.       )  
  17.     )
  18.   )
  19.   (prompt (strcat "\n" (itoa i) " objects moved to -F construction layer"))
  20.   (princ)
  21. )

jlogan02

  • Bull Frog
  • Posts: 327
Man, my whole post was wonky. I wrote it once asking about the multiple -Fs. Then decided to try and remove the entmake section as a test because I don't need it changing the color to red. When I removed it, I got the enter issue.

I forgot to remove that section from my post before.

Code - Auto/Visual Lisp: [Select]
  1. (if (not (tblsearch "layer" n))
  2.               (progn (setq e (entget (tblobjname "layer" lyrname)))
  3.                (entmake (subst (cons 2 n) (assoc 2 e) (subst '(62 . 1) (assoc 62 e) e)))
  4.               )
  5.             )

Thanks for adding the check. That went through my mind earlier in the day but didn't get it done.
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
You can also filter out the items directly like so:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:futlyr (/ e i layname n s x)
  2.   (prompt "\nSelect Object to Set to -F Construction Layer")
  3.   (setq i 0)
  4.   ;; Direct filter for layer that starts with S and does not end in -F
  5.   (if (setq s (ssget ":L" '((8 . "S*,") (8 . "~*-F"))))
  6.     (progn
  7.       (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
  8.         (if (setq layname (cdr (assoc 8 (setq x (entget ent)))))
  9.           (progn (if (not (tblsearch "layer" (setq n (strcat layname "-F"))))
  10.                    (progn (setq e (entget (tblobjname "layer" layname)))
  11.                           (entmake (subst (cons 2 n) (assoc 2 e) (subst '(62 . 1) (assoc 62 e) e)))
  12.                    )
  13.                  )
  14.                  (entmod (subst (cons 8 n) (assoc 8 x) x))
  15.                  (setq i (1+ i))
  16.           )
  17.         )
  18.       )
  19.       (prompt (strcat "\n" (itoa i) " objects moved to -F construction layer"))
  20.     )
  21.   )
  22.   (princ)
  23. )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC