TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: PM on July 15, 2021, 02:50:31 AM

Title: help with an alert box message
Post by: PM on July 15, 2021, 02:50:31 AM
I am using this lisp. This code try to find  "_WATER LINE" and then start. I want to add an alert message box incase this layer does not exist and say that this layer does not exist in this drawing. I dont want to create it just alert.

Code - Auto/Visual Lisp: [Select]
  1.     (vl-load-com)
  2.     (defun c:symbsxim (/ selset offset_value loops hatch layer)
  3.       (if (and (= (type
  4.                     (setq selset (vl-catch-all-apply
  5.                                    (function
  6.                                      (lambda ()
  7.                                        (ssget '((0 . "*POLYLINE") (8 . "_WATER LINE") (-4 . "<OR") (70 . 1) (70 . 129) (-4 . "OR>")))
  8.                                      ) ;_ end of lambda
  9.                                    ) ;_ end of function
  10.                                  ) ;_ end of vl-catch-all-apply
  11.                     ) ;_ end of setq
  12.                   ) ;_ end of type
  13.                   'pickset
  14.                ) ;_ end of =
  15.                (= (type (setq offset_value
  16.                                (vl-catch-all-apply
  17.                                  (function (lambda ()
  18.                                              (initget "1 2")
  19.                                              (cond ((getkword "\nSelect offset value [1 - OPRION1 /2 - OPTION2] <1> : "))
  20.                                                    (t "1")
  21.                                              ) ;_ end of cond
  22.                                            ) ;_ end of lambda
  23.                                  ) ;_ end of function
  24.                                ) ;_ end of vl-catch-all-apply
  25.                         ) ;_ end of setq
  26.                   ) ;_ end of type
  27.                   'str
  28.                ) ;_ end of =
  29.           ) ;_ end of and
  30.                (setq layer (vla-add (vla-get-layers adoc) "POLYLINE LAYER"))
  31.                (vla-put-color layer 253) ; change color
  32.                (vla-put-lineweight layer aclnwt005) ; change lineweight
  33.                (setq offset_value (cond ((= (atoi offset_value) 1) 0.5)
  34.                                         ((= (atoi offset_value) 2) 2.0)
  35.                                   ) ;_ end of cond
  36.                      loops        (mapcar (function
  37.                                             (lambda (ent)
  38.                                               (vl-sort (mapcar (function (lambda (x)
  39.                                                                            (setq x (car (vlax-safearray->list (vlax-variant-value x))))
  40.                                                                            (vla-put-layer x (vla-get-name layer))
  41.                                                                            x
  42.                                                                          ) ;_ end of lambda
  43.                                                                ) ;_ end of function
  44.                                                                (list (vla-offset (vlax-ename->vla-object ent) offset_value)
  45.                                                                      (vla-offset (vlax-ename->vla-object ent) (- offset_value))
  46.                                                                ) ;_ end of list
  47.                                                        ) ;_ end of mapcar
  48.                                                        (function (lambda (a b) (> (vla-get-area a) (vla-get-area b))))
  49.                                               ) ;_ end of vl-sort
  50.                                             ) ;_ end of lambda
  51.                                           ) ;_ end of function
  52.                                           ((lambda (/ tab item)
  53.                                              (repeat (setq tab  nil
  54.                                                            item (sslength selset)
  55.                                                      ) ;_ end setq
  56.                                                (setq tab (cons (ssname selset (setq item (1- item))) tab))
  57.                                              ) ;_ end of repeat
  58.                                            ) ;_ end of lambda
  59.                                           )
  60.                                   ) ;_ end of mapcar
  61.                ) ;_ end of setq
  62.                (foreach item loops
  63.                  (setq hatch (vla-addhatch
  64.                                (vla-get-modelspace adoc)
  65.                                achatchpatterntypepredefined
  66.                                "ANSI31"
  67.                                :vlax-false
  68.                                achatchobject
  69.                              ) ;_ end of vla-AddHatch
  70.                  ) ;_ end of setq
  71.                  (vla-appendouterloop
  72.                    hatch
  73.                    (vlax-safearray-fill (vlax-make-safearray vlax-vbobject '(0 . 0)) (list (car item)))
  74.                  ) ;_ end of vla-appendouterloop
  75.                  (vla-appendinnerloop
  76.                    hatch
  77.                    (vlax-safearray-fill (vlax-make-safearray vlax-vbobject '(0 . 0)) (list (cadr item)))
  78.                  ) ;_ end of vla-appendinnerloop
  79.                  (vla-evaluate hatch)
  80.                  (vla-update hatch)
  81.                  (vla-put-patternscale hatch 0.1) ; change hatch scale
  82.                  (vla-put-layer hatch (vla-get-name layer))
  83.                ) ;_ end of foreach
  84.                (vla-endundomark adoc)
  85.         ) ;_ end of progn
  86.       ) ;_ end of if
  87.       (princ)
  88.     (command "_Setbylayer" (ssget "X") "" "_Yes" "_Yes")
  89.     ) ;_ end of defun    
  90.  
  91.  

Thanks
Title: Re: help with an alert box message
Post by: ribarm on July 15, 2021, 04:04:07 AM
Code - Auto/Visual Lisp: [Select]
  1. (defun c:symbsxim (/ selset offset_value loops hatch layer)
  2.       (if (tblsearch "LAYER" "_WATER LINE")
  3.             (if (and (= (type
  4.                           (setq selset (vl-catch-all-apply
  5.                                          (function
  6.                                            (lambda ()
  7.                                              (ssget '((0 . "*POLYLINE") (8 . "_WATER LINE") (-4 . "<OR") (70 . 1) (70 . 129) (-4 . "OR>")))
  8.                                            ) ;_ end of lambda
  9.                                          ) ;_ end of function
  10.                                        ) ;_ end of vl-catch-all-apply
  11.                           ) ;_ end of setq
  12.                         ) ;_ end of type
  13.                         'pickset
  14.                      ) ;_ end of =
  15.                      (= (type (setq offset_value
  16.                                      (vl-catch-all-apply
  17.                                        (function (lambda ()
  18.                                                    (initget "1 2")
  19.                                                    (cond ((getkword "\nSelect offset value [1 - OPRION1 /2 - OPTION2] <1> : "))
  20.                                                          (t "1")
  21.                                                    ) ;_ end of cond
  22.                                                  ) ;_ end of lambda
  23.                                        ) ;_ end of function
  24.                                      ) ;_ end of vl-catch-all-apply
  25.                               ) ;_ end of setq
  26.                         ) ;_ end of type
  27.                         'str
  28.                      ) ;_ end of =
  29.                 ) ;_ end of and
  30.                      (setq layer (vla-add (vla-get-layers adoc) "POLYLINE LAYER"))
  31.                      (vla-put-color layer 253) ; change color
  32.                      (vla-put-lineweight layer aclnwt005) ; change lineweight
  33.                      (setq offset_value (cond ((= (atoi offset_value) 1) 0.5)
  34.                                               ((= (atoi offset_value) 2) 2.0)
  35.                                         ) ;_ end of cond
  36.                            loops        (mapcar (function
  37.                                                   (lambda (ent)
  38.                                                     (vl-sort (mapcar (function (lambda (x)
  39.                                                                                  (setq x (car (vlax-safearray->list (vlax-variant-value x))))
  40.                                                                                  (vla-put-layer x (vla-get-name layer))
  41.                                                                                  x
  42.                                                                                ) ;_ end of lambda
  43.                                                                      ) ;_ end of function
  44.                                                                      (list (vla-offset (vlax-ename->vla-object ent) offset_value)
  45.                                                                            (vla-offset (vlax-ename->vla-object ent) (- offset_value))
  46.                                                                      ) ;_ end of list
  47.                                                              ) ;_ end of mapcar
  48.                                                              (function (lambda (a b) (> (vla-get-area a) (vla-get-area b))))
  49.                                                     ) ;_ end of vl-sort
  50.                                                   ) ;_ end of lambda
  51.                                                 ) ;_ end of function
  52.                                                 ((lambda (/ tab item)
  53.                                                    (repeat (setq tab  nil
  54.                                                                  item (sslength selset)
  55.                                                            ) ;_ end setq
  56.                                                      (setq tab (cons (ssname selset (setq item (1- item))) tab))
  57.                                                    ) ;_ end of repeat
  58.                                                  ) ;_ end of lambda
  59.                                                 )
  60.                                         ) ;_ end of mapcar
  61.                      ) ;_ end of setq
  62.                      (foreach item loops
  63.                        (setq hatch (vla-addhatch
  64.                                      (vla-get-modelspace adoc)
  65.                                      achatchpatterntypepredefined
  66.                                      "ANSI31"
  67.                                      :vlax-false
  68.                                      achatchobject
  69.                                    ) ;_ end of vla-AddHatch
  70.                        ) ;_ end of setq
  71.                        (vla-appendouterloop
  72.                          hatch
  73.                          (vlax-safearray-fill (vlax-make-safearray vlax-vbobject '(0 . 0)) (list (car item)))
  74.                        ) ;_ end of vla-appendouterloop
  75.                        (vla-appendinnerloop
  76.                          hatch
  77.                          (vlax-safearray-fill (vlax-make-safearray vlax-vbobject '(0 . 0)) (list (cadr item)))
  78.                        ) ;_ end of vla-appendinnerloop
  79.                        (vla-evaluate hatch)
  80.                        (vla-update hatch)
  81.                        (vla-put-patternscale hatch 0.1) ; change hatch scale
  82.                        (vla-put-layer hatch (vla-get-name layer))
  83.                      ) ;_ end of foreach
  84.                      (vla-endundomark adoc)
  85.               ) ;_ end of progn
  86.             ) ;_ end of if
  87.             (alert "Layer : \"_WATER LINE\" don't exist...")
  88.       ) ;_ end of if (tblsearch "LAYER" "_WATER LINE")
  89.       (command "_Setbylayer" (ssget "X") "" "_Yes" "_Yes")
  90.       (princ)
  91. ) ;_ end of defun
  92.  
Title: Re: help with an alert box message
Post by: PM on July 15, 2021, 10:23:04 AM
Hi  ribarm work nice. Can you add another two options. Some times i have a lot of close polylines on _WATER LINE layer. Can you add an alert box that


1)  "The polyline you select is not on  _WATER LINE  layer !!!!" 
and

2)  "The polyline you select is not close !!!!!" 

Thanks
Title: Re: help with an alert box message
Post by: ribarm on July 15, 2021, 10:55:21 AM
1) With the filter already present in the code, you are not able to select polyline entities that reside in some other layer than "WATER LINE"...
2) What do you mean not close?
Perhaps closed?
Title: Re: help with an alert box message
Post by: PM on July 15, 2021, 11:02:48 AM
This  code must work only for close polyline. Some times the first and the last vertex of the polyline is in the same point but the polyline is not close. So you try to run the code and you dont take any results and you dont know why untill find out that the polyline is not close or the close polyline you select is not in the correct layer. Thats why i want this two filters

Thanks