GregGleason 发表于 2022-7-5 15:28:20

SSGET - Polyline Select by Clo

I am have a selection that is to get closed polylines on the indicated layer.The goal is if the closed polyline has 6 vertices then that polyline will be changed to another layer.
 
I need help with the middle bit.
 

(defun c:Test ( / in ss en get vtx) (if (setq in -1 ss (ssget "_C" '(7.244 2.071) '(16.665 10.003) '((0 . "*POLYLINE") (8 . "DIMLDR") (70 . 1))))   (while (setq en (ssname ss (setq in (1+ in))))   {count vertices of closed polyline}   {if vertex count = 6 change to another layer}   )   ) (princ) )Does the selection at least appears that it will work?
 
Greg

Lee Mac 发表于 2022-7-5 15:48:44

 
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:

(defun c:test1 ( / i s x )   (if       (setq s         (ssget "_C"            '( 7.2442.071)            '(16.665 10.003)            '(                   (0 . "LWPOLYLINE")                   (8 . "DIMLDR")                   (90 . 6)                   (-4 . "&=") (70 . 1)               )         )       )       (repeat (setq i (sslength s))         (setq x (entget (ssname s (setq i (1- i)))))         (entmod (subst '(8 . "PolylinesWith6Vertices") (assoc 8 x) x))       )   )   (princ))
 
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:

(defun c:test2 ( / c e i s x )   (if       (setq s         (ssget "_C"            '( 7.2442.071)            '(16.665 10.003)            '(                   (-4 . "")                   (8 . "DIMLDR")                   (-4 . "&=") (70 . 1)               )         )       )       (repeat (setq i (sslength s))         (setq i (1- i)               e (ssname s i)               x (entget e)               c 0         )         (if (= "POLYLINE" (cdr (assoc 0 x)))               (while (= "VERTEX" (cdr (assoc 0 (entget (setq e (entnext e))))))                   (setq c (1+ c))               )               (setq c 6)         )         (if (= c 6)               (entmod (subst '(8 . "PolylinesWith6Vertices") (assoc 8 x) x))         )       )   )   (princ))
 
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 ))))

rlx 发表于 2022-7-5 16:01:00

I also liked this one :
 

(1+ (vlax-curve-getendparam (vlax-ename->vla-object (car (entsel "\nSelect polyline: "))))) http://forums.augi.com/showthread.php?48293-No-of-Vertices-in-a-PolyLine/page2
 
I'm not sure about the 1+ though...
 
but I admit , most of the time the only polylines I use in my field of work (electrical / instrumentation) are just plain square (and boring) 2D poly's so I don't really know what I'm talking about...
 
gr. Rlx

GregGleason 发表于 2022-7-5 16:15:27

 
Lee, you are da man!Thank you, sir!Worked like a Rolex.
 
Greg

Lee Mac 发表于 2022-7-5 16:20:39

You're welcome Greg, happy to help.

BIGAL 发表于 2022-7-5 16:29:18

Just an alternative and Lee you have given me the answer for some old code, using VL you can get the co-ordinates and how many adding the "is it a Polyline or a Lwpolyline" ? The number of x y or xyz points is divided by either 2 or 3. Will have a play. It will not work with some of the other objects that you have checked for.
页: [1]
查看完整版本: SSGET - Polyline Select by Clo