TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: jlogan02 on January 12, 2021, 11:22:09 AM

Title: Routine requires an enter between picks.
Post by: jlogan02 on January 12, 2021, 11:22:09 AM
I'm trying to change overridden dimensions from their overridden color to another color. Not change the dimstyle, just the dims placed in the drawing.

The dimoverride command runs and allows me to pick the dimensions. It changes them just fine but doesn't move onto the next ssget without me hitting enter, but it works fine.

Now that I write that, that sounds like normal operation since I want the user to pick the objects that need to change. Can someone verify that for me?

I don't know...

If I switch them around the ssget col
Code - Auto/Visual Lisp: [Select]
for text, lines, and etc. runs then gives me the pickbox for the dims but won't actually pick the dims.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test (/ col col1 )
  2.  
  3.  (while (if (setq col1 (ssget "_:L" '((0 . "dimension"))))
  4.     (command "_.dimoverride" "dimclrd" 1 "dimclre" 1 "dimclrt" 1 "" col1 "")
  5.     )
  6.    )
  7.  
  8.   (setq col (ssget "_:L" '((0 . "MultiLeader,Hatch,*Line,*Text,Arc,Circle"))))
  9.         (foreach x (mapcar 'cadr (ssnamex col))
  10.         (entmod (append (entget x) '((62 . 1)))))
  11.  
  12.  
  13.   (princ)
  14. )

Any ideas.
Title: Re: Routine requires an enter between picks.
Post by: Tharwat on January 12, 2021, 01:36:20 PM
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test (/ col lst)  
  2.   (if (setq col (ssget "_:L" '((0 . "MultiLeader,Hatch,*Line,*Text,Arc,Circle,dimension"))))
  3.     (foreach x (vl-remove-if 'listp (mapcar 'cadr (ssnamex col)))
  4.       (if (= (strcase (cdr (assoc 0 (setq lst (entget x))))) "DIMENSION")
  5.         (command "_.dimoverride" "dimclrd" 1 "dimclre" 1 "dimclrt" 1 "" (ssadd x) "")
  6.         (entmod (append lst '((62 . 1))))
  7.         )
  8.       )
  9.     )
  10.   (princ)
  11. )
  12.  
Title: Re: Routine requires an enter between picks.
Post by: jlogan02 on January 14, 2021, 01:47:20 PM
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test (/ col lst)  
  2.   (if (setq col (ssget "_:L" '((0 . "MultiLeader,Hatch,*Line,*Text,Arc,Circle,dimension"))))
  3.     (foreach x (vl-remove-if 'listp (mapcar 'cadr (ssnamex col)))
  4.       (if (= (strcase (cdr (assoc 0 (setq lst (entget x))))) "DIMENSION")
  5.         (command "_.dimoverride" "dimclrd" 1 "dimclre" 1 "dimclrt" 1 "" (ssadd x) "")
  6.         (entmod (append lst '((62 . 1))))
  7.         )
  8.       )
  9.     )
  10.   (princ)
  11. )
  12.  

Thanks Tharwat,

Am I understanding the
Code - Auto/Visual Lisp: [Select]
correctly. It's adding all entities found in
Code - Auto/Visual Lisp: [Select]
  1. setq col
to the selection of dimoverride, and then entmoding those selections found for that selection?

So in effect using the opportunity given by the user prompt for selecting dims during the dimoverride?
Title: Re: Routine requires an enter between picks.
Post by: Tharwat on January 14, 2021, 01:56:11 PM
No, the ssadd function converts an entity to selection set and it is only for the dimension objects in this case although I think it would work without converting the entity to selection which means that you can replace the (ssadd x) with just the variable 'x' .

Entmod is used for all the object names that are included in the filter with ssget except the dimensions.
Title: Re: Routine requires an enter between picks.
Post by: jlogan02 on January 15, 2021, 05:18:14 PM
No, the ssadd function converts an entity to selection set and it is only for the dimension objects in this case although I think it would work without converting the entity to selection which means that you can replace the (ssadd x) with just the variable 'x' .

Entmod is used for all the object names that are included in the filter with ssget except the dimensions.

Dropping the
Code - Auto/Visual Lisp: [Select]
does indeed work. Thanks.

I have several versions of this to make. The next version would select all objects colored RED and change them to 56. Each subsequent version would do the same, color 56 to 136, 136 to 191, 191 to 107.

so...RED to color 56
Code - Auto/Visual Lisp: [Select]
  1.  (if (setq col (ssget "_X" '((62 . 1)(0 . "MultiLeader,Hatch,*Line,*Text,Arc,Circle,dimension"))))
  2.     (foreach x (vl-remove-if 'listp (mapcar 'cadr (ssnamex col)))
  3.       (if (= (strcase (cdr (assoc 0 (setq lst (entget x))))) "DIMENSION")
  4.         (command "_.dimoverride" "dimclrd" 56 "dimclre" 56 "dimclrt" 56 "" (ssadd x) "")
  5.         (entmod (append lst '((62 . 56))))
  6.        )
  7.      )
  8.    )

Changed
Code - Auto/Visual Lisp: [Select]
  1. (setq col (ssget "_:L" '((0 . "MultiLeader,Hatch,*Line,*Text,Arc,Circle,dimension"))))
to
Code - Auto/Visual Lisp: [Select]
  1. (setq col (ssget "_X" '((62 . 1)(0 . "MultiLeader,Hatch,*Line,*Text,Arc,Circle,dimension"))))
;;;get all red objects

and changed the color numbers from
Code - Auto/Visual Lisp: [Select]
  1. (command "_.dimoverride" "dimclrd" 1 "dimclre" 1 "dimclrt" 1 "" (ssadd x) "")
  2.         (entmod (append lst '((62 . 1))))
to
Code - Auto/Visual Lisp: [Select]
  1. (command "_.dimoverride" "dimclrd" 56 "dimclre" 56 "dimclrt" 56 "" (ssadd x) "")
  2.         (entmod (append lst '((62 . 56))))

Either I've dropped something and am not seeing it. Or I'm missing code and don't know it.

If I leave out the (62 . 1) from the code it changes everything including objects I don't want changed. If I include (62 . 1) it changes all red objects to color 56 but dimensions.


Title: Re: Routine requires an enter between picks.
Post by: Tharwat on January 15, 2021, 05:33:31 PM
Your mods should work without any issue I believe.

But the objects that didn't change to the new color 56 may were on Red color by layer and if so, then you need to go with different selection set by iterating the layer table and get the layer names that set with red color then add the list into the filter of the selection set.

Difficult?  :no:
Title: Re: Routine requires an enter between picks.
Post by: jlogan02 on January 15, 2021, 05:51:51 PM
Let me verify that and get back to you.
Title: Re: Routine requires an enter between picks.
Post by: jlogan02 on January 15, 2021, 06:03:52 PM
Drew an line on a layer with layer color set to red - Fail.
Drew a line on a layer and changed the lines color property to red using the code you helped me with earlier - Success.

Did the same with a dimensions.
Dim on Layer with layer color set to red - failed.
Dim on Layer with overridden dimclrt, dimclre, dimclrd to red - failed.

We have one layer that uses color bylayer RED. I can deal with that.


Title: Re: Routine requires an enter between picks.
Post by: jlogan02 on January 15, 2021, 06:06:54 PM
Full code

Code - Auto/Visual Lisp: [Select]
  1. (defun c:ST01to56 (/ *error* col lst osm )
  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.   (if (setq col (ssget "_X" '((0 . "MultiLeader,Hatch,*Line,*Text,Arc,Circle,dimension")(62 . 1))))
  37.     (foreach x (vl-remove-if 'listp (mapcar 'cadr (ssnamex col)))
  38.       (if (= (strcase (cdr (assoc 0 (setq lst (entget x))))) "DIMENSION")
  39.         (command "_.dimoverride" "dimclrd" 56 "dimclre" 56 "dimclrt" 56 "" (ssadd x) "")
  40.         (entmod (append lst '((62 . 56))))
  41.        )
  42.      )
  43.    )
  44.  
  45.   (_addlayer "FiberMgt_056" 56 "Continous" 1)
  46.  
  47.   (if (setq fm1 (ssget "x" '((8 . "FiberMgt_001"))))
  48.     (foreach x (mapcar 'cadr (ssnamex fm1))
  49.        (entmod (append (entget x) '((8 . "FiberMgt_056"))))
  50.     )
  51.   )
  52.  
  53.     ;;(command ".-layer" "filter" "edit" "Stations Standard Layers" "add" "FiberMgt_056" "exit" "")
  54.  
  55.  
  56.   (if (tblsearch "LAYER" "FiberMgt_001")
  57.     (command "-laydel" "_n" "FiberMgt_001" "" "Y" "")
  58.   )
  59.  
  60.   (command ".-layer" "filter" "edit" "Stations Standard Layers" "add" "FiberMgt_056" "exit" "")
  61.  
  62.   (setvar 'osmode osm)
  63.   (setvar 'cmdecho 1)
  64.  
  65.   (princ)
  66. )
Title: Re: Routine requires an enter between picks.
Post by: Tharwat on January 16, 2021, 06:47:23 AM
Hi,
Rectify this:
Code - Auto/Visual Lisp: [Select]
  1.  (mapcar 'cadr (ssnamex fm1))
With this:
Code - Auto/Visual Lisp: [Select]
  1. (vl-remove-if 'listp (mapcar 'cadr (ssnamex fm1)))
  2.  
Title: Re: Routine requires an enter between picks.
Post by: ronjonp on January 16, 2021, 11:00:33 PM
Hi,
Rectify this:
Code - Auto/Visual Lisp: [Select]
  1.  (mapcar 'cadr (ssnamex fm1))
With this:
Code - Auto/Visual Lisp: [Select]
  1. (vl-remove-if 'listp (mapcar 'cadr (ssnamex fm1)))
  2.  
@Tharwat you don't need the vl-remove-if when "_X" is used in ssget.
Title: Re: Routine requires an enter between picks.
Post by: Tharwat on January 17, 2021, 03:53:41 AM
Thanks Ron, you are right.
But what makes that difference once using that string mode in your opinion ?
Title: Re: Routine requires an enter between picks.
Post by: Tharwat on January 17, 2021, 03:55:35 AM
Logan,
Please upload the same drawing that you tested your codes out on to take a close look if possible.
Title: Re: Routine requires an enter between picks.
Post by: ronjonp on January 18, 2021, 02:34:47 PM
Thanks Ron, you are right.
But what makes that difference once using that string mode in your opinion ?
I'm not sure I understand your question.
Title: Re: Routine requires an enter between picks.
Post by: Tharwat on January 18, 2021, 02:45:09 PM
Once using the ssget "_X" then there is no need to use (vl-remove-if 'listp ... but with the ssget "_:L" for instance there is a need to use (vl-remove-if 'listp  since the return of the ssnamex would return the last item in the list as a list.

I have read about ssget and ssnamex functions and nothing was written in regard of such a return or so.
Title: Re: Routine requires an enter between picks.
Post by: Lee Mac on January 18, 2021, 06:53:45 PM
I have read about ssget and ssnamex functions and nothing was written in regard of such a return or so.

The ssnamex function returns information describing the method used to acquire the selection; for graphical selection methods, this will include the coordinates of selection windows etc. however, since the X mode string is not a graphical selection method and will iterate directly over the drawing database, only the entity names are returned as there isn't any other relevant selection information.
Title: Re: Routine requires an enter between picks.
Post by: Tharwat on January 19, 2021, 04:26:20 AM
Thanks Lee, that explained it beautifully.
Title: Re: Routine requires an enter between picks.
Post by: jlogan02 on January 19, 2021, 01:57:57 PM
Your mods should work without any issue I believe.

But the objects that didn't change to the new color 56 may were on Red color by layer and if so, then you need to go with different selection set by iterating the layer table and get the layer names that set with red color then add the list into the filter of the selection set.

Difficult?  :no:

I wasn't reading what you said here, all the way through. I got the other color routines to work, but had to make sure that any dimension that was selected had it's layer color set to RED. Then the remainder of the routines would just look at the properties of the layer color for selected objects and change them.

added this...
Code - Auto/Visual Lisp: [Select]
  1.   (if (setq col (ssget "_X" '((62 . 1)(0 . "MultiLeader,Hatch,*Line,*Text,Arc,Circle,dimension"))))
  2.     (foreach x (mapcar 'cadr (ssnamex col)))
  3.       (if (= (strcase (cdr (assoc 0 (setq lst (entget x))))) "DIMENSION")
  4.         (command "_.dimoverride" "dimclrd" 56 "dimclre" 56 "dimclrt" 56 "" (ssadd x) "")
  5.         (entmod (append lst '((62 . 56))))
  6.        )
  7.      )
  8.    )

added

Code - Auto/Visual Lisp: [Select]
  1.   (setq col2 (ssget "_X" '((62 . 1)(0 . "dimension"))))
  2.   (command "chprop" col2 "" "color" "56" "")

Then I'll set color back to bylayer at Record Issue.

Cheers. Thanks for the help guys.
 
Title: Re: Routine requires an enter between picks.
Post by: jlogan02 on January 21, 2021, 01:29:20 PM

Full code

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test1 (/ *error* col fm1 osm col2)
  2.  (defun *error* (msg)
  3.    
  4.     (if osm
  5.       (setvar 'osmode osm)
  6.     )
  7.     (if (not (member msg '("Function cancelled" "quit / exit abort")))
  8.      
  9.       (princ (strcat "\nError: " msg))
  10.     )
  11.     (princ)
  12.   )
  13.   (setq osm (getvar 'osmode))
  14.   (setvar 'osmode 0)
  15.   (setvar 'cmdecho 0)
  16.  
  17.   (if (setq col (ssget "X" '((0 . "MultiLeader,Hatch,*Line,*Text,Arc,Circle,dimension"))))
  18.     (foreach x (vl-remove-if 'listp (mapcar 'cadr (ssnamex col)))
  19.       (if (= (strcase (cdr (assoc 0 (setq lst (entget x))))) "DIMENSION")
  20.         (command "_.dimoverride" "dimclrd" 2 "dimclre" 2 "dimclrt" 3 "" (ssadd x) "")
  21.         (entmod (append lst '((62 . 256))))
  22.         )
  23.       )
  24.     )
  25.  
  26.   (if (tblsearch "LAYER" "FiberMgt_001") ;Check if the layer exists
  27.     (progn
  28.         (setq fm1 (ssget "x" '((8 . "FiberMgt_001"))))
  29.         (foreach x (mapcar 'cadr (ssnamex fm1)) (entmod (append (entget x) '((8 . "FiberMgt"))))
  30.           (command "-layer" "Make" "FiberMgt" "Color" "Yellow" "" "")
  31.           (command "-color" "ByLayer")
  32.          
  33.     );;End foreach
  34.    );;end progn
  35.   );;end if
  36.  
  37.   (setq col2 (ssget "_X" '((62 . 1)(0 . "dimension")(8 . "DIMEN")))
  38.   (command "chprop" col2 "" "color" "256" "layer" "DIMEN" "" "")
  39.  
  40. (if (tblsearch "LAYER" "FiberMgt_001")
  41.  (command "-laydel" "_n" "FiberMgt_001" "" "_y")
  42. )
  43.  
  44.  
  45.   (setvar 'osmode osm)
  46.   (setvar 'cmdecho 1)
  47.  
  48.  (princ)
  49. )
Title: Re: Routine requires an enter between picks.
Post by: jlogan02 on January 21, 2021, 01:37:28 PM
Logan,
Please upload the same drawing that you tested your codes out on to take a close look if possible.