auto lisp (flag or circle) all open ends of open polylines, ignoring closed polylines.

auto lisp (flag or circle) all open ends of open polylines, ignoring closed polylines.

mkroll9in5in
Enthusiast Enthusiast
832 Views
11 Replies
Message 1 of 12

auto lisp (flag or circle) all open ends of open polylines, ignoring closed polylines.

mkroll9in5in
Enthusiast
Enthusiast

I have a collection of parts in one layer, all of which should be closed poly-lines. unfortunately some of them may have broken segments. I'm looking for a lisp I can run, then I select the group of poly-lined parts in question, and it either draws a circle or flags all open ends of open polylines, ignoring closed polylines in the selection.  

0 Likes
Accepted solutions (3)
833 Views
11 Replies
Replies (11)
Message 2 of 12

Kent1Cooper
Consultant
Consultant
Accepted solution

If selecting/highlighting/gripping all Polylines that are not closed is enough, without explicitly calling attention to their open end points, this will do that:

 

(sssetfirst nil (ssget "_X" '((0 . "LWPOLYLINE") (-4 . "<NOT") (-4 . "&") (70 . 1) (-4 . "NOT>"))))

 

If you really want to identify the open ends, the result of that (ssget) could be saved to a variable, and stepped through to identify the ends.

Kent Cooper, AIA
Message 3 of 12

ronjonp
Mentor
Mentor
Accepted solution

@mkroll9in5in How about just selecting them? 

This will make them RED since Kent's post was pretty much the same as mine previously.

 

(defun c:foo (/ _red s)
  (defun _red (e) (entmod (append (entget e) '((62 . 1) (420 . 16711680)))))
  (if (setq s (ssget "_X" '((0 . "lwpolyline") (-4 . "<NOT") (-4 . "&=") (70 . 1) (-4 . "NOT>"))))
    (mapcar '_red (mapcar 'cadr (ssnamex s)))
  )
  (princ)
)

 

DOH! .. too slow. 😃

 

0 Likes
Message 4 of 12

mkroll9in5in
Enthusiast
Enthusiast

That is closer than my current solution. While it does highlight the bad apples, it is not quite what I'm looking for. image it is a 2d part/ countertop for a kitchen with a scribe back wall with a bunch of line segments they should be endpoint to endpoint so that you can join them into a polyline. I need something that can point them all out in a instant.

0 Likes
Message 5 of 12

Kent1Cooper
Consultant
Consultant

 

(if (setq ss (ssget "_X" '((0 . "LWPOLYLINE") (-4 . "<NOT") (-4 . "&") (70 . 1) (-4 . "NOT>"))))
  (repeat (setq n (sslength ss))
    (setq pl (ssname ss (setq n (1- n))))
    (command
      "_.circle" "_non" (vlax-curve-getStartPoint pl) 3 ;;; <--EDIT Circle radius
      "_.circle" "_non" (vlax-curve-getEndPoint pl) 3 ;;; <--EDIT Circle radius
    ); command
  )
)

 

Kent Cooper, AIA
0 Likes
Message 6 of 12

WeTanks
Mentor
Mentor

but

Why can the closed polylines be selected?

 

We.Tanks

EESignature

A couple of Fusion improvement ideas that could your vote/support:
図面一括印刷

0 Likes
Message 7 of 12

Kent1Cooper
Consultant
Consultant

@WeTanks wrote:

but

Why can the closed polylines be selected?


That one is not closed as AutoCAD means the word.  Pick it and look at its Properties, and you'll see -- it's in your video.

 

If you want those that end at the same place where they start, but are not actually closed, to be not selected, that can't be done in (ssget), because there is no entry in the entity data list that can be filtered for.  It would involve finding all open Polylines, and stepping through them to check whether their first and last vertices are at the same place, removing any like that from the selection.

Kent Cooper, AIA
Message 8 of 12

WeTanks
Mentor
Mentor

I understand. Thank you so so much.

どうもありがとうございました。

We.Tanks

EESignature

A couple of Fusion improvement ideas that could your vote/support:
図面一括印刷

0 Likes
Message 9 of 12

WeTanks
Mentor
Mentor

How can I use the following piece of code?

 it doesn't have the 「 defun c:」

 

We.Tanks

EESignature

A couple of Fusion improvement ideas that could your vote/support:
図面一括印刷

0 Likes
Message 10 of 12

Kent1Cooper
Consultant
Consultant
Accepted solution

You can just paste the code in at the Command line [now that I fixed something], but here it is with a containing command-definition format:

(defun C:POEC ; = Polyline Open Ends Circled
  (/ ss n pl)
  (if (setq ss (ssget "_X" '((0 . "LWPOLYLINE") (-4 . "<NOT") (-4 . "&") (70 . 1) (-4 . "NOT>"))))
    (repeat (setq n (sslength ss)); then
      (setq pl (ssname ss (setq n (1- n))))
      (command
        "_.circle" "_non" (vlax-curve-getStartPoint pl) 3 ;;; <--EDIT Circle radius
        "_.circle" "_non" (vlax-curve-getEndPoint pl) 3 ;;; <--EDIT Circle radius
      ); command
    ); repeat
  ); if
  (prin1)
)
Kent Cooper, AIA
Message 11 of 12

WeTanks
Mentor
Mentor

Thank you .

I learned a lot from it.

We.Tanks

EESignature

A couple of Fusion improvement ideas that could your vote/support:
図面一括印刷

0 Likes
Message 12 of 12

mkroll9in5in
Enthusiast
Enthusiast

YES, this is what I have always wanted for years. 2024 LT LISP, I'm in heaven. I would like to thank you very much good sir. I have to deal with 20+ onsite digital templaters that are not every good CAD people. I have to move their work to a CNC that can be very picky about open geometries. Counter top work has a lot of scribe walls were segments are not always endpoint to endpoint due to sloppy work. I poly-line all the parts with different layered edges temporarily, then start the list command, select objects, then run threw that list to find the open ones, I write down the first X,Y coordinate, then undo, draw a line at that coordanate to help reveal the breaks. With a lot of broken segments this can take a while. Having this LISP to point out the issues in a single click, see the issue, undo the layer isolation required to collect that information, so you can go fix that issue, this is night and day. Thank You.

0 Likes