Author Topic: Need some help with this routine I found  (Read 2108 times)

0 Members and 1 Guest are viewing this topic.

Brick_top

  • Guest
Need some help with this routine I found
« on: September 22, 2014, 04:40:45 AM »
hi there I found this great routine from Gile and I would like to incorporate it into a routine of mine but I haven't been able to do it.

Here is his routine:

Code: [Select]
;; DDATA (gile)
;; Display the mtext which is linked to the entity under the cursor

(defun c:ddata (/ *error* gr ent text ent str norm pt lst)
  (vl-load-com)

  (defun *error* (msg)
    (and msg
(/= msg "Function cancelled")
(princ (strcat "Error: " msg))
    )
    (and text (entdel text))
    (and ent (redraw ent 4))
    (princ)
  )

  (sssetfirst nil nil)
  (while (= (car (setq gr (grread T 14 2))) 5)
    (and text (entdel text) (setq text nil))
    (and ent (redraw ent 4))
    (setq pt (cadr gr))
    (if
      (and
(setq ent (ssget pt '((-3 ("DynDisplayData")))))
(setq ent (ssname ent 0))
(setq lst (cdadr (assoc -3 (entget ent '("DynDisplayData")))))
      )
       (progn
(redraw ent 3)
(setq size (/ (getvar "VIEWSIZE") 50.) ; hauteur de texte
       norm (trans '(0 0 1) 2 0 t)
       text (entmakex
      (append
(list
  '(0 . "MTEXT")
  '(100 . "AcDbEntity")
  '(100 . "AcDbMText")
  (cons 10
(trans
  (polar (trans pt 1 2) (* pi 1.75) size)
  2
  0
)
  )
  (cons 40 size)
  '(41 . 0.)
  (cons 1 "")
  (cons 7 (getvar 'textstyle))
  (cons 210 norm)
  (cons 11 (trans '(1 0 0) 2 0 T))
)
(if (assoc 1070 lst)
  (list
    (cons 90 (cdr (assoc 1070 lst)))
    (cons 63 (cdr (assoc 1071 lst)))
    (cons 45 (cdr (assoc 1040 lst)))
  )
)
      )
    )
)
(vla-put-TextString (vlax-ename->vla-object text) (cdr (assoc 1000 lst)))
       )
    )
  )
  (*error* nil)
)

it shows a text from xdata of an object when you put the mouse over it.

what I would like it to do is to make it show a text I have in xrecord which I would get by the info I have in xdata of an object.

can anyone give me some ideias on how to do it?

thanks
« Last Edit: September 22, 2014, 05:50:05 AM by Brick_top »

Brick_top

  • Guest
Re: Need some help with this routine I found
« Reply #1 on: September 22, 2014, 04:55:12 AM »
I tryed to make it on my own but so far I only have this:

Code: [Select]
(defun c:grtest ()
 (while
   (and
     (setq a (grread T 14 2)) (= (car a) 5)
     );and
     (setq mcoord (cadr a);coordenadas do rato
   entf (ssget mcoord);encontrou entidade
     );setq
     (if entf
       (progn
(setq ent (ssname entf 0)) ;nome da entidade seleccionada
(redraw ent 3) ;mostrar entidade seleccionada
       );progn
       (redraw ent 4) ;mostrar entidade sem visibilidade de entidade seleccionada
     );if
   );while
  );defun

which highlights a selected object when you put the mouse over it.

But now I don't know how to make it show the text I want.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Need some help with this routine I found
« Reply #2 on: September 22, 2014, 08:30:36 AM »
Since you appear to be able to read/write xdata and dictionary data, you should have all the tools you need. Taking gile's function all you have to do is:
1.
Change "DynDisplayData" to your application name.
2.
Remove the (if (assoc 1070 lst) ...) section.
3.
Extract the right info from lst (= xdata).
4.
Use that info to retrieve the right dict. data.
5.
Update the (vla-put-TextString (vlax-ename->vla-object text) ...) line.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Need some help with this routine I found
« Reply #3 on: September 22, 2014, 08:33:39 AM »
... And there are numerous examples of xdata and dictionary data handling on this forum.

Brick_top

  • Guest
Re: Need some help with this routine I found
« Reply #4 on: September 22, 2014, 08:38:47 AM »
Ok, I'll see what I can do.

thanks for your reply

Brick_top

  • Guest
Re: Need some help with this routine I found
« Reply #5 on: September 22, 2014, 08:59:19 AM »
thanks a lot for the help it seems I got some of it working now  :-)

Brick_top

  • Guest
Re: Need some help with this routine I found
« Reply #6 on: September 23, 2014, 06:30:31 AM »
I'm stuck with a problem

If I got it right the way the mtext uses new lines is to use "\\". I have formatted the text I want to use but the final result isn't new lines but the "\\" get represent by this "\".

hope I was clear enough

edit - oops I think I got the new line "thing" wrong, it is "\\P" I think

edit2 - yes I confirmed I got it wrong. with "\\P" it works
« Last Edit: September 23, 2014, 06:35:14 AM by Brick_top »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Need some help with this routine I found
« Reply #7 on: September 23, 2014, 08:03:46 AM »
Looks like you figured it out.  8)
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.

Brick_top

  • Guest
Re: Need some help with this routine I found
« Reply #8 on: September 23, 2014, 09:12:18 AM »
yes finally! I can do it now

sometimes knowing this forum exists is a temptation to get a quick answer to a problem.

Fortunately many times I post anything I find a solution right after without anyone answering