There are many ways to approach this:
If you are only working with 2D polylines (LWPOLYLINEs), then you can filter the polylines by number of vertices directly from the ssget filter list, using DXF group 90:
- ([color=BLUE]defun[/color] c:test1 ( [color=BLUE]/[/color] i s x ) ([color=BLUE]if[/color] ([color=BLUE]setq[/color] s ([color=BLUE]ssget[/color] [color=MAROON]"_C"[/color] '( 7.244 2.071) '(16.665 10.003) '( (0 . [color=MAROON]"LWPOLYLINE"[/color]) (8 . [color=MAROON]"DIMLDR"[/color]) (90 . 6) (-4 . [color=MAROON]"&="[/color]) (70 . 1) ) ) ) ([color=BLUE]repeat[/color] ([color=BLUE]setq[/color] i ([color=BLUE]sslength[/color] s)) ([color=BLUE]setq[/color] x ([color=BLUE]entget[/color] ([color=BLUE]ssname[/color] s ([color=BLUE]setq[/color] i ([color=BLUE]1-[/color] i))))) ([color=BLUE]entmod[/color] ([color=BLUE]subst[/color] '(8 . [color=MAROON]"PolylinesWith6Vertices"[/color]) ([color=BLUE]assoc[/color] 8 x) x)) ) ) ([color=BLUE]princ[/color]))
Note that DXF group 70 is bit-coded, therefore I have used the Bitwise Masked Equals operator in the filter list to essentially perform a (= 1 (logand 1 (cdr (assoc 70 )))) check. You can find more information about this technique here.
However, if you are working with a combination of both 2D lightweight polylines (LWPOLYLINEs) and 2D & 3D 'heavy' polylines (POLYLINEs), you would need to perform the check on the number of vertices from within the loop, as the number of vertices is not stored in the DXF data for a POLYLINE entity.
For this, you could use the following:
- ([color=BLUE]defun[/color] c:test2 ( [color=BLUE]/[/color] c e i s x ) ([color=BLUE]if[/color] ([color=BLUE]setq[/color] s ([color=BLUE]ssget[/color] [color=MAROON]"_C"[/color] '( 7.244 2.071) '(16.665 10.003) '( (-4 . [color=MAROON]""[/color]) (8 . [color=MAROON]"DIMLDR"[/color]) (-4 . [color=MAROON]"&="[/color]) (70 . 1) ) ) ) ([color=BLUE]repeat[/color] ([color=BLUE]setq[/color] i ([color=BLUE]sslength[/color] s)) ([color=BLUE]setq[/color] i ([color=BLUE]1-[/color] i) e ([color=BLUE]ssname[/color] s i) x ([color=BLUE]entget[/color] e) c 0 ) ([color=BLUE]if[/color] ([color=BLUE]=[/color] [color=MAROON]"POLYLINE"[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 0 x))) ([color=BLUE]while[/color] ([color=BLUE]=[/color] [color=MAROON]"VERTEX"[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 0 ([color=BLUE]entget[/color] ([color=BLUE]setq[/color] e ([color=BLUE]entnext[/color] e)))))) ([color=BLUE]setq[/color] c ([color=BLUE]1+[/color] c)) ) ([color=BLUE]setq[/color] c 6) ) ([color=BLUE]if[/color] ([color=BLUE]=[/color] c 6) ([color=BLUE]entmod[/color] ([color=BLUE]subst[/color] '(8 . [color=MAROON]"PolylinesWith6Vertices"[/color]) ([color=BLUE]assoc[/color] 8 x) x)) ) ) ) ([color=BLUE]princ[/color]))
Here, note the use of the additional bitwise test on the value of DXF group 70 when filtering POLYLINE entities to exclude 3D polygon meshes (DXF group 70 = 16) and polyface meshes (DXF group 70 = 64). This is equivalent to (zerop (logand 80 (cdr (assoc 70 )))) |