lisp to select all the text and mtext which has a common Y position

lisp to select all the text and mtext which has a common Y position

symoin
Enthusiast Enthusiast
1,801 Views
5 Replies
Message 1 of 6

lisp to select all the text and mtext which has a common Y position

symoin
Enthusiast
Enthusiast

Hi, 

I am looking for a lisp which will erase all the texts and mtexts which have a common Y position in Autocad.

like select a text or mtext then based on the Y position of the selected text it should select all the text which are in the same alignment (same Y position). Then I may erase / move / copy or change properties based on my requirement.

Thank you all.

0 Likes
Accepted solutions (1)
1,802 Views
5 Replies
Replies (5)
Message 2 of 6

Sea-Haven
Mentor
Mentor

You need to select a text etc and get the Y value of insertion, then can use 

 

(setq ss (ssget "X" '((0 . "*TEXT")(cons 410 (getvar 'ctab)))))

 

You now have a selection set of all text in current space. You can check the Y value using Equal as the text can have very tiny differences of Y 0.0 v's 0.00000002 etc then delete.

 

You could using a combination of EXTMAX EXTMIN make a selection window with ssget so reducing the size of the selection set so will be faster to carry out task. Based on if text is bottom left alignment fairly straight forward. 

 

0 Likes
Message 3 of 6

ryanatkins49056
Enthusiast
Enthusiast

This is something I have and you do need to know what the coordinates are. It will automatically select all single line text when you enter in the appropriate coordinate it asks for. I should have something that would allow you to select a source entity and extract the coordinates out of it but not really sure where its located at the moment.

 

(defun c:xlintext ()
  (setq dirtyx (getreal "\n Enter X Value..."))
  (setq dirtyxlist (list 11 dirtyx 0.0 0.0))
  (setq dirtyxtest (ssget "X" (list '(0 . "TEXT") '(-4 . "=,*") dirtyxlist)))
  (command "PSELECT" dirtyxtest "")
)

(defun c:ylintext ()
  (setq dirtyy (getreal "\n Enter Y Value..."))
  (setq dirtyylist (list 11 0.0 dirtyy 0.0))
  (setq dirtyytest (ssget "X" (list '(0 . "TEXT") '(-4 . "*,=") dirtyylist)))
  (command "PSELECT" dirtyytest "")
)
 
Hope this helps
0 Likes
Message 4 of 6

ryanatkins49056
Enthusiast
Enthusiast
Accepted solution

Hello again,

 

I should also add using the QSELECT command at the command line also allows you to filterer down to the text via X and Y positions as well.

0 Likes
Message 5 of 6

Sea-Haven
Mentor
Mentor

A couple of suggestions, instead of entering X value just entsel a text and get its X value from insertion point of the text.

 

If the text has been moved or copied without say Ortho on its X value maybe slightly off so will not find all at that X value. That is why I suggested using a window selection.

 

 

0 Likes
Message 6 of 6

ronjonp
Mentor
Mentor

@symoin Here's an example using an SSGET filter to grab text with a common Y value. The downside is the text have to be at the EXACT Y location otherwise it will fail.

 

(defun c:foo (/ e p s)
  ;; RJP » 2024-03-04
  (cond
    ((and (setq e (car (entsel "\nPick text to grab Y coordinate: ")))
	  (setq p (assoc 10 (entget e)))
     )
     (sssetfirst nil (setq s (ssdel e (ssget "_X" (list (assoc 0 (entget e)) '(-4 . "*,=,*") p)))))
     ;; Uncomment line below to delete
     ;; (and s (mapcar 'entdel (mapcar 'cadr (ssnamex s))))
    )
  )
  (princ)
)

 

2024-03-04_17-05-01.gif

0 Likes