Jump to content

Select lines and polylines if length is less than x and object has 2 vertices


Recommended Posts

Posted

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

Posted

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)
)

 

Posted

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)
  )
)

 

Posted

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.

  • Like 1
Posted

I am struggling to learn and apply conditional functions.

 

I still struggle !

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...