Author Topic: Closest text string to a point  (Read 5922 times)

0 Members and 1 Guest are viewing this topic.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Closest text string to a point
« Reply #15 on: October 01, 2010, 12:48:08 AM »

Should work fine Alan.
Probably at a severe disadvantage time-wise due to iterating the complete database.
.. also, it won't satisfy the OP's requirement regarding being at the "Correct" location

... but heh, it's Friday afternoon so I'd buy it  :-)

ps : that's a significant sort  statement sir ... very busy !
 I like it
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Closest text string to a point
« Reply #16 on: October 01, 2010, 08:57:12 AM »
I don't know why but I got the sense that this was headed to a ObjectDBX application. :?
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Closest text string to a point
« Reply #17 on: October 01, 2010, 03:22:21 PM »


Perhaps, Alan's sneaky like that  :-D

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

johnson

  • Guest
Re: Closest text string to a point
« Reply #18 on: March 14, 2011, 10:48:32 AM »
Just for kicks, what about grabbing the object closest to the picked point? I hope I'm not stepping on your toes, Kerry; I just wanted to throw another thought/direction out there.

Code: [Select]
(defun _selectClosestTextToPoint (pt / ss)
  (if (and (vl-consp pt)
           (setq ss (ssget "_X"
                           (list '(0 . "TEXT")
                                 (cons 410
                                       (if (eq 1 (getvar 'cvport))
                                         (getvar 'ctab)
                                         "Model"
                                       )
                                 )
                           )
                    )
           )
      )
    (caar (vl-sort
            ((lambda (i / e l)
               (while (setq e (ssname ss (setq i (1+ i))))
                 (setq l (cons (cons e (cdr (assoc 10 (entget e)))) l))
               )
             )
              -1
            )
            (function
              (lambda (a b)
                (< (distance (trans pt 1 (car a)) (cdr a)) (distance (trans pt 1 (car b)) (cdr b)))
              )
            )
          )
    )
  )
)

eg.
Code: [Select]
(vla-put-color (vlax-ename->vla-object (_selectClosestTextToPoint (getpoint "\nSpecify point: "))) 3)


how to find the text using contents with highlighting method except qselect method.i want highlight how many my given contents text availble in selected area

hmspe

  • Bull Frog
  • Posts: 362
Re: Closest text string to a point
« Reply #19 on: March 14, 2011, 11:35:20 AM »
What I've used is

Code: [Select]
  (defun getss (apnt adist)
    (ssget "c"
      (list (- (car apnt) adist) (- (cadr apnt) adist))
      (list (+ (car apnt) adist) (+ (cadr apnt) adist))
    )
  )

apnt is the assumed location point.  adist is 1/2 the size of the search box.  Depending on what I'm trying to do I'll set adist to a reasonable size then test the entities returned, or I'll set up a loop that starts with a small value for adist and increments until the correct type entity is found.
"Science is the belief in the ignorance of experts." - Richard Feynman

johnson

  • Guest
Re: Closest text string to a point
« Reply #20 on: March 17, 2011, 10:45:06 AM »
hmspe i have tried with cad2007..but no response

Brick_top

  • Guest
Re: Closest text string to a point
« Reply #21 on: March 17, 2011, 11:11:47 AM »
Curiously enought I made this a couple of days ago

Not exactly what you want but might help.

This will change the Z of a point to the value of the closest text string.
sorry, It wont change. It will create a new point

Code: [Select]
;mudar z de pontos para o valor do texto mais próximo
;

(defun c:tzp (/ polst txtlstf dstf)

  (setq wd (getpoint "\nSeleccionar janela à volta dos objectos a calcular:")
wdc (getcorner wd)
        tss (ssget "_W" wd wdc '((0 . "TEXT")(8 . "T_Z")))[color=red];specific layer name[/color]
        poss (ssget "_W" wd wdc '((0 . "POINT")(8 . "T_PONTOS"))) [color=red];specific layer name[/color]
num 0
num1 0
num2 0
  );setq
  (repeat (sslength poss)
    (setq ent (entget (ssname poss num))
  poip (cdr (assoc 10 ent))
  polst (append (list poip) polst) ;lista dos pontos sem z
  num (+ 1 num)
     );setq
    );repeat
  (repeat (sslength tss)
    (setq txtent (entget (ssname tss num1))
  txtval (atof (cdr (assoc 1 txtent)))
  txtcoord (cdr (assoc 10 txtent))
  txtlst (list txtcoord (list txtval))
  txtlstf (append (list txtlst) txtlstf)
  num1 (+ 1 num1)
    );setq
   );repeat
  (repeat (length txtlstf)
    (setq txtcoordt (nth num2 txtlstf)
  dlst (mapcar '(lambda (x) (list x (list (distance (car txtcoordt) x)) (cadr txtcoordt))) polst)
  dlstmin (vl-sort dlst '(lambda (d1 d2) (< (car (cadr d1))(car (cadr d2)))))
  dstf (append (list (car dlstmin)) dstf)
  num2 (+ 1 num2)
    );setq
  );repeat
  (setq ptf (mapcar '(lambda (x)(entmake (list (cons 0 "POINT")
       (cons 8 "00_Pontos_Z")
                                               (cons 10 (list (car (car x))(cadr (car x))(* (+ (caddr (car x)) 1) (car (caddr x)))))))) dstf)
  );setq

 );defun
 

hmspe

  • Bull Frog
  • Posts: 362
Re: Closest text string to a point
« Reply #22 on: March 17, 2011, 12:14:57 PM »
hmspe i have tried with cad2007..but no response

Here's example code.  There is no error checking.  It changes OSMODE to 0.  It relies on having DIMSCALE set.

Code: [Select]
[font=courier](defun c:test ( / scale point sse counter string)

  (defun dxf (1code 1ent) (cdr (assoc 1code 1ent)))  ; returns the value assigned to a dxf code

  (defun getss (apnt adist)                          ; gets a selection set using a bounding box
                                                     ; based on the apnt point (x,y) passed, box
                                                     ; bounded by (x-adist,y-adist),(x+adist,y+adist)
    (ssget "c"
      (list (- (car apnt) adist) (- (cadr apnt) adist))
      (list (+ (car apnt) adist) (+ (cadr apnt) adist))
    )
  )

  (setq scale (getvar "dimscale"))
  (setq point (getpoint "\nSelect existing entry or insertion point ... "))
  (setvar "OSMODE" 0)                                ; turn off osnaps
  (setq string nil)
  (setq counter 1)
  (while (and (= string nil)
              (< counter 100)
         )
    (if (setq sse (getss point (* scale 0.03 counter)))
                                                     ; Get the entity at the insertion point.
      (progn
        (setq ent (entget (ssname sse 0)))           ; get the entity
        (if (= (dxf 0 ent) "TEXT")
          (setq string (dxf 1 ent))
        )
      )
    )
    (setq counter (1+ counter))
  )
  (print string)
)
[/font]
"Science is the belief in the ignorance of experts." - Richard Feynman