Author Topic: Select the closest line when I click on the text  (Read 191 times)

0 Members and 1 Guest are viewing this topic.

emerrryjones

  • Mosquito
  • Posts: 1
Select the closest line when I click on the text
« on: July 13, 2021, 10:44:56 PM »
Hi everyone,

How do I select the nearest line when I click on any text. I have a code, but this code select single line. I want to select multiple text(or single text but I want to select the lines next to the text with the same content) then lisp select lines. I'm adding a video about how it works.

If you help me, I will be very glad.  :smitten: :smitten: :smitten:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:sl (/ ns sc ss n m p ls) (vl-load-com)
  2.   (if (setq ns (ssget ":s" '((0 . "text")))
  3.         sc (ssadd) ss (ssget "x" '((0 . "line"))))
  4.     (progn
  5.       (repeat (setq n (sslength ss))
  6.         (setq n (1- n) m (ssname ss n) p (cdr (assoc
  7.           10 (entget (ssname ns 0)))) ls (cons (list
  8.             m (distance p (vlax-curve-getclosestpointto
  9.               (vlax-ename->vla-object m) p))) ls)))
  10.       (sssetfirst nil (ssadd (caar (vl-sort ls
  11.         '(lambda(a b) (< (cadr a) (cadr b))))) sc))
  12.     )
  13.   ) (princ)
  14. )
  15.  

BIGAL

  • Swamp Rat
  • Posts: 830
  • 30 + years of using Autocad
Re: Select the closest line when I click on the text
« Reply #1 on: July 14, 2021, 03:56:42 AM »
Look at this (repeat (setq n (sslength ss))

So you need after selecting the text to do another (repeat (sslength ns)) dont forget closing )

You will need some way of recording which text which line could make another list ( (textentname lineentname) ....   I will let you have a go.
A man who never made a mistake never made anything