Author Topic: Q: How to get start/end points of multiple lines via ssget  (Read 2150 times)

0 Members and 1 Guest are viewing this topic.

Oak3s

  • Guest
Q: How to get start/end points of multiple lines via ssget
« on: March 01, 2011, 07:45:42 PM »
Currently we have a routine to draw a line from mid-point of line 1 to mid-point of line 2. We are using entsel for this and I would like to use ssget with a window option. I can worry about the filtering at another time. Where I am stuck is how to get the information needed from ssget when multiple entities are selected. Any suggestions or help is appreciated.

Example of the current method used:
Code: [Select]
(setq line1 (car (entsel "\nSelect the first line: ")))
(setq pt1 (cdr (assoc 10 (entget line1))))

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Q: How to get start/end points of multiple lines via ssget
« Reply #1 on: March 01, 2011, 07:56:29 PM »
Hi Oak3s,

You will need to iterate through the acquired SelectionSet, operating on each entity in turn.

There are various ways to accomplish this (in all examples, 'ss' is the SelectionSet returned by ssget):

1) Using a While Loop:

Code: [Select]
(setq i -1)
(while (setq ent (ssname ss (setq i (1+ i))))
  (setq p1 (cdr (assoc 10 (entget ent))))
  ...
)

2) Using a Repeat Expression:

Code: [Select]
(repeat (setq i (sslength ss))
  (setq ent (ssname ss (setq i (1- i)))
         p1 (cdr (assoc 10 (entget ent)))
  )
  ...
)

3) Using a Foreach Expression (slower):

Code: [Select]
(foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
  (setq p1 (cdr (assoc 10 (entget ent))))
  ...
)

Hope this gets you started!

Lee

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Q: How to get start/end points of multiple lines via ssget
« Reply #2 on: March 01, 2011, 08:03:31 PM »
Twas bored, hacked together:

Code: [Select]
; [  Scroll for the answer after attempting it yourself  ;)  ]



























(defun c:test ( / ss i j e1 e2 )

  (if (setq ss (ssget '((0 . "LINE"))))
   
    (repeat (setq i (sslength ss))
      (setq e1 (entget (ssname ss (setq i (1- i)))))
     
      (repeat (setq j i)
        (setq e2 (entget (ssname ss (setq j (1- j)))))
        (entmakex
          (list
            (cons 0 "LINE")
            (cons 10
              (mapcar '(lambda ( a b ) (/ (+ a b) 2.))
                (cdr (assoc 10 e1))
                (cdr (assoc 11 e1))
              )
            )
            (cons 11
              (mapcar '(lambda ( a b ) (/ (+ a b) 2.))
                (cdr (assoc 10 e2))
                (cdr (assoc 11 e2))
              )
            )
          )
        )
      )
    )
  )

  (princ)
)

Oak3s

  • Guest
Re: Q: How to get start/end points of multiple lines via ssget
« Reply #3 on: March 01, 2011, 08:26:53 PM »
Sorry, I couldn't help but look. Pretty awesome! Thank you for being bored. I will remember this thread though and refer back to it for sure. Thanks again.