Jump to content

Recommended Posts

Posted

 

Hi again,
I'm trying to figure out a way for changing text to be displayed in real time next to the cursor during the execution of a Lisp code, when it gets close to objects with relevant information.
Is there a simple way to achieve this?

Thanks in advance.

Posted (edited)

I guess using GRREAD to pick a point in real time and behind the scenes do a search box looking for text and in particular a match say "ABC" in "ABCDEFGH" if yes then zoom in on that text. I am not good at GRREAD code so some one else may be able to help. Search box.part based on a pick point.

 

(setq off 18) ; needs to be changed to suit a dwg.
(while (setq pt (getpoint "\nPick point "))
(setq pt1 (polar pt (* 0.25 pi) off))
(setq pt2 (polar pt (* 0.75 pi) off))
(setq pt3(polar pt (* 1.25 pi) off))
(setq pt4 (polar pt (* 1.75 pi) off))
(setq pts (list pt1 pt2 pt3 pt4 pt1))
(setq ss (ssget "CP" pts '((0 . "TEXT"))))
(if (= ss nil)
(princ "\n nothing found ")
(princ (strcat "\n" (cdr (assoc 1 (entget (ssname ss 0)))) " found"))
)
)

 

Edited by BIGAL
  • Like 2
  • Agree 1
Posted

 

Thank you all for your replies.

 

Bigal, I don’t really understand how to use that.

 

Mhupp, I discovered LeeMac’s GRText a few weeks ago, but it’s too long and I haven’t been able to figure out how it works.

 

Daniel, it’s very interesting and quite similar to what I’m looking for, but I’d prefer it to be in Lisp since it’s the only language I understand a bit.
Could it be implemented as a DLL to be called from Lisp? That way, it might be more versatile across both recent and older versions of AutoCAD, right?

 

I have a routine that inserts text labels indicating the insertion point on the screen.
But I’d like to see a distance indicator relative to the previous label inserted.
I’ll also try to make it so that, when the cursor hovers over an object on certain layers, it shows the value of any interesting property at the cursor

Posted

Although I suppose the reference for this is Lee Mac's GRText because it's not easy to achieve something simpler.
So I'll keep trying to assimilate Lee Mac's code.

Anyway, it would be great news for me if anyone can suggest something simpler.

Posted

Hi
I understand you want all of this to happen while executing the same command.

 

Posted (edited)

Something simpler is actually possible.

But it will also be less efficient.

However, if your PC isn't too slow, this won't matter much.

 

But, in return, I think it will be more versatile, manageable, and simpler.

 

When I get home, I'll explain a little more.

Edited by GLAVCVS
Posted

One of the things you can do is get all text and then look at each one and if it matches your search then zoom to that text and ask change ? This has been done before.

Posted (edited)

After seeing @BIGAL's suggestion, I'm wondering if I understood correctly what you're asking, Vica.

Anyway, I'm attaching a short clip of what I'm talking about.

 

I’ve implemented a small emulator of the "pline" command in the base code, but each user should implement the code they need for their specific task instead.
Basically, the distance variation from the last stored point in LASTPOINT is displayed above the cursor (though this can be easily changed by modifying the textoGR1 function).
Below the cursor, any desired information about the object under it will be shown (or not, if visibility is toggled by pressing the F10 key). This information must be passed to the textoGR2 function as a list of (Property_Name  StringValue) pairs.

The main code must be implemented in the 'FuncionPrincipal' function.

Edited by GLAVCVS
  • Like 6
Posted

pretty slick! you made a Jig in lisp :)

  • Like 2
Posted (edited)

Wow!

That looks great.

But the Lisp, where is it?

Can you share it, please?

 

Edited by Vica
Posted (edited)

 

Hi
I’m attaching the code.
But first, a brief explanation of how it works.

The function is implemented by calling MiGRTexto with one parameter: the desired height for the real-time texts (this should be a value between 0.5 and 1)
Therefore, it can be placed inside a main function that can be called from the command line (e.g., (defun c:myCommand)).

As for the code that provides functionality, it's actually very simple: it consists of a text next to the right CROSSHAIR and an MTEXT below it. These must be properly managed so that they dynamically update their size, location and content—it's that straightforward.
From there, it’s just a matter of adding code to achieve whatever final functionality the user needs.

In the attached code, a small emulator for the "pline" command is implemented, triggered by a LEFT CLICK event. This event calls funcionPrincipal, which is provided with two arguments: the screen point indicated and the entity name (or nil) of the object under the PICKBOX at that location.
These two arguments should be enough to enable any subsequent operation.

It’s important to note that the entire behavior relies on GRREAD, and therefore on mouse and keyboard events. These events are handled using several clauses within a cond expression, which can be extended or modified by the user.

I haven’t implemented any code to add object snap functionality. Doing so would considerably complicate the code, and for some users, it may not be necessary.
In any case, suggestions and improvements (regarding snapping or any other proposals) are welcome in this thread—for those (myself included) who may want to improve or add new features.

I won’t go on any further.

Now, the code...

 

;*******************  p o r d e s í a r g o  ********************
;************************ G L A V C V S *************************
;************************** F E C I T ***************************
(defun MiGRTexto (factor / l se e le txTmp txTmp1 txOk tam p pa pt pt1 i? v1 polil alt tx para erroria errores error0 textoGR1 textoGR2 funcionPrincipal)
  (defun erroria ()
    (defun errores (mens)
      (setq *error* error0)
      (vla-delete txTmp)
      (vla-delete txTmp1)
      (redraw)
      (if e (redraw e 4))
      (prin1)
    )
    (setq error0  *error*
	  *error* errores
    )
  )
  (defun funcionPrincipal (pt e)
    (setvar 'LASTPOINT pt)
    
;;;INICIO(START) EMULAD(T)OR "pline"
    (if polil
      (entmod (append (entget polil) (list (cons 10 pt))))
      (if (entmake (list '(0 . "LWPOLYLINE")
			 '(100 . "AcDbEntity")
			 '(100 . "AcDbPolyline")
			 (cons 8 "0")
			 (cons 90 2)
			 '(70 . 128)
			 '(62 . 256)
			 (cons 10 pa)
			 (cons 10 pt)
		   )
	  )
	(setq polil (entlast))
      )
    )
    (setq pa pt)
;;;FIN(END) EMULAD(T)OR "pline"
    
  )
  (defun textoGR1 ()    ;THIS FUNCTION RETURN TEXT STRING TO DISPLAY ABOVE CURSOR. ADJUST IT TO SUIT YOUR NEEDS
    			;ESTA FUNCIÓN DEVUELVE EL TEXTO A MOSTRAR SOBRE EL CURSOR. MIDIFÍCALA SEGÚN LO NECESITES
    (rtos (distance (getvar 'LASTPOINT) p) 2 3)
  )
  (defun textoGR2 (lp / lp MT) ;ESTA FUNCIÓN DA EL FORMATO NECESARIO AL MTEXT QUE SE MOSTRARÁ BAJO EL CURSOR
    (foreach l lp
      (if MT
        (setq MT (strcat MT (car l) " {\\fLucida Sans Unicode|b0|i0|c0|p34;\\C4;" (cadr l) "}"))
        (setq MT (strcat (car l) " {\\fLucida Sans Unicode|b0|i0|c0|p34;\\C4;" (cadr l) "}"))
      )
      (setq MT (if (equal l (last lp)) MT (strcat MT "\\P")))
    )
  )
  (defun dameGRT2 (le / cl to)  ;THIS FUNCTION RETURN THE LIST OF PAIRS THAT textoGR2 NEEDS TO FORMAT CONTENTS OF MTEXT. ADJUST IT TO SUIT YOUR NEEDS
    				;ESTA FUNCIÓN DEVUELVE LA LISTA DE PARES QUE NECESITA textoGR2 PARA GENERAR LA CADENA DE TEXTO QUE NECESITA EL MTEXT
    (list
      (list "Object" (setq to (cdr (assoc 0 le))))
      (list "Layer" (cdr (assoc 8 le)))
      (list "Color" (if (setq cl (cdr (assoc 62 le))) (itoa cl) "BYLAYER"))
      (list "XData?" (if (assoc -3 le) "YES" "NO"))
    )
  )

  (erroria)
  (setq	txTmp (vla-AddText (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) "0" (VLAX-3D-POINT '(0 0)) 0.1)
	txTmp1 (vla-AddMText (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) (vlax-3d-point '(0 0)) 5000 "0")
	i? T
  )
  (vla-put-color txTmp 1)
  (vla-put-visible txTmp 0)
  (vla-put-color txTmp1 2)
  (vla-put-visible txTmp1 0)
  (while (and (not para) (setq l (grread nil 13 0)))
    (setq tam (* (getvar "PICKBOX")
		 (/ (getvar "VIEWSIZE") (cadr (getvar "SCREENSIZE")))
		 2
		 factor
	      )
    )
    (if e (redraw e 4))
    

    (setq e (if	(setq se (if (listp (setq p (cadr l))) (nentselp p)))
	      (if (and
		    (not (member (vlax-ename->vla-object (car se)) (list txTmp txTmp1)))
		    (member (cdr (assoc 0 (setq le (entget (car se) '("*")))))
			  '("LWPOLYLINE" "POLYLINE" "LINE" "SHAPE" "3DFACE" "INSERT" "TEXT" "MTEXT" "ATTRIB")
		    )
		  )
		(car se)
	      )
	    )
    )
    (if (and i? e) (vla-put-visible txTmp1 1) (vla-put-visible txTmp1 0))
    (prompt (strcat "\rLWPOLYLINE mode: " (if pa "next" "first") " point... (Press \'F10\' for " (if i? "DEACTIVATE" "ACTIVATE")  " real-time reporting)"))

    (cond
      ((= (car l) 5)
        (if (not v1) (setq v1 (vla-put-visible txTmp 1) v1 T))
	(setq pt (list (+ (car p) (* tam 0.8)) (+ (cadr p) (/ tam 2.2))))
        (redraw)
        (if pa (grvecs (list 7 pa p))); THIS LINE IS PART OF THE "pline" EMULATOR CODE. DISABLE IT IF YOU DONT WANT TO USE THE EMULATOR IMPLEMENTED IN funcionPrincipal
       				      ; ESTA LINEA FORMA PARTE DEL EMULADOR "pline". DESACTIVALO SI ELIMINAS EL CÓDIGO EMULADOR IMPLEMENTADO EN funcionPrincipal
	(vlax-put-property txTmp 'InsertionPoint (vlax-make-variant (vlax-3d-point pt)))
        (vlax-put txTmp 'Height tam)
	(vlax-put txTmp 'TextString (textoGR1));<<<-- MODIFICAR ESTA LINEA DE CÓDIGO PARA QUE 'TextString MUESTRE EL TEXTO DESEADO
       
        (if (and i? e)
	  (progn
	    (redraw e 3)
	    (setq pt1 (list (car pt) (- (cadr p) (/ tam 2.))))
	    (vlax-put-property txTmp1 'InsertionPoint (vlax-make-variant (vlax-3d-point pt1)))
	    (vlax-put txTmp1 'Height tam)
	    (vlax-put txTmp1 'TextString (textoGR2 (dameGRT2 le)))
	  )
	)
      )
      
      ((= (car l) 3) (if pa (funcionPrincipal p (car se)) (setq pa p)));
      
      ((= (car l) 25) (setq para T)); BOTON DERECHO = SALIR

      ((member (cadr l) '(67 99)) (if polil (setq para (entmod (subst (cons 70 1) (assoc 70 (entget polil)) (entget polil))))));

      ((= (cadr l) 21) (setq i? (not i?)))
      
;;;      AQUI DEBAJO EL CODIGO PARA GESTIONAR EL RESTO DE OPCIONES
;;;      BELOW YOU CAN ADD MORE CLAUSES TO 'cond' TO EXTEND THE CODE FUNCTIONALITY
      (T ;REST OF CASES: WE DO NOTHING
      )
;|
      ....
      ....
|;
    )
  )
  (vla-delete txTmp)
  (vla-delete txTmp1)
  (redraw)
  (if e (redraw e 4))
  (princ)
)

 

Edited by GLAVCVS
  • Like 1
  • Thanks 1
Posted

Here's my 'Q' lisp for dynamic properties:

image.thumb.png.c400feeb02ab380a0bd6185f28b7ff82.png

Posted (edited)

Hi @ronjonp
How does it work?

Can you attach a video clip? 

Edited by GLAVCVS
Posted
On 6/25/2025 at 12:51 AM, GLAVCVS said:

Hi @ronjonp
How does it work?

Can you attach a video clip? 

Sorry for the delay 'real' work got in the way : )

 

Dang .. I can't get an animated GIF to load at the moment:

image.thumb.png.6422ecb3926dcaba3287a07b63153f5c.png

 

  • Agree 1
Posted
5 hours ago, ronjonp said:

Dang .. I can't get an animated GIF to load at the moment:

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...