Author Topic: Highlight text with GRDRAW  (Read 7496 times)

0 Members and 1 Guest are viewing this topic.

Logan

  • Newt
  • Posts: 41
Highlight text with GRDRAW
« on: February 01, 2014, 09:49:54 AM »
Hello guys.

I'm looking for a function that draws temporary objects, rectangles, polygons, triangles or circles around objects of type text. I give the function a list of objects of type text previously selected. The aim is to highlight a selection of objects.

I'm using the following line to change the color of objects.
Code - Auto/Visual Lisp: [Select]
  1. (foreach e text (vla-put-color (vlax-ename->vla-object e) 1))
  2.  

I found many examples of how to use the function grdraw, nothing like what I seek.

Can someone help me?
 
Thank you very much.

kruuger

  • Swamp Rat
  • Posts: 637
Re: Highlight text with GRDRAW
« Reply #1 on: February 01, 2014, 10:01:50 AM »
Hello guys.

I'm looking for a function that draws temporary objects, rectangles, polygons, triangles or circles around objects of type text. I give the function a list of objects of type text previously selected. The aim is to highlight a selection of objects.

I'm using the following line to change the color of objects.
Code - Auto/Visual Lisp: [Select]
  1. (foreach e text (vla-put-color (vlax-ename->vla-object e) 1))
  2.  

I found many examples of how to use the function grdraw, nothing like what I seek.

Can someone help me?
 
Thank you very much.
the best option for me to highlight something is draw a "spider".
check sample here http://www.cadtutor.net/forum/showthread.php?52730-Spiderdim-lisp
kruuger

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Highlight text with GRDRAW
« Reply #2 on: February 01, 2014, 10:05:06 AM »
If you mean "highlight" in the same way as acad highlights objects while the user interactively selects them, then look at the vla-highlight method: http://www.afralisp.net/archive/methods/lista/highlight_method.htm

Otherwise, if you want to "draw temporary objects", then draw them around the text's vla-getBoundingBox method: http://www.afralisp.net/archive/methods/lista/getboundingbox_method.htm

You can either draw lines using grdraw, or a set of lines using grvecs, or actually placing new objects and then deleting them after they're not needed anymore.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Logan

  • Newt
  • Posts: 41
Re: Highlight text with GRDRAW
« Reply #3 on: February 01, 2014, 10:37:14 AM »

the best option for me to highlight something is draw a "spider".
check sample here http://www.cadtutor.net/forum/showthread.php?52730-Spiderdim-lisp
kruuger

Hey Kruuger, yesterday I came across your program. It very interesting, but not what I seek.
Thank you very much.

kruuger

  • Swamp Rat
  • Posts: 637
Re: Highlight text with GRDRAW
« Reply #4 on: February 01, 2014, 10:57:00 AM »

the best option for me to highlight something is draw a "spider".
check sample here http://www.cadtutor.net/forum/showthread.php?52730-Spiderdim-lisp
kruuger

Hey Kruuger, yesterday I came across your program. It very interesting, but not what I seek.
Thank you very much.
http://lee-mac.com/boxtext.html
k.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Highlight text with GRDRAW
« Reply #5 on: February 01, 2014, 11:27:11 AM »

Logan

  • Newt
  • Posts: 41
Re: Highlight text with GRDRAW
« Reply #6 on: February 01, 2014, 11:33:41 AM »
If you mean "highlight" in the same way as acad highlights objects while the user interactively selects them, then look at the vla-highlight method: http://www.afralisp.net/archive/methods/lista/highlight_method.htm

Otherwise, if you want to "draw temporary objects", then draw them around the text's vla-getBoundingBox method: http://www.afralisp.net/archive/methods/lista/getboundingbox_method.htm

You can either draw lines using grdraw, or a set of lines using grvecs, or actually placing new objects and then deleting them after they're not needed anymore.

Hello Irneb, thanks for the examples.

The first method is interesting but does not draw attention to need.

The second method may be the beginning of what I seek. The problem I'm still not sufficient to draw using grdraw taking as reference object edges knowledge.

Regarding the last option, create objects and then delete them, do not know if it's a good idea to me. I'm finding some difficulties with the function (* error *) when the program is canceled by the ESC key.
I know things are simple to fix, even I'm starting to walk. Have a little patience.

Thanks for the replies.

Logan

  • Newt
  • Posts: 41
Re: Highlight text with GRDRAW
« Reply #7 on: February 01, 2014, 11:56:52 AM »
Another example to consider:

http://www.theswamp.org/index.php?topic=39951.0

Hello Lee

I was responding to irneb when you posted your comment, then edited.
I'd put this link, bumped into him a few days ago.

I'm looking for something exactly like this, but I have no knowledge to draw rectangles or any objects. To be honest even tried to understand the method you used, but I'm still very new in autolisp. You could set your program for my situation?  :embarrassed:

No need of reference lines, I just need to highlight with an object, the texts contained in the list.

Thank you for your attention.

VovKa

  • Water Moccasin
  • Posts: 1631
  • Ukraine
Re: Highlight text with GRDRAW
« Reply #8 on: February 01, 2014, 12:57:53 PM »
i use
Code: [Select]
(defun vk_Wait (Time / End)
    (setq End (+ (getvar 'MILLISECS) Time))
    (while (> End (getvar 'MILLISECS)))
)
(defun vk_BlinkEnt (EntName Time / Wait)
    (setq Wait 50)
    (repeat (/ Time Wait 2)
(redraw EntName 3)
(princ)
(vk_Wait Wait)
(redraw EntName 4)
(princ)
(vk_Wait Wait)
    )
)

Logan

  • Newt
  • Posts: 41
Re: Highlight text with GRDRAW
« Reply #9 on: February 01, 2014, 01:43:47 PM »
i use
Code: [Select]
(defun vk_Wait (Time / End)
    (setq End (+ (getvar 'MILLISECS) Time))
    (while (> End (getvar 'MILLISECS)))
)
(defun vk_BlinkEnt (EntName Time / Wait)
    (setq Wait 50)
    (repeat (/ Time Wait 2)
(redraw EntName 3)
(princ)
(vk_Wait Wait)
(redraw EntName 4)
(princ)
(vk_Wait Wait)
    )
)

Hello Vovka.
Could you give me an example of use?
Thanks for help.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Highlight text with GRDRAW
« Reply #10 on: February 01, 2014, 02:11:26 PM »
I'm looking for something exactly like this, but I have no knowledge to draw rectangles or any objects. To be honest even tried to understand the method you used, but I'm still very new in autolisp. You could set your program for my situation?  :embarrassed:

Consider the following example:

Code: [Select]
(defun c:hltext ( / *error* cur enx itm lst sel )

    (defun *error* ( msg )
        (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
            (princ (strcat "\nError: " msg))
        )
        (redraw) (princ)
    )
    (princ "\nSelect text: ")
    (while (member (car (setq cur (grread nil 15 2))) '(3 5))
        (if (= 3 (car cur))
            (if (ssget (cadr cur))
                (if (setq sel (ssget (cadr cur) '((0 . "TEXT,MTEXT"))))
                    (if (setq enx (entget (ssname sel 0))
                              itm (assoc (cdr (assoc 5 enx)) lst)
                        )
                        (setq lst (vl-remove itm lst))
                        (setq lst (cons (cons (cdr (assoc 5 enx)) (text-box enx (/ (cdr (assoc 40 enx)) 2.0))) lst))
                    )
                    (princ "\nInvalid object selected.\nSelect text: ")
                )
                (princ "\nMissed, try again.\nSelect text: ")
            )
        )
        (redraw)
        (foreach x lst
            (mapcar '(lambda ( a b ) (grdraw a b 1 1)) (cdr x) (cons (last x) (cdr x)))
        )
    )
    (redraw) (princ)
)

;; Text Box  -  gile / Lee Mac
;; Returns an OCS point list describing a rectangular frame surrounding
;; the supplied text or mtext entity with optional offset
;; enx - [lst] Text or MText DXF data list
;; off - [rea] offset (may be zero)
 
(defun text-box ( enx off / b h j l m n o p r w )
    (if
        (setq l
            (cond
                (   (= "TEXT" (cdr (assoc 0 enx)))
                    (setq b (cdr (assoc 10 enx))
                          r (cdr (assoc 50 enx))
                          l (textbox enx)
                    )
                    (list
                        (list (- (caar  l) off) (- (cadar  l) off))
                        (list (+ (caadr l) off) (- (cadar  l) off))
                        (list (+ (caadr l) off) (+ (cadadr l) off))
                        (list (- (caar  l) off) (+ (cadadr l) off))
                    )
                )
                (   (= "MTEXT" (cdr (assoc 0 enx)))
                    (setq n (cdr (assoc 210 enx))
                          b (trans  (cdr (assoc 10 enx)) 0 n)
                          r (angle '(0.0 0.0 0.0) (trans (cdr (assoc 11 enx)) 0 n))
                          w (cdr (assoc 42 enx))
                          h (cdr (assoc 43 enx))
                          j (cdr (assoc 71 enx))
                          o (list
                                (cond
                                    ((member j '(2 5 8)) (/ w -2.0))
                                    ((member j '(3 6 9)) (- w))
                                    (0.0)
                                )
                                (cond
                                    ((member j '(1 2 3)) (- h))
                                    ((member j '(4 5 6)) (/ h -2.0))
                                    (0.0)
                                )
                            )
                    )
                    (list
                        (list (- (car o)   off) (- (cadr o)   off))
                        (list (+ (car o) w off) (- (cadr o)   off))
                        (list (+ (car o) w off) (+ (cadr o) h off))
                        (list (- (car o)   off) (+ (cadr o) h off))
                    )
                )
            )
        )
        (   (lambda ( m ) (mapcar '(lambda ( p ) (mapcar '+ (mxv m p) b)) l))
            (list
                (list (cos r) (sin (- r)) 0.0)
                (list (sin r) (cos r)     0.0)
               '(0.0 0.0 1.0)
            )
        )
    )
)
 
;; Matrix x Vector  -  Vladimir Nesterovsky
;; Args: m - nxn matrix, v - vector in R^n
 
(defun mxv ( m v )
    (mapcar '(lambda ( r ) (apply '+ (mapcar '* r v))) m)
)

(princ)


Logan

  • Newt
  • Posts: 41
Re: Highlight text with GRDRAW
« Reply #11 on: February 01, 2014, 03:28:25 PM »
Lee, thank you very much.
That's exactly what I need.
Without wanting to abuse their generosity, as I would call your function in a ForEach?
To change the color of text to red i'm using the following line:

Code: [Select]
(foreach e text (vla-put-color (vlax-ename->vla-object e) 1))
Thank you in advance.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Highlight text with GRDRAW
« Reply #12 on: February 01, 2014, 04:04:41 PM »
You're welcome Logan  :-)

Assuming 'text' is a list of text entities, try the following:

Code: [Select]
(foreach e text
    (setq e (entget e)
          l (text-box e (/ (cdr (assoc 40 e)) 2.0))
    )
    (entmod (append e '((62 . 1))))
    (mapcar '(lambda ( a b ) (grdraw a b 1 1)) l (cons (last l) l))
)

Logan

  • Newt
  • Posts: 41
Re: Highlight text with GRDRAW
« Reply #13 on: February 01, 2014, 05:14:58 PM »
You're welcome Logan  :-)

Assuming 'text' is a list of text entities, try the following:

Code: [Select]
(foreach e text
    (setq e (entget e)
          l (text-box e (/ (cdr (assoc 40 e)) 2.0))
    )
    (entmod (append e '((62 . 1))))
    (mapcar '(lambda ( a b ) (grdraw a b 1 1)) l (cons (last l) l))
)

Yes, perfect. :lol:
What more can I say.
Thank you Lee, I admire your work.

Thanks to everyone who gave their contribution.
Until next.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Highlight text with GRDRAW
« Reply #14 on: February 01, 2014, 06:37:27 PM »
Thank you Logan - happy to help  :-)