Author Topic: Filtration with ssget  (Read 7222 times)

0 Members and 1 Guest are viewing this topic.

Coder

  • Swamp Rat
  • Posts: 827
Filtration with ssget
« on: May 22, 2011, 03:46:06 AM »
Hello .

I wonder how to filter only the CLOSED *LWPOLYLINE* and *POLYLINE* with ssget !

My start ....

Code: [Select]
(setq ss (ssget
           '(
             (-4 . "<or")
             (0 . "POLYLINE")
             (-4 . "<and")
             (0 . "LWPOLYLINE")(70 . 1)
             (-4 . "and>")
             (-4 . "or>")
            )
         )
)

Thanks

gile

  • Gator
  • Posts: 2520
  • Marseille, France
Re: Filtration with ssget
« Reply #1 on: May 22, 2011, 04:46:52 AM »
Hi,

You'd rather use the bitwise AND operator ("&") to test for the 70 group flag (a closed (lw)polyline may also have flag 128).
For POLYLINE entities, you have to avoid (old style) meshes which are polylines too (flags 16, 32 and 64).

Code: [Select]
(ssget '((-4 . "<OR")
(-4 . "<AND")
(0 . "LWPOLYLINE")
(-4 . "&")
(70 . 1)
(-4 . "AND>")
(-4 . "<AND")
(0 . "POLYLINE")
(-4 . "&")
(70 . 1)
(-4 . "<NOT")
(-4 . "&")
(70 . 112)
(-4 . "NOT>")
(-4 . "AND>")
(-4 . "OR>")
)
)
« Last Edit: May 22, 2011, 04:50:46 AM by gile »
Speaking English as a French Frog

Coder

  • Swamp Rat
  • Posts: 827
Re: Filtration with ssget
« Reply #2 on: May 22, 2011, 04:56:06 AM »
Thank you gile .

I couldn't find in Cad help tutorial the description of (operators & ).

And your codes would select the LWPolyline (that made be Rectang command) and avoid the closed polylines that were made manually .

Many thanks

gile

  • Gator
  • Posts: 2520
  • Marseille, France
Re: Filtration with ssget
« Reply #3 on: May 22, 2011, 05:30:08 AM »
Quote
I couldn't find in Cad help tutorial the description of (operators & ).

AutoLISP Developer's Guide > Using the AutoLISP Language > Using AutoLISP to Manipulate AutoCAD Objects > Selection Set Handling > Selection Set Filter Lists > Relational Tests

Quote
And your codes would select the LWPolyline (that made be Rectang command) and avoid the closed polylines that were made manually

The code I posted does select closed polylines (even made manually with the 'Close' option).
AFAIK there's no way to directly filter polylines which last vertex is ovelapped to the first one (which aren't truely closed polylines).
Speaking English as a French Frog

gile

  • Gator
  • Posts: 2520
  • Marseille, France
Re: Filtration with ssget
« Reply #4 on: May 22, 2011, 06:41:32 AM »
If you want to select also 'look like' closed polylines, you can do something like this:

Code: [Select]
(defun selectclosedplines (/ ss n elst)
  (if (setq ss (ssget '((-4 . "<OR")
      (0 . "LWPOLYLINE")
      (-4 . "<AND")
      (0 . "POLYLINE")
      (-4 . "<NOT")
      (-4 . "&")
      (70 . 112)
      (-4 . "NOT>")
      (-4 . "AND>")
      (-4 . "OR>")
     )
     )
    )
     (repeat (setq n (sslength ss))
       (setq elst (entget (ssname ss (setq n (1- n)))))
       (if (and (= 0 (logand (cdr (assoc 70 elst)) 1))
(not (equal (cdr (assoc 10 elst)) (cdr (assoc 10 (reverse elst)))))
   )
(ssdel (cdr (assoc -1 elst)) ss)
       )
     )
  )
  ss
)
Speaking English as a French Frog

Coder

  • Swamp Rat
  • Posts: 827
Re: Filtration with ssget
« Reply #5 on: May 22, 2011, 06:50:28 AM »
If you want to select also 'look like' closed polylines, you can do something like this:
Code: [Select]
    (ssdel (cdr (assoc -1 elst)) ss)
     

Yes , Great .

So the selection set must be filtered after selecting entities with the function ssget  . Am I right ?

Thanking you gile

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Filtration with ssget
« Reply #6 on: May 22, 2011, 09:27:56 AM »
One more:
(setq ss (ssget  '((0 . "LWPOLYLINE,POLYLINE")(-4 . "&")(70 . 1))))
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Filtration with ssget
« Reply #7 on: May 22, 2011, 09:50:20 AM »
Code: [Select]
(0 . "*POLYLINE")

pedroantonio

  • Guest
Re: Filtration with ssget
« Reply #8 on: November 30, 2013, 11:57:41 AM »
Sorry Coder i am late for this post   :-)

I use this lisp , its Lee Mac code

You only have to choose the layer of the polyline and this lisp finds all open and close polyline (of this layer)

Code: [Select]
;
  ; Check for open polylines
  ; (c) 2009 Lee Mac   
  ;
(defun c:GetLwClsd  (/ ss) ; Notice that *flag_def* is not localised, as it is a global variable
 
  (or *flag_def* (setq *flag_def* "Open")) ;; Set first-time default
 
  (initget "Open Closed") ; Only allow these values, allow enter also
 
  (setq *flag_def*
    (cond ((getkword
             (strcat "\nLooking for [O]pen or [C]losed LWPolylines? <" *flag_def* "> : ")))
          ;; Either a keyword has been entered, hence set it as the new default
         
          (t *flag_def*))) ;; Else use the original default
 
  (if (setq ss
        (ssget "_X"
          (list (cons 0 "LWPOLYLINE")
                (cons 8 (getvar "CLAYER"))
                (cons -4 "<OR")
                (cons 70 (cond ((eq *flag_def* "Open") 0)   (t 1)))
                (cons 70 (cond ((eq *flag_def* "Open") 128) (t 129)))
                (cons -4 "OR>"))))
   
    (progn
      (foreach ent  (mapcar 'cadr (ssnamex ss))
        (setq lay (tblsearch "LAYER" (cdr (assoc 8 (entget ent)))))
        (if (or (eq 1 (logand 1 (cdr (assoc 70 lay))))
                (eq 4 (logand 4 (cdr (assoc 70 lay)))))
          (ssdel ent ss)))
      (princ (strcat "\n" (itoa (sslength ss)) " found."))
      (sssetfirst nil ss))
    (princ "\n<< nothing found >>"))
  (princ))
(textscr) ; bring text-window to front and inform user
(princ "\nSearching LW-Polylines at curent layer.
          Note: splines, curved fit, and 3D plines
          will not work\nStart with mit << GetLwClsd >>")