Author Topic: User Select multiple objects and change prop of each differently  (Read 4552 times)

0 Members and 1 Guest are viewing this topic.

jlogan02

  • Bull Frog
  • Posts: 327
User Select multiple objects and change prop of each differently
« on: November 20, 2019, 08:42:17 PM »
I'm not sure I can ask this question without confusing everyone, since I confuse myself when trying to word it.

I have blocks that when inserted insert on a specific layer, color Bylayer (RED). At the same time I might have lines, text, hatch and revclouds all on their own assigned layers with their color changed to red.

I want to...
Code - Auto/Visual Lisp: [Select]
  1. (setq SS1 (ssget));;user selects for the blocks
  2. (setq SS2 (ssget));;user selects for all other objects
  3. ;;then I want to...
  4. (command "._change" SS1 "" "P" "la" "FiberMgt_015" "");;or entmod
  5. (command "._change" SS2 "" "P" "C" "15" "");;or entmod

I'm can't seem to do this without separate lisps.

Something like this
Code - Auto/Visual Lisp: [Select]
  1. (defun C:Foo (/ ss1 ss2)
  2.  (defun _addlayer (name color ltype plot)
  3.     (cond ((not (tblsearch "layer" name))
  4.            (entmakex (list '(0 . "LAYER")
  5.                            '(100 . "AcDbSymbolTableRecord")
  6.                            '(100 . "AcDbLayerTableRecord")
  7.                            '(70 . 0)
  8.                            (cons 2 name)
  9.                            (cons 62 color)
  10.                            (cons 6
  11.                                  (cond ((tblobjname "ltype" ltype))
  12.                                        ("continuous")
  13.                                  )
  14.                            )
  15.                            (cons 290 plot)
  16.                            ;;1 = plottable 0 = not=plottable
  17.                      )
  18.            )
  19.           )
  20.           ((tblobjname "layer" name))
  21.     )
  22.   )
  23. ;;error checking and setvar getvars here...
  24.  
  25.    (_addlayer "FiberMgt_001" 1 "Continous" 1)
  26.    (_addlayer "FiberMgt_015" 15 "Continous" 1)
  27.  
  28. ;;create a layer filter
  29.  
  30. ;;user selects the objects.

Maybe it's an
Code - Auto/Visual Lisp: [Select]
  1. (if user selects blocks, do this
  2.  (and if user selects *lines, *text, etc., do this)

It's late. Or quitting time and I think I might have just answered my own question with that last bit. Don't know. I'll let someone confirm or deny.
 
J. Logan
ACAD 2018

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

kpblc

  • Bull Frog
  • Posts: 396
Re: User Select multiple objects and change prop of each differently
« Reply #1 on: November 21, 2019, 12:03:21 AM »
Maybe something like this?
Code - Auto/Visual Lisp: [Select]
  1. (setq selset (ssget))
  2. (foreach ent ((lambda (/ tab item)
  3.                 (repeat (setq tab  nil
  4.                               item (sslength selset)
  5.                               ) ;_ end setq
  6.                   (setq tab (cons (ssname selset (setq item (1- item))) tab))
  7.                   ) ;_ end of repeat
  8.                 ) ;_ end of lambda
  9.               )
  10.   (cond ((= (cdr (assoc 0 (entget ent))) "INSERT")
  11.          ;; do smth
  12.          )
  13.         ((= (cdr (assoc 0 (entget ent))) "LINE")
  14.          ;; do smth else
  15.          )
  16.         ((wcmatch (cdr (assoc 0 (entget ent))) "*TEXT")
  17.          ;; do smth part 3
  18.          )
  19.         ) ;_ end of cond
  20.   ) ;_ end of foreach
Sorry for my English.

jlogan02

  • Bull Frog
  • Posts: 327
Re: User Select multiple objects and change prop of each differently
« Reply #2 on: November 21, 2019, 12:54:45 PM »
This works quite well...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo6 (/ osm SELSET)
  2. (defun _addlayer (name color ltype plot)
  3.     (cond ((not (tblsearch "layer" name))
  4.            (entmakex (list '(0 . "LAYER")
  5.                            '(100 . "AcDbSymbolTableRecord")
  6.                            '(100 . "AcDbLayerTableRecord")
  7.                            '(70 . 0)
  8.                            (cons 2 name)
  9.                            (cons 62 color)
  10.                            (cons 6
  11.                                  (cond ((tblobjname "ltype" ltype))
  12.                                        ("continuous")
  13.                                  )
  14.                            )
  15.                            (cons 290 plot)
  16.                            ;;1 = plottable 0 = not=plottable
  17.                      )
  18.            )
  19.           )
  20.           ((tblobjname "layer" name))
  21.     )
  22.   )
  23.   (defun *error* (msg)
  24.     (if osm
  25.       (setvar 'osmode osm)
  26.     )
  27.     (if (not (member msg '("Function cancelled" "quit / exit abort")))
  28.       (princ (strcat "\nError: " msg))
  29.     )
  30.     (princ)
  31.   )
  32.   (setq osm (getvar 'osmode))
  33.   (setvar 'osmode 0)
  34.   (setvar 'cmdecho 0)
  35.  
  36.    ;;(_addlayer "FiberMgt_001" 1 "Continous" 1)
  37.    (_addlayer "FiberMgt_015" 15 "Continous" 1)
  38.          
  39.  
  40.   ;; Assign FiberMgt layer to layer filter
  41.          (command ".-layer"
  42.                   "filter"
  43.                   "edit"
  44.                   "Stations Standard Layers"
  45.                   "add"
  46.                   "FiberMgt_015"
  47.                   "exit"
  48.                   (command)
  49.                   (command)
  50.          )
  51.  
  52. (setq selset (ssget))
  53.  (foreach ent ((lambda (/ tab item)
  54.                 (repeat (setq tab  nil
  55.                               item (sslength selset)
  56.                               ) ;_ end setq
  57.                   (setq tab (cons (ssname selset (setq item (1- item))) tab))
  58.                   ) ;_ end of repeat
  59.                 ) ;_ end of lambda
  60.               )
  61.   (cond ((= (cdr (assoc 0 (entget ent))) "INSERT")
  62.          (command "._change" ent "" "P" "la" "Fibermgt_015" "");; do smth
  63.          )
  64.         ((= (cdr (assoc 0 (entget ent))) "LINE")
  65.          (command "._change" ent "" "P" "C" "15" "");; do smth else
  66.          )     
  67.                   ((= (cdr (assoc 0 (entget ent))) "CIRCLE")
  68.          (command "._change" ent "" "P" "C" "15" "");; do smth else
  69.          )
  70.                   ((= (cdr (assoc 0 (entget ent))) "POLYLINE")
  71.          (command "._change" ent "" "P" "C" "15" "");; do smth else
  72.          )
  73.                   ((= (cdr (assoc 0 (entget ent))) "ARC")
  74.          (command "._change" ent "" "P" "C" "15" "");; do smth else
  75.          )
  76.         ((wcmatch (cdr (assoc 0 (entget ent))) "TEXT,MTEXT")
  77.          (command "._change" ent "" "P" "C" "15" "");; do smth part 3
  78.          )
  79.         ) ;_ end of cond
  80.   ) ;_ end of foreach
  81.                 (princ)
  82. )
  83. )

Can't seem to get polylines not matter if I put them in a line by themselves or combined as...

Code - Auto/Visual Lisp: [Select]
  1. (entget ent))) "line,polyline,arc,circle"...

but yet doing the same with TEXT,MTEXT works fine.
J. Logan
ACAD 2018

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

Dlanor

  • Bull Frog
  • Posts: 263
Re: User Select multiple objects and change prop of each differently
« Reply #3 on: November 21, 2019, 04:37:50 PM »
"POLYLINE" refers to a specific type of polyline. If you want all polylines use "*POLYLINE" (LW, 2D, 3D and POLYLINE). If you only want LWPOLYLINES the use "LWPOLYLINE"

ronjonp

  • Needs a day job
  • Posts: 7526
Re: User Select multiple objects and change prop of each differently
« Reply #4 on: November 21, 2019, 04:47:21 PM »
Give this a try .. put in a few comments.
Code - Auto/Visual Lisp: [Select]
  1. (if (setq selset (ssget '((0 . "ARC,CIRCLE,LINE,POLYLINE,TEXT,MTEXT"))))
  2.   (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex selset)))
  3.     (cond ((= (cdr (assoc 0 (setq el (entget ent)))) "INSERT")
  4.            (entmod (append el '((8 . "Fibermgt_015"))))
  5.            ;; (command "._change" ent "" "P" "la" "Fibermgt_015" "")
  6.            ;; do smth
  7.           )
  8.           ;; The code below uses '=' .. you need wcmatch to check multiple items at once
  9.           ((wcmatch (cdr (assoc 0 el)) "ARC,CIRCLE,LINE,POLYLINE,TEXT,MTEXT")
  10.            ;; (command "._change" ent "" "P" "C" "15" "")
  11.            ;; Use entmod instead of command calls
  12.            (entmod (append el '((62 . 15))))
  13.            ;; do smth else
  14.           )
  15. ;;;      ((= (cdr (assoc 0 (entget ent))) "CIRCLE")
  16. ;;;       (command "._change" ent "" "P" "C" "15" "")
  17. ;;;       ;; do smth else
  18. ;;;      )
  19. ;;;      ((= (cdr (assoc 0 (entget ent))) "POLYLINE")
  20. ;;;       (command "._change" ent "" "P" "C" "15" "")
  21. ;;;       ;; do smth else
  22. ;;;      )
  23. ;;;      ((= (cdr (assoc 0 (entget ent))) "ARC")
  24. ;;;       (command "._change" ent "" "P" "C" "15" "")
  25. ;;;       ;; do smth else
  26. ;;;      )
  27.     ) ;_ end of cond
  28.   ) ;_ end of foreach
  29.   (princ)
  30. )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

jlogan02

  • Bull Frog
  • Posts: 327
Re: User Select multiple objects and change prop of each differently
« Reply #5 on: November 21, 2019, 05:02:25 PM »
Posting at the same time Ron...


Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo6 (/ ELST ENTTYPE OSM SELSET)
  2. (defun _addlayer (name color ltype plot)
  3.     (cond ((not (tblsearch "layer" name))
  4.            (entmakex (list '(0 . "LAYER")
  5.                            '(100 . "AcDbSymbolTableRecord")
  6.                            '(100 . "AcDbLayerTableRecord")
  7.                            '(70 . 0)
  8.                            (cons 2 name)
  9.                            (cons 62 color)
  10.                            (cons 6
  11.                                  (cond ((tblobjname "ltype" ltype))
  12.                                        ("continuous")
  13.                                  )
  14.                            )
  15.                            (cons 290 plot)
  16.                            ;;1 = plottable 0 = not=plottable
  17.                      )
  18.            )
  19.           )
  20.           ((tblobjname "layer" name))
  21.     )
  22.   )
  23.   (defun *error* (msg)
  24.     (if osm
  25.       (setvar 'osmode osm)
  26.     )
  27.     (if (not (member msg '("Function cancelled" "quit / exit abort")))
  28.       (princ (strcat "\nError: " msg))
  29.     )
  30.     (princ)
  31.   )
  32.   (setq osm (getvar 'osmode))
  33.   (setvar 'osmode 0)
  34.   (setvar 'cmdecho 0)
  35.  
  36.    (_addlayer "FiberMgt_001" 1 "Continous" 1)
  37.    (_addlayer "FiberMgt_015" 15 "Continous" 1)
  38.          
  39.  
  40.   ;; Assign FiberMgt layer to layer filter
  41.          (command ".-layer"
  42.                   "filter"
  43.                   "edit"
  44.                   "Stations Standard Layers"
  45.                   "add"
  46.                   "FiberMgt_015"
  47.                   "exit"
  48.                   (command)
  49.                   (command)
  50.          )
  51.  
  52. (setq selset (ssget))
  53.  (foreach ent ((lambda (/ tab item)
  54.                 (repeat (setq tab  nil
  55.                               item (sslength selset)
  56.                               ) ;_ end setq
  57.                   (setq tab (cons (ssname selset (setq item (1- item))) tab))
  58.                   ) ;_ end of repeat
  59.                 ) ;_ end of lambda
  60.               )
  61.   (cond ((= (cdr (assoc 0 (entget ent))) "INSERT")
  62.          (command "._change" ent "" "P" "la" "Fibermgt_015" "");; do smth
  63.          )
  64.         ((= (cdr (assoc 0 (entget ent))) "LINE")
  65.          (command "._change" ent "" "P" "C" "15" "");; do smth else
  66.          )     
  67.                   ((= (cdr (assoc 0 (entget ent))) "CIRCLE")
  68.          (command "._change" ent "" "P" "C" "15" "");; do smth else
  69.          )
  70.                   ((= (cdr (assoc 0 (entget ent))) "ARC")
  71.          (command "._change" ent "" "P" "C" "15" "");; do smth else
  72.          )
  73.         ((wcmatch (cdr (assoc 0 (entget ent))) "TEXT,MTEXT")
  74.          (command "._change" ent "" "P" "C" "15" "");; do smth part 3
  75.                         )
  76.                 ;;check for entsel selection
  77.      ((wcmatch (cdr (assoc 0 (entget ent))) "*POLYLINE");;added this...
  78.          (command "._change" ent "" "P" "C" "15" "")
  79.                    )
  80.         ) ;_ end of cond
  81.   ) ;_ end of foreach
  82.                 (princ)
  83. )

Did a little searching and found you're example

Code - Auto/Visual Lisp: [Select]
  1. Re: Function if with entget confusion
  2. « Reply #1 on: July 03, 2010, 04:08:45 PM »
  3. See if this helps you out:
  4.  
  5. Code: [Select]
  6. (setq ss (ssget ":s" '((0 . "*polyline"))));;filter selection
  7. (setq ent (ssname ss 0));;grab ename
  8.  
  9. ;;check for entsel selection
  10. (if (wcmatch (cdr (assoc 0 (entget ent))) "*POLYLINE")
  11.   (alert "Im a happy polyline")
  12. )
  13.  

From this thread in the wayyy back...http://www.theswamp.org/index.php?topic=34004.0

I was going to test (wcmatch just as you mentioned it..

Code - Auto/Visual Lisp: [Select]
  1.      ;; The code below uses '=' .. you need wcmatch to check multiple items at once
  2.           ((wcmatch (cdr (assoc 0 el)) "ARC,CIRCLE,LINE,POLYLINE,TEXT,MTEXT")
  3.            ;; (command "._change" ent "" "P" "C" "15" "")
  4.            ;; Use entmod instead of command calls
  5.            (entmod (append el '((62 . 15))))
  6.            ;; do smth else
  7.           )

But you're too damned fast. Thanks for answering the wcmatch question without me asking.
Code - Auto/Visual Lisp: [Select]
again!!! :-D Nice. I figured there had to be a better way than command calls...

Thanks guys for your help.
J. Logan
ACAD 2018

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

jlogan02

  • Bull Frog
  • Posts: 327
Re: User Select multiple objects and change prop of each differently
« Reply #6 on: November 21, 2019, 05:07:53 PM »
I think I have a tendency to over complicate things.

I looked at
Code - Auto/Visual Lisp: [Select]
when comparing why

Code - Auto/Visual Lisp: [Select]
  1.  ((wcmatch (cdr (assoc 0 (entget ent))) "TEXT,MTEXT")
worked.

Then when I tested it, I must have missed something or typed something wrong within that line of code because it still didn't work, but didn't realize I made a mistake, I just assumed it was the wrong application.



J. Logan
ACAD 2018

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

jlogan02

  • Bull Frog
  • Posts: 327
Re: User Select multiple objects and change prop of each differently
« Reply #7 on: November 21, 2019, 07:50:22 PM »
I must be missing something in the "(cond...statement.
Blocks don't get selected. I've stared at it long enough. I just don't see it...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo7...
  2.  
  3. ;; this cond statement doesn't seem to work. Block does not get selected.
  4.     (cond ((= (cdr (assoc 0 (setq el (entget ent)))) "INSERT")
  5.            (entmod (append el '((8 . "FiberMgt_015"))))
  6.           )...
  7.          
  8.          
  9.         ...);; end cond
  10.          );; end foreach
  11.   );; added missing ")" for "if"
  12.   (princ)
  13.   )
J. Logan
ACAD 2018

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

Dlanor

  • Bull Frog
  • Posts: 263
Re: User Select multiple objects and change prop of each differently
« Reply #8 on: November 21, 2019, 09:03:26 PM »
You're appending a layer to something that already has a layer. You need to substitute the new layer for the old layer.

Code - Auto/Visual Lisp: [Select]
  1. (entmod (subst '(8 . "FiberMgt_015") (assoc 8 el) el))
« Last Edit: November 21, 2019, 09:13:06 PM by Dlanor »

ronjonp

  • Needs a day job
  • Posts: 7526
Re: User Select multiple objects and change prop of each differently
« Reply #9 on: November 23, 2019, 10:22:51 AM »
I must be missing something in the "(cond...statement.
Blocks don't get selected. I've stared at it long enough. I just don't see it...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo7...
  2.  
  3. ;; this cond statement doesn't seem to work. Block does not get selected.
  4.     (cond ((= (cdr (assoc 0 (setq el (entget ent)))) "INSERT")
  5.            (entmod (append el '((8 . "FiberMgt_015"))))
  6.           )...
  7.          
  8.          
  9.         ...);; end cond
  10.          );; end foreach
  11.   );; added missing ")" for "if"
  12.   (princ)
  13.   )
You need to add 'insert' to the selection filter:
Code - Auto/Visual Lisp: [Select]
  1. (setq selset (ssget '((0 . "ARC,CIRCLE,INSERT,LINE,POLYLINE,TEXT,MTEXT"))))

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

snownut2

  • Swamp Rat
  • Posts: 971
  • Bricscad 22 Ultimate
Re: User Select multiple objects and change prop of each differently
« Reply #10 on: November 23, 2019, 02:34:46 PM »
FYI 

Code - Auto/Visual Lisp: [Select]
  1.    "*line*"
  2.  

Also works to include all line entities...

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: User Select multiple objects and change prop of each differently
« Reply #11 on: November 23, 2019, 03:07:59 PM »
FYI 

Code - Auto/Visual Lisp: [Select]
  1.    "*line*"
  2.  

Also works to include all line entities...

FYI, that will also match SPLINE.

jlogan02

  • Bull Frog
  • Posts: 327
Re: User Select multiple objects and change prop of each differently
« Reply #12 on: December 02, 2019, 06:40:41 PM »
Sorry, I didn't get back to you all sooner. Holidays...

Anyway. Thanks for the help. All is working fine. I added hatches to the selection as well. Other than that, nothing changed.

Thanks again.
J. Logan
ACAD 2018

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