getting a text entity at a point

getting a text entity at a point

kpennell
Collaborator Collaborator
3,139 Views
25 Replies
Message 1 of 26

getting a text entity at a point

kpennell
Collaborator
Collaborator

Is there any way using 'ssget' that I can get a text entity at a non-specific point?  Like:

 

(ssget "X" '((0 . "TEXT")(11 318.03737793 9.13950144 0.0)))

 

Or will I have to retrieve all texts in the drawing, and do a compare?  Like this:

 

(and (= (cdr (assoc 0 ent1)) "TEXT") (equal (cdr (assoc 11 ent1)) '(318.03737793 9.13950144 0.0) 1e-8))

 

 

0 Likes
3,140 Views
25 Replies
Replies (25)
Message 21 of 26

john.uhden
Mentor
Mentor
I'll raise you a penny.
Do you mean 4 points, or 4 times around?

John F. Uhden

0 Likes
Message 22 of 26

Sea-Haven
Mentor
Mentor

Example

 

(setq p2 (mapcar '+ p1 (list 1 1 0.0))
p3 (mapcar '+ p1 (list -1 1 0.0))
p4 (mapcar '+ p1 (list -1 -1 0.0))
p5 (mapcar '+ p1 (list 1 -1 0.0)))
(setq pts (list pt2 pt3 pt4 pt5 pt2))
(setq ss (ssget "F" pts '((0 . "TEXT"))))

 

0 Likes
Message 23 of 26

john.uhden
Mentor
Mentor
Only one time around? 😁

John F. Uhden

0 Likes
Message 24 of 26

john.uhden
Mentor
Mentor

I was thinking over the weekend (scary, eh?)...

that the size of your PICKBOX determines how much drawing area one pick can cover,

and that nentselp doesn't need user input and is not restricted to nested entities.

So I just tested with the following by picking an empty spot in the middle of an MTEXT.

(defun c:test ( / p pick)
  (princ (strcat "\nPICKBOX is starting at " (itoa (getvar "pickbox")) "."))
  (setq p (getpoint "\nPick roughly where you think text is: "))
  (while (not pick)
    (setq pick (nentselp p))
    (if (not pick)(setvar "pickbox" (1+ (getvar "pickbox"))))
  )
  (princ (strcat "\nPICKBOX ended at " (itoa (getvar "pickbox")) ".\n"))
  pick
)

And, lo, it is true.  Growing the pickbox ended up finding the mtext.

Of course if you are zoomed out it may not have to grow at all.

 

John F. Uhden

0 Likes
Message 25 of 26

john.uhden
Mentor
Mentor

@kpennell and @Sea-Haven,

The pickbox approach applies to (ssget) as well as (nentselp) which means you can add the filter whereas (nentselp) does not accept a filter.

Here.  Try it out for yourself.

 

(defun c:OnePick ( / *error* vars vals p ss)
   (defun *error* (err)
      (mapcar 'setvar vars vals)
      (vla-endundomark Doc)
      (cond
         ((not err))
         ((wcmatch (strcase err) "*CANCEL*,*QUIT*")
            (vl-exit-with-error "\r                                        ")
         )
         (1 (vl-exit-with-error (strcat "\r*ERROR*: " err)))
      )
      (princ)
   )
   ;;-------------------------------------------
   ;; Initialize drawing and program variables:
   ;;
   (setq Doc (vlax-get (vlax-get-acad-object) 'Activedocument)
         vars '("cmdecho" "pickbox")
         vals (mapcar 'getvar vars)
   )
   (vla-endundomark Doc)
   (vla-startundomark Doc)
   (setvar "cmdecho" 0)
   (command "_.expert" (getvar "expert")) ;; dummy command

  (princ (strcat "\nPICKBOX is starting at " (itoa (getvar "pickbox")) "."))
  (setq p (getpoint "\nPick roughly where you think text is: "))
  (while (not ss)
    (setq ss (ssget p '((0 . "*TEXT"))))
    (if (not ss)(setvar "pickbox" (1+ (getvar "pickbox"))))
  )
  (princ (strcat "\nPICKBOX ended at " (itoa (getvar "pickbox")) ".\n"))
  (sssetfirst nil ss)
  (*error* nil)
)
(defun c:OP ()(c:OnePick))

 

You could rearrange it to be a simple function that takes a point and a filter as arguments...

 

(defun OnePick (p filter / *error* pb ss)
  (defun *error* (err)
    (setvar "pickbox" pb)
    (princ)
  )
  (setq pb (getvar "pickbox"))
  (while (not ss)
    (setq ss (ssget p filter))
    (if (not ss)(setvar "pickbox" (1+ (getvar "pickbox"))))
  )
  (sssetfirst nil ss)
  (*error* nil)
)

 

 

John F. Uhden

0 Likes
Message 26 of 26

Sea-Haven
Mentor
Mentor

Nice idea about pickbox so many times get asked find something else near to a point like parallel lines.

0 Likes