Author Topic: Limit of vertices in list to use "_WP" with ssget?  (Read 6138 times)

0 Members and 1 Guest are viewing this topic.

Brick_top

  • Guest
Limit of vertices in list to use "_WP" with ssget?
« on: January 26, 2011, 07:21:06 AM »
Hi

I have a polygon with 160 vertices which I would like to use with the "_WP" ssget filter, but It returns nil.

I tested with a polygon with a lower number (71) and it selected the objects within.

What could be wrong?

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Limit of vertices in list to use "_WP" with ssget?
« Reply #1 on: January 26, 2011, 08:01:35 AM »
polygon may have overlapping or self-intersection point of ...

Brick_top

  • Guest
Re: Limit of vertices in list to use "_WP" with ssget?
« Reply #2 on: January 26, 2011, 08:44:01 AM »
sounds complicated... thanks a lot for your answer

Brick_top

  • Guest
Re: Limit of vertices in list to use "_WP" with ssget?
« Reply #3 on: January 26, 2011, 09:06:22 AM »
Problem is

I have a number of polylines 4000+ and which one of them should have a text inside.

I'm trying to write a routine that would tell me which polylines don't have a text inside.

Code: [Select]
(setq num6 0)
(repeat (length lst2)
    (setq ptlst (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= 10 (car x))) (entget (nth num6 lst2))))
  ptlst2 (ssget "_WP" ptlst (list (cons 0 typ2)(cons 8 nom7)))
    );setq  
    (if
      (= ptlst2 nil)
        (command "hatch" "angle" "5" "0" (nth num6 lst2))
    );if
    (setq num6 (+ 1 num6))

    );repeat

lst2 = list of all the entities of polylines to test
typ2 = "TEXT"
nom7 = layer of the text

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Limit of vertices in list to use "_WP" with ssget?
« Reply #4 on: January 26, 2011, 09:09:08 AM »
before the function, you must ensure that the entire polygon is visible on the screen...

Brick_top

  • Guest
Re: Limit of vertices in list to use "_WP" with ssget?
« Reply #5 on: January 26, 2011, 09:36:20 AM »
You mean a zoom extents or a zoom for every polygon being tested?

I tried to copy some of the polygons to another drawing and it worked.. hum

Code: [Select]
(command "hatch" "angle" "5" "0" (nth num6 lst2)"")
And I was missing this ("") in this part of the code, apparently

did.ave

  • Guest
Re: Limit of vertices in list to use "_WP" with ssget?
« Reply #6 on: January 26, 2011, 09:53:03 AM »
Bonjour

"OSMODE" to zero, perhaps

sorry, I'm french ..

amicalement.

Brick_top

  • Guest
Re: Limit of vertices in list to use "_WP" with ssget?
« Reply #7 on: January 26, 2011, 09:56:38 AM »
thanks for your reply, unfortunately it didn't influence the result

Brick_top

  • Guest
Re: Limit of vertices in list to use "_WP" with ssget?
« Reply #8 on: January 26, 2011, 10:00:51 AM »
One thing I have noticed is in the file with all of the polygons it just starts to hatch all of them.

In the file with less polygons it hatches them correctly, but one of them has a text inside.

I want it just to hatch the ones that don't have a text

VVA

  • Newt
  • Posts: 166
Re: Limit of vertices in list to use "_WP" with ssget?
« Reply #9 on: January 26, 2011, 12:42:01 PM »
Try it
Test1 - change the layer of polylines that do not have the text inside, at NO-HAVE-TEXT
Test2 - add hatch to this polyline
Code: [Select]
(vl-load-com)
(defun C:TEST1 ( / ss textlist pllist)
  ;;;Move polyline to layer NO-HAVE-TEXT
(setq ss (ssget "_X" (list '(0 . "TEXT")(cons 410 (getvar "CTAB")))))
(setq textlist (pickset-to-list ss)) ;_List of text
(setq ss (ssget "_X" (list '(0 . "LWPOLYLINE")(cons 410 (getvar "CTAB")))))
(setq pllist (pickset-to-list ss));_list of boundary
(foreach pl (vl-remove-if-not '(lambda(x)(Is-none-text-inside-polyline x textlist)) pllist)
  (entmod (subst (cons 8 "NO-HAVE-TEXT")(assoc 8 (entget pl))(entget pl)))
  )
  )

(defun C:TEST2 ( / ss textlist pllist)
  ;;;Add hatch
(setq ss (ssget "_X" (list '(0 . "TEXT")(cons 410 (getvar "CTAB")))))
(setq textlist (pickset-to-list ss)) ;_List of text
(setq ss (ssget "_X" (list '(0 . "LWPOLYLINE")(cons 410 (getvar "CTAB")))))
(setq pllist (pickset-to-list ss));_list of boundary
(foreach pl (vl-remove-if-not '(lambda(x)(Is-none-text-inside-polyline x textlist)) pllist)
   ;; Pat - pattern
 ;; L - list point
 ;; A - angle hatch
 ;; N - name pattern
 ;; S - scale
  (entmakex-hatch
    (list(massoc 10 (entget pl))) ;_list point
    0                       ;_Angle hatch
    "ANSI31"                ;_Name Pattern
    1                       ;_Scale
    )
    )
  )


(defun Is-none-text-inside-polyline ( polyline textlist / boundary)
  ;;;Return T if polyline not have text inside
  (setq boundary (massoc 10 (entget polyline)))
  (apply 'and
  (mapcar '(lambda ( text )
             (if (In_Figure (cdr(assoc 10 (entget text))) boundary)
               nil
               polyline
               )
             )
          textlist
          )
         )
  )
       
(defun massoc (key alist)
(mapcar 'cdr (vl-remove-if-not (function (lambda (x) (= key (car x)))) alist)))
(defun pickset-to-list (ss / item lst)
       (repeat (setq item (sslength ss)) ;_ end setq
         (setq lst (cons (ssname ss (setq item (1- item))) lst))
         ) ;_ end repeat

  lst
  ) ;_ end of defun

(defun entmakex-hatch (L a n s)
;; By ElpanovEvgeniy
;; L - list of list point
;; A - angle hatch
;; N - name pattern
;; S - scale
;; returne - hatch ename
(entmakex
  (apply
   'append
   (list
    (list '(0 . "HATCH")
          '(100 . "AcDbEntity")
          '(410 . "Model")
          '(100 . "AcDbHatch")
          '(10 0.0 0.0 0.0)
          '(210 0.0 0.0 1.0)
          (cons 2 n)
          (if (= n "SOLID")
           '(70 . 1)
           '(70 . 0)
          ) ;_  if
          '(71 . 0)
          (cons 91 (length l))
    ) ;_  list
    (apply 'append
           (mapcar '(lambda (a)
                     (apply 'append
                            (list (list '(92 . 7) '(72 . 0) '(73 . 1) (cons 93 (length a)))
                                  (mapcar '(lambda (b) (cons 10 b)) a)
                                  '((97 . 0))
                            ) ;_  list
                     ) ;_  apply
                    ) ;_  lambda
                   l
           ) ;_  mapcar
    ) ;_  apply
    (list '(75 . 0)
          '(76 . 1)
          (cons 52 a)
          (cons 41 s)
          '(77 . 0)
          '(78 . 1)
          (cons 53 a)
          '(43 . 0.)
          '(44 . 0.)
          '(45 . 1.)
          '(46 . 1.)
          '(79 . 0)
          '(47 . 1.)
          '(98 . 2)
          '(10 0. 0. 0.0)
          '(10 0. 0. 0.0)
          '(451 . 0)
          '(460 . 0.0)
          '(461 . 0.0)
          '(452 . 1)
          '(462 . 1.0)
          '(453 . 2)
          '(463 . 0.0)
          '(463 . 1.0)
          '(470 . "LINEAR")
    ) ;_  list
   ) ;_  list
  ) ;_  apply
) ;_  entmakex
) ;_  defun

(defun In_Figure (Point Boundary / FarPoint Check)
 ;_Проверяет Boundary на условие car и last одна и та же точка
      (if (not (equal (car Boundary) (last Boundary) 1e-6))
        (setq Boundary (append Boundary (list (car Boundary))))
      ) ;_ end of if
      (setq FarPoint (cons (+ (apply 'max (mapcar 'car Boundary)) 1.0)
                           (cdr Point)
                     ) ;_ end of cons
      ) ;_ end of setq
      (or
        (not
          (zerop
            (rem
              (length
                (vl-remove
                  nil
                  (mapcar
                    (function
                      (lambda (p1 p2) (inters Point FarPoint p1 p2))
                    ) ;_ end of function
                    Boundary
                    (cdr Boundary)
                  ) ;_ end of mapcar
                ) ;_ end of vl-remove
              ) ;_ end of length
              2
            ) ;_ end of rem
          ) ;_ end of zerop
        ) ;_ end of not
        (vl-some (function (lambda (x) x))
                 (mapcar
                   (function (lambda (p1 p2)
                               (or Check
                                   (if (equal (+ (distance Point p1)
                                                 (distance Point p2)
                                              ) ;_ end of +
                                              (distance p1 p2)
                                              1e-3
                                       ) ;_ end of equal
                                     (setq Check t)
                                     nil
                                   ) ;_ end of if
                               ) ;_ end of or
                             ) ;_ end of lambda
                   ) ;_ end of function
                   Boundary
                   (cdr Boundary)

                 ) ;_ end of mapcar
        ) ;_ end of vl-some
      ) ;_ end of or
    )

Brick_top

  • Guest
Re: Limit of vertices in list to use "_WP" with ssget?
« Reply #10 on: January 27, 2011, 03:55:45 AM »
 :-o

I'm testing right now

Don't know how to thank you!  :-o

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Limit of vertices in list to use "_WP" with ssget?
« Reply #11 on: January 27, 2011, 03:59:35 AM »
Bonjour

< .. >
sorry, I'm french ..

amicalement.

 :-)
That's ok ... it's not your fault   :lol:
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

did.ave

  • Guest
Re: Limit of vertices in list to use "_WP" with ssget?
« Reply #12 on: January 27, 2011, 04:11:47 AM »
Coucou

it's not my fault but it is so, and talk with you is a challenge
 
amicalement

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Limit of vertices in list to use "_WP" with ssget?
« Reply #13 on: January 27, 2011, 04:19:02 AM »
Hello did.ave

Welcome to theSwamp :)


Stay well.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Brick_top

  • Guest
Re: Limit of vertices in list to use "_WP" with ssget?
« Reply #14 on: January 27, 2011, 05:48:48 AM »
Try it
Test1 - change the layer of polylines that do not have the text inside, at NO-HAVE-TEXT
Test2 - add hatch to this polyline
Code: [Select]
(vl-load-com)
(defun C:TEST1 ( / ss textlist pllist)
  ;;;Move polyline to layer NO-HAVE-TEXT
(setq ss (ssget "_X" (list '(0 . "TEXT")(cons 410 (getvar "CTAB")))))
(setq textlist (pickset-to-list ss)) ;_List of text
(setq ss (ssget "_X" (list '(0 . "LWPOLYLINE")(cons 410 (getvar "CTAB")))))
(setq pllist (pickset-to-list ss));_list of boundary
(foreach pl (vl-remove-if-not '(lambda(x)(Is-none-text-inside-polyline x textlist)) pllist)
  (entmod (subst (cons 8 "NO-HAVE-TEXT")(assoc 8 (entget pl))(entget pl)))
  )
  )

(defun C:TEST2 ( / ss textlist pllist)
  ;;;Add hatch
(setq ss (ssget "_X" (list '(0 . "TEXT")(cons 410 (getvar "CTAB")))))
(setq textlist (pickset-to-list ss)) ;_List of text
(setq ss (ssget "_X" (list '(0 . "LWPOLYLINE")(cons 410 (getvar "CTAB")))))
(setq pllist (pickset-to-list ss));_list of boundary
(foreach pl (vl-remove-if-not '(lambda(x)(Is-none-text-inside-polyline x textlist)) pllist)
   ;; Pat - pattern
 ;; L - list point
 ;; A - angle hatch
 ;; N - name pattern
 ;; S - scale
  (entmakex-hatch
    (list(massoc 10 (entget pl))) ;_list point
    0                       ;_Angle hatch
    "ANSI31"                ;_Name Pattern
    1                       ;_Scale
    )
    )
  )


(defun Is-none-text-inside-polyline ( polyline textlist / boundary)
  ;;;Return T if polyline not have text inside
  (setq boundary (massoc 10 (entget polyline)))
  (apply 'and
  (mapcar '(lambda ( text )
             (if (In_Figure (cdr(assoc 10 (entget text))) boundary)
               nil
               polyline
               )
             )
          textlist
          )
         )
  )
       
(defun massoc (key alist)
(mapcar 'cdr (vl-remove-if-not (function (lambda (x) (= key (car x)))) alist)))
(defun pickset-to-list (ss / item lst)
       (repeat (setq item (sslength ss)) ;_ end setq
         (setq lst (cons (ssname ss (setq item (1- item))) lst))
         ) ;_ end repeat

  lst
  ) ;_ end of defun

(defun entmakex-hatch (L a n s)
;; By ElpanovEvgeniy
;; L - list of list point
;; A - angle hatch
;; N - name pattern
;; S - scale
;; returne - hatch ename
(entmakex
  (apply
   'append
   (list
    (list '(0 . "HATCH")
          '(100 . "AcDbEntity")
          '(410 . "Model")
          '(100 . "AcDbHatch")
          '(10 0.0 0.0 0.0)
          '(210 0.0 0.0 1.0)
          (cons 2 n)
          (if (= n "SOLID")
           '(70 . 1)
           '(70 . 0)
          ) ;_  if
          '(71 . 0)
          (cons 91 (length l))
    ) ;_  list
    (apply 'append
           (mapcar '(lambda (a)
                     (apply 'append
                            (list (list '(92 . 7) '(72 . 0) '(73 . 1) (cons 93 (length a)))
                                  (mapcar '(lambda (b) (cons 10 b)) a)
                                  '((97 . 0))
                            ) ;_  list
                     ) ;_  apply
                    ) ;_  lambda
                   l
           ) ;_  mapcar
    ) ;_  apply
    (list '(75 . 0)
          '(76 . 1)
          (cons 52 a)
          (cons 41 s)
          '(77 . 0)
          '(78 . 1)
          (cons 53 a)
          '(43 . 0.)
          '(44 . 0.)
          '(45 . 1.)
          '(46 . 1.)
          '(79 . 0)
          '(47 . 1.)
          '(98 . 2)
          '(10 0. 0. 0.0)
          '(10 0. 0. 0.0)
          '(451 . 0)
          '(460 . 0.0)
          '(461 . 0.0)
          '(452 . 1)
          '(462 . 1.0)
          '(453 . 2)
          '(463 . 0.0)
          '(463 . 1.0)
          '(470 . "LINEAR")
    ) ;_  list
   ) ;_  list
  ) ;_  apply
) ;_  entmakex
) ;_  defun

(defun In_Figure (Point Boundary / FarPoint Check)
 ;_Проверяет Boundary на условие car и last одна и та же точка
      (if (not (equal (car Boundary) (last Boundary) 1e-6))
        (setq Boundary (append Boundary (list (car Boundary))))
      ) ;_ end of if
      (setq FarPoint (cons (+ (apply 'max (mapcar 'car Boundary)) 1.0)
                           (cdr Point)
                     ) ;_ end of cons
      ) ;_ end of setq
      (or
        (not
          (zerop
            (rem
              (length
                (vl-remove
                  nil
                  (mapcar
                    (function
                      (lambda (p1 p2) (inters Point FarPoint p1 p2))
                    ) ;_ end of function
                    Boundary
                    (cdr Boundary)
                  ) ;_ end of mapcar
                ) ;_ end of vl-remove
              ) ;_ end of length
              2
            ) ;_ end of rem
          ) ;_ end of zerop
        ) ;_ end of not
        (vl-some (function (lambda (x) x))
                 (mapcar
                   (function (lambda (p1 p2)
                               (or Check
                                   (if (equal (+ (distance Point p1)
                                                 (distance Point p2)
                                              ) ;_ end of +
                                              (distance p1 p2)
                                              1e-3
                                       ) ;_ end of equal
                                     (setq Check t)
                                     nil
                                   ) ;_ end of if
                               ) ;_ end of or
                             ) ;_ end of lambda
                   ) ;_ end of function
                   Boundary
                   (cdr Boundary)

                 ) ;_ end of mapcar
        ) ;_ end of vl-some
      ) ;_ end of or
    )


many thanks again it has worked perfectly :-) it took aproximately 50 minutes to execute but all went well!

Don't know how to thank you enough  :-o

By the way your function to check if a point is inside a polyline is helping me a lot in another routine I wanted to write.

I got the function from another page but didn't remember where from.

thanks a lot for your work, I'm gratefull