Jump to content

store endpoints of lines into a list


motee-z

Recommended Posts

The base engine could look like this :

 

[b][color=BLACK]([/color][/b]defun c:linepl [b][color=FUCHSIA]([/color][/b]/ pl ss i en ed[b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]and [b][color=NAVY]([/color][/b]setq ss [b][color=MAROON]([/color][/b]ssget '[b][color=GREEN]([/color][/b][b][color=BLUE]([/color][/b]0 . [color=#2f4f4f]"LINE"[/color][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
      [b][color=NAVY]([/color][/b]setq i 0[b][color=NAVY])[/color][/b]
      [b][color=NAVY]([/color][/b]while [b][color=MAROON]([/color][/b]setq en [b][color=GREEN]([/color][/b]ssname ss i[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]setq ed [b][color=GREEN]([/color][/b]entget en[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]foreach g '[b][color=GREEN]([/color][/b]10 11[b][color=GREEN])[/color][/b]
               [b][color=GREEN]([/color][/b]setq pl [b][color=BLUE]([/color][/b]cons [b][color=RED]([/color][/b]cdr [b][color=PURPLE]([/color][/b]assoc g ed[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b] pl[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]setq i [b][color=GREEN]([/color][/b]1+ i[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
      [b][color=NAVY]([/color][/b]and pl [b][color=MAROON]([/color][/b]alert [b][color=GREEN]([/color][/b]rtos [b][color=BLUE]([/color][/b]length pl[b][color=BLUE])[/color][/b] 2 0[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
[b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

Link to comment
Share on other sites

The variable 'lst' holds the list of end coordinates of the selected lines .

 

(defun c:Ends (/ ss lst)
 (if (setq ss (ssget '((0 . "LINE"))))
   ((lambda (i / sn)
      (while (setq sn (ssname ss (setq i (1+ i))))
        (setq lst (cons (cdr (assoc 11 (entget sn))) lst))
      )
    )
     -1
   )
 )
 (if lst lst (princ))
)

Link to comment
Share on other sites

One thing whilst great code above what happens when you draw a line the other way ? You may want the bit extra like I use about checking which end you pick so swap 10 & 11 answers to get start end as I desire.

Link to comment
Share on other sites

While I use sp (start_pt) & ep ( end_point ) a lot as the point values of lines, AutoCAD really uses From & To prompts and never really designates start and end.

 

The OP never really stated which points were required. ( all line points ) ( pairs of all line points ) ( pairs and their reverse of all line points )

 

I use the pairs and their reverse a lot ( for an overkill type function )

 

(defun vld_deldup (/ ss i ll en ed p10 p11 mln)
 (setq mln 0.003)
 (princ (strcat "\nSearching " (getvar "CLAYER") "...  "))
 (and (setq ss (ssget "X" (list (cons 0 "LINE")(cons 8 (getvar "CLAYER")))))
      (setq i 0)
      (while (setq en (ssname ss i))
             (setq ed (entget en)
                  p10 (cdr (assoc 10 ed))
                  p11 (cdr (assoc 11 ed)))
             (if (or (< (distance p10 p11) mln)
                     (member (list p10 p11) ll)
                     (member (list p11 p10) ll))
                  (entdel en)
                  (setq ll (cons (list p10 p11) ll)))
             (setq i (1+ i)))
       (if ll (princ (strcat (rtos (length ll) 2 0) " Of " (rtos i 2 0) " LINEs Remain"))
              (princ "- No Duplicates Found")))
 (prin1))

 

Most of the time, I will round the point values to mln

Link to comment
Share on other sites

One thing whilst great code above what happens when you draw a line the other way ? You may want the bit extra like I use about checking which end you pick so swap 10 & 11 answers to get start end as I desire.

 

example if OP wants collect points of vertical lines intersect in cross section?, if the first line endpoint facing down side ,the rest offset interval & trimmed lines would inherit the same pattern.

Though the OP's example dwg has no issue, i do agree BIGAL's consideration for the direction should be taken in to account. noted :thumbsup:

Link to comment
Share on other sites

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