LISP ? Macro? Pick Mtext by position Y

LISP ? Macro? Pick Mtext by position Y

adrielsimon
Explorer Explorer
475 Views
4 Replies
Message 1 of 5

LISP ? Macro? Pick Mtext by position Y

adrielsimon
Explorer
Explorer

Hello community, 

 

I am in need of a LISP or a Macro, or some sort of method to do the next:

I have to pick a Mtext entity. From this entity i have to pick any other Mtext entity that has the same position in the Y axis. 

Currently Im executing the Qselect, and manually selecting the parameters (Mtext, position Y, input Y dimension), but this process is getting quite bothersome. 

Anyone can provide me a hint to do this more efficiently?

Thank you, 

 

Simón Flores Medrano

0 Likes
Accepted solutions (2)
476 Views
4 Replies
Replies (4)
Message 2 of 5

johnyDFFXO
Advocate
Advocate
Accepted solution

Whatever you like...

 

As a macro for toolpalette or something..

(sssetfirst nil (ssget "_X" (list '(0 . "MTEXT") '(-4 . "*,=,*") (assoc 10 (entget (car (entsel "Mtext: ")))))))

 

Or as a command:

(defun c:selymtext () (sssetfirst nil (ssget "_X" (list '(0 . "MTEXT") '(-4 . "*,=,*") (assoc 10 (entget (car (entsel "Mtext: "))))))) (princ))

 

DEpending on how precise your drawing is might need to add some fuzz.

Message 3 of 5

ronjonp
Advisor
Advisor
Accepted solution

Here's one with a fuzz value for vertical or horizontal locations:

 

(defun c:foo (/ e p r)
  ;; RJP » 2023-05-02
  ;; Select all MTEXT that have a similar vertical or horizontal location
  (or *kw* (setq *kw* "H"))
  (if (and (progn (initget 0 "H V")
		  (setq	*kw* (cond ((getkword (strcat "Vertical or Horizontal<" *kw* ">:")))
				   (*kw*)
			     )
		  )
	   )
	   (setq e (car (entsel "\nPick MTEXT to get vertical selection: ")))
	   (setq p (cdr (assoc 10 (entget e))))
      )
    (progn (setq r (if (= "H" *kw*)
		     '((-4 . "*,>=,*") (0 1e-2 0) (-4 . "*,<=,*"))
		     '((-4 . ">=,*,*") (1e-2 0 0) (-4 . "<=,*,*"))
		   )
	   )
	   (sssetfirst
	     nil
	     (ssget "_X"
		    (list '(0 . "MTEXT")
			  '(-4 . "<AND")
			  (car r)
			  (cons 10 (mapcar '- p (cadr r)))
			  (caddr r)
			  (cons 10 (mapcar '+ p (cadr r)))
			  '(-4 . "AND>")
		    )
	     )
	   )
    )
  )
  (princ)
)

 

 

 

Message 4 of 5

adrielsimon
Explorer
Explorer
ty
0 Likes
Message 5 of 5

adrielsimon
Explorer
Explorer
Ty
0 Likes