densan Posted August 31, 2022 Share Posted August 31, 2022 Hello Forum, I have to clean up a topography file containing digital debris in the form of 1000's random lines and polylines, and each object has two vertices (the client delivered it as is). If I select by length only, quick select captures a lot of contour information I want to keep. I found this code in another post and wanted to ask for some guidance. I am stuck on where to include the part that counts vertices, how to incorporate it into the code, and if the approach using vlax-curve-getendparam will work for lines and polylines. Thank you in advance for any feedback, I included a simplified scenario of my problem for reference. ;; Select lines and polylines if length is less than x and object has 2 vertices ;; https://www.cadtutor.net/forum/topic/61456-lisp-for-select-less-than-specified-length-lines/ ;; By the amazing: Lee Mac - 2016 (defun c:leesel (/ e i s) (if (setq s (ssget '((-4 . "<OR") (0 . "LINE") (-4 . "<AND") (0 . "LWPOLYLINE") (-4 . "<NOT") (-4 . "&=") (70 . 1) (-4 . "NOT>") (-4 . "AND>") (-4 . "OR>") ) ) ) (repeat (setq i (sslength s)) (setq e (ssname s (setq i (1- i)))) (if (<= 150 (vlax-curve-getdistatparam e (vlax-curve-getendparam e)) ) (ssdel e s) ) ) ) (sssetfirst nil s) ;; Why vlax-curve-getendparam returns the number of vertices minus one in a polyline? ;; Documentation definition for it is, Returns the parameter of the endpoint of the curve ;; Is this the correct approach to count vertices for lines and polys ;; (setq endptcurve (vlax-curve-getendparam eachobj)) ;; (setq test (+ 1 endptcurve)) total number of vertices (princ) ) (princ) TopoExample.dwg Quote Link to comment Share on other sites More sharing options...
BIGAL Posted September 1, 2022 Share Posted September 1, 2022 To me looks like the only thing you want to get rid of is the 2 pt plines so just get all plines, and can use a couple of methods but just ignore plines with more than 2 points. I doubt that any contours will be only 2 points. There are no Lines ?? (defun c:wow ( / ss obj lst) (setq ss (ssget "x" (list (cons 0 "LWPOLYLINE")(cons 410 "Model")))) (alert (strcat "you have picked " (rtos (sslength ss) 2 0))) (repeat (setq x (sslength ss)) (setq obj (vlax-ename->vla-object (ssname ss (setq x (1- x))))) (setq lst (vlax-safearray->list (vlax-variant-value (vla-get-coordinates obj)))) (if (> (length lst) 4) (princ "skip") (vla-delete obj) ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
mhupp Posted September 1, 2022 Share Posted September 1, 2022 This will highlight any polyline that has two vertices, or any lines. ;; Select lines and polylines if length is less than x and object has 2 vertices ;; https://www.cadtutor.net/forum/topic/61456-lisp-for-select-less-than-specified-length-lines/ ;; By the amazing: Lee Mac - 2016 (defun c:leesel (/ s) (if (setq s (ssget '((-4 . "<OR") (0 . "LINE") (-4 . "<AND") (0 . "*POLYLINE") ;(70 . 0) ;open polyline check not needed since its only two vertices (90 . 2) ;number of vertices (-4 . "AND>") (-4 . "OR>") ) ) ) (sssetfirst nil s) ) (princ) ) ;; if you need to filter futher for length (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))) (if (<= (vlax-curve-getdistatparam ent (vlax-curve-getendparam ent)) 150) (ssdel ent s) ) ) Quote Link to comment Share on other sites More sharing options...
densan Posted September 1, 2022 Author Share Posted September 1, 2022 Thank you, BIGAL; you are correct your code completes the task. As I search for examples at the beginning, I tend to follow the same logic in the code I find and try to learn from it. I hope with more experience, I won't overthink the solution in the future. And mhupp thank you for the explanation. I am struggling to learn and apply conditional functions. I really appreciate the example. Thank you very much to the admins and members of this forum. 1 Quote Link to comment Share on other sites More sharing options...
BIGAL Posted September 2, 2022 Share Posted September 2, 2022 I am struggling to learn and apply conditional functions. I still struggle ! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.