Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Select texts on a line

8 REPLIES 8
Reply
Message 1 of 9
grimeye
383 Views, 8 Replies

Select texts on a line

Hi there. Please imagine a situation. There is a very complecated drawing. Texts are on a line and crossing a line or something like that. Some texts has insertion points on the line. When the line is selected by LISP, only the specific texts with insertion points on the line are selected. Does it make sence? Please give me advices. I spent two days for thinking of this problem. I didn't write a single line on my editor. Thanks in advance.

8 REPLIES 8
Message 2 of 9
Kent1Cooper
in reply to: grimeye


@Anonymous wrote:

.... Some texts has insertion points on the line. When the line is selected by LISP, only the specific texts with insertion points on the line are selected. ....


Untested [it's late], and without any of the usual controls, but something like this should do it:

 

(defun C:STOL (/ ldata end1 end2 txtss txt ins); = Select Text[s] with insertion point[s] On Line

  (setq

    ldata (entget (car (entsel "\nSelect Line to find Text with insertion points on it: ")))

    end1 (cdr (assoc 10 ldata)); start point

    end2 (cdr (assoc 11 ldata)); end point

    txtss (ssget "_X" '((0 . "TEXT"))); all Text entities in drawing

    txton (ssadd); empty selection set of those with insertion points on Line

  ); setq

  (repeat (sslength txtss)

    (setq

      txt (ssname txtss 0); Text entity [first in set]

      ins (cdr (assoc 10 (entget txt))); its insertion point

    ); setq

    (if

      (or

        (equal ins end1 1e-6); on start point [change the 6 for different precision]

        (equal ins end2 1e-6); on end point

        (equal (angle end1 ins) (angle ins end2) 1e-6); along Line

      ); or

      (ssadd txt txton); add to on-the-Line set

    ); if

    (ssdel txt txtss); remove from overall set

  ); repeat

  (princ)

); defun

 

That should leave you with the 'txton' variable containing a selection set of all Text entities whose insertion points are on the selected Line.  [If other-than-World coordinates are possible, it would need to be more complicated.]

Kent Cooper, AIA
Message 3 of 9
grimeye
in reply to: Kent1Cooper

Thanks for your prompt reply. But it doesn't work for me. Any other advices?

Message 4 of 9
pbejse
in reply to: grimeye


@Anonymous wrote:

Thanks for your prompt reply. But it doesn't work for me. Any other advices?



grimeye.

 

Please don't just say it doesnt work for me, describe why, what are the conditions?

Message 5 of 9
_Tharwat
in reply to: Kent1Cooper

Mr Kent

 

You can use the function sssetfirst to high light the selection set that you have gathered .

 

e.g. as in your routine .

 

(if (> (sslength txtss) 0) (sssetfirst nil txtss))

 Tharwat

Message 6 of 9
Hallex
in reply to: grimeye

Sorry it's working good on my end,

guess your text didn't intersect a line,

try again:

;;KentCooper
(defun C:STOL (/ ldata end1 end2 txtss txt ins); = Select Text[s] with insertion point[s] On Line

  (setq

    ldata (entget (car (entsel "\nSelect Line to find Text with insertion points on it: ")))

    end1 (cdr (assoc 10 ldata)); start point

    end2 (cdr (assoc 11 ldata)); end point

    txtss (ssget "_X" '((0 . "TEXT"))); all Text entities in drawing

    txton (ssadd); empty selection set of those with insertion points on Line

  ); setq

  (repeat (sslength txtss)

    (setq

      txt (ssname txtss 0); Text entity [first in set]

      ins (cdr (assoc 10 (entget txt))); its insertion point

    ); setq

    (if

      (or

        (equal ins end1 1e-3); on start point [change the 6 for different precision];3 is enough?

        (equal ins end2 1e-3); on end point

        (equal (angle end1 ins) (angle ins end2) 1e-3); along Line

      ); or

      (ssadd txt txton); add to on-the-Line set

    ); if

    (ssdel txt txtss); remove from overall set

  ); repeat
  
(princ (strcat "\nCount: " (itoa (sslength txton))))
  
  (princ)

); defun

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 7 of 9
grimeye
in reply to: pbejse

Oh I'm really sorry. All texts on the drawing were selected, and the texts on a line were not selected. Please see the attached sample. My applogy again.

Message 8 of 9
pbejse
in reply to: grimeye


@Anonymous wrote:

Oh I'm really sorry. All texts on the drawing were selected, and the texts on a line were not selected. Please see the attached sample. My applogy again.


 

No worries, Tha fact of the matter is , the code does work, you may need to add thise lines 

)';repeat

(sssetfirst nil txton)
  (princ)

); defun

 

Like thatwats suggested. or

);repeat

(print (strcat (itoa (sslength txton)) " Text insertion on selected line :"))
  (princ)

)

 

Kent did say:

That should leave you with the 'txton' variable containing a selection set of all Text entities whose insertion points are on the selected

 

Can you try that now?

 

 

Message 9 of 9
Kent1Cooper
in reply to: grimeye


@Anonymous wrote:

.... But it doesn't work for me. Any other advices?


Thanks to others for their guidance [while I was in bed...].  I have now tested it, and for me it does put the Text entities into a selection set.  I didn't include highlighting them, partly because it was late, and partly because whether that's appropriate depends on what you plan to do with the selection.  If you wanted to include the identification process within some larger routine and immediately process them in some way [e.g. put them on a particular Layer, change their style or height, or something], then highlighting wouldn't serve any purpose.

 

If you call up a command involving object selection [Move, Copy, etc.], and at the selection prompt, type the variable name with an exclamation point before it:

 

!txton

 

you'll see that it has found them.

Kent Cooper, AIA

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost