Jump to content

Enable osnap in LM:GrText program


Recommended Posts

Posted (edited)

hello
Is it possible to have osnap enabled when using this app so we can click at the beginning of the lines.

 

https://www.lee-mac.com/grtext.html

 

 

 

Edited by SLW210
Removed code as link was provided.
Posted

You would need to implement your own Object Snap functionality, or perhaps leverage my existing GrSnap function.

  • Like 1
  • 2 months later...
Posted

I worked on this program a little
When drawing a polyline, it shows the total length of the polyline and the distance to the mouse next to the mouse
Is it possible to see how it can be made more functional and better?
I want the snap point to be on when selecting a point to find the beginning of the lines
I also want to see the mouse with the ruler to the last part of the drawn part

 

 

 (princ "\nSpecify point: ")
 (setq ename nil sumdist 0)
 (if (setq pt (getpoint "\nSpecify Specify point: "))
   (progn
    (while (and pt 
        (= (while (= 5 (car (setq pnt (grread nil 13 0))))
        (redraw)
        (LM:DisplayGrText (cadr pnt)
	  (LM:GrText (strcat (rtos (+ sumdist (distance pt (cadr pnt))) 2 2) ))
	  4	;Color
	  15	;x
	  -31)	;y
      ) nil))

        (command "_.pline" pt (cadr pnt) "")
        (if ename (command "_.pedit" ename "_j" (entlast) "" "" ))
        (setq ename (entlast))
        (setq sumdist (+ sumdist (distance pt (cadr pnt))))
        (setq pt (cadr pnt))

    )
   )
 )

 

Posted

grrear doesn't do snaps so easily - if you look at Lee Macs link above to get the snaps

 

I might have something - will have to look

  • Like 1
Posted

I had a bit of time to look at this, I think this is what I added to Lees code above:

 

 

(defun c:grsnap ( / )

... Lee Macs code here until...


(vl-load-com) (princ)

    (setq osf (LM:grsnap:snapfunction)
          osm (getvar 'osmode)
    )
    (princ "\nPick point: ")
    (while (= 5 (car (setq grr (grread t 15 0))))
        (redraw)
        (osf (cadr grr) osm)
    )
;    (if (listp (cadr grr))
;        (entmake (list '(0 . "POINT") (cons 10 (trans (osf (cadr grr) osm) 1 0))))
;    )
    (redraw) (princ)
    (trans (osf (cadr grr) osm) 1 0)
)

 

 

Posted

It's fun to play with GRRead. But it's also laborious.
I've been experimenting with your code this afternoon and have added a few things.
But this code only supports references to endpoint objects. I didn't have enough time for more.

This is the result.

 

(defun c:santaVassolian (/ ename sumdist pt pnt ptGR polil tam dibuSnap)

;;;  HERE 'LM:DisplayGrText' code ....
;;;  ....................................
  
  (defun dibuSnap (pt color / xMin yMin xMax yMax)
;;;    ONLY _end POINT
    (grvecs
      (list
	color
	(list (setq Xmin (- (car pt) tam))
	      (setq Ymin (- (cadr pt) tam))
	)
	(list Xmin (setq Ymax (+ (cadr pt) tam)))
	(list Xmin Ymax)
	(list (setq Xmax (+ (car pt) tam)) Ymax)
	(list Xmax Ymax)
	(list Xmax Ymin)
	(list Xmax Ymin)
	(list Xmin Ymin)
      )
    )
    T
  )
 
  (princ "\nSpecify point: ")
  (setq	ename	nil
	sumdist	0
  )
  (if (setq pt (getpoint "\nSpecify Specify point: "))
    (progn
      (princ "\nPick next point (right button for exit)...")
      (while
	(and
	  pt
	  (=
	    (while (= 5 (car (setq pnt (grread nil 13 0))))
	      (redraw)
	      (LM:DisplayGrText
		(cadr pnt)
		(LM:GrText		
		  (strcat (rtos (+ sumdist (distance pt (cadr pnt))) 2 2))
		)
		4			;Color
		15			;x
		-31
	      )				;y
	      (setq tam	(* (* (getvar "PICKBOX")
			      (/ (getvar "VIEWSIZE")
				 (cadr (getvar "SCREENSIZE"))
			      )
			   )
			   2
			)
	      )
	      (if (listp (cadr pnt))
		(grvecs	(list
			  7
			  pt
			  (if (and
				(setq ptGR (osnap (cadr pnt) "_end"))
				(and
				  (<=
				    (abs (- (car ptGR) (car (cadr pnt))))
				    tam
				  )
				  (<=
				    (abs (- (cadr ptGR) (cadr (cadr pnt))))
				    tam
				  )
				)
				(dibuSnap ptGR 1)
			      )
			    ptGR
			    (progn
			      (setq ptGR nil)
			      (cadr pnt)
			    )
			  )
			)
		)
	      )
	    )
	    nil
	  )
	)
	(redraw)
	(if (= (car pnt) 3)
	  (progn
	    (if	polil
	      (if ptGR
		(entmod	(append	(entget polil)
				(list (cons 10 ptGR))
			)
		)
		(entmod	(append	(entget polil)
				(list (cons 10 (cadr pnt)))
			)
		)
	      )
	      (if
		(entmake (list '(0 . "LWPOLYLINE")
			       '(100 . "AcDbEntity")
			       '(100 . "AcDbPolyline")
			       (cons 8 "0")
			       (cons 90 2)
			       '(70 . 128)
			       '(62 . 256)
			       (cons 10 pt)
			       (if (setq ptGR (osnap (cadr pnt) "_end"))
				 (cons 10 ptGR)
				 (cons 10 (cadr pnt))
			       )
			 )
		)
		 (setq polil (entlast))
	      )
	    )

;;;	(command "_.pline" pt (cadr pnt) "")
;;;	(if ename
;;;	  (command "_.pedit" ename "_j" (entlast) "" "")
;;;	)
;;;	 (setq ename (entlast))
	    (setq sumdist (+ sumdist (distance pt (cadr pnt))))
	    (setq pt (if ptGR
		       ptGR
		       (cadr pnt)
		     )
	    )
	  )
	  (setq pt nil); OBLIGA A SALIR
	)
      )
    )
  )
  (PRINC)
)

 

  • Like 1
Posted (edited)

I hope you find it useful. Or anyone who needs a starting point.

 

Running, it looks more or less like this

 

 

 

 

Edited by GLAVCVS
  • Like 1
Posted
7 hours ago, GLAVCVS said:

It's fun to play with GRRead. But it's also laborious.
I've been experimenting with your code this afternoon and have added a few things.
But this code only supports references to endpoint objects. I didn't have enough time for more.

This is the result.

 

(defun c:santaVassolian (/ ename sumdist pt pnt ptGR polil tam dibuSnap)

;;;  HERE 'LM:DisplayGrText' code ....
;;;  ....................................
  
  (defun dibuSnap (pt color / xMin yMin xMax yMax)
;;;    ONLY _end POINT
    (grvecs
      (list
	color
	(list (setq Xmin (- (car pt) tam))
	      (setq Ymin (- (cadr pt) tam))
	)
	(list Xmin (setq Ymax (+ (cadr pt) tam)))
	(list Xmin Ymax)
	(list (setq Xmax (+ (car pt) tam)) Ymax)
	(list Xmax Ymax)
	(list Xmax Ymin)
	(list Xmax Ymin)
	(list Xmin Ymin)
      )
    )
    T
  )
 
  (princ "\nSpecify point: ")
  (setq	ename	nil
	sumdist	0
  )
  (if (setq pt (getpoint "\nSpecify Specify point: "))
    (progn
      (princ "\nPick next point (right button for exit)...")
      (while
	(and
	  pt
	  (=
	    (while (= 5 (car (setq pnt (grread nil 13 0))))
	      (redraw)
	      (LM:DisplayGrText
		(cadr pnt)
		(LM:GrText		
		  (strcat (rtos (+ sumdist (distance pt (cadr pnt))) 2 2))
		)
		4			;Color
		15			;x
		-31
	      )				;y
	      (setq tam	(* (* (getvar "PICKBOX")
			      (/ (getvar "VIEWSIZE")
				 (cadr (getvar "SCREENSIZE"))
			      )
			   )
			   2
			)
	      )
	      (if (listp (cadr pnt))
		(grvecs	(list
			  7
			  pt
			  (if (and
				(setq ptGR (osnap (cadr pnt) "_end"))
				(and
				  (<=
				    (abs (- (car ptGR) (car (cadr pnt))))
				    tam
				  )
				  (<=
				    (abs (- (cadr ptGR) (cadr (cadr pnt))))
				    tam
				  )
				)
				(dibuSnap ptGR 1)
			      )
			    ptGR
			    (progn
			      (setq ptGR nil)
			      (cadr pnt)
			    )
			  )
			)
		)
	      )
	    )
	    nil
	  )
	)
	(redraw)
	(if (= (car pnt) 3)
	  (progn
	    (if	polil
	      (if ptGR
		(entmod	(append	(entget polil)
				(list (cons 10 ptGR))
			)
		)
		(entmod	(append	(entget polil)
				(list (cons 10 (cadr pnt)))
			)
		)
	      )
	      (if
		(entmake (list '(0 . "LWPOLYLINE")
			       '(100 . "AcDbEntity")
			       '(100 . "AcDbPolyline")
			       (cons 8 "0")
			       (cons 90 2)
			       '(70 . 128)
			       '(62 . 256)
			       (cons 10 pt)
			       (if (setq ptGR (osnap (cadr pnt) "_end"))
				 (cons 10 ptGR)
				 (cons 10 (cadr pnt))
			       )
			 )
		)
		 (setq polil (entlast))
	      )
	    )

;;;	(command "_.pline" pt (cadr pnt) "")
;;;	(if ename
;;;	  (command "_.pedit" ename "_j" (entlast) "" "")
;;;	)
;;;	 (setq ename (entlast))
	    (setq sumdist (+ sumdist (distance pt (cadr pnt))))
	    (setq pt (if ptGR
		       ptGR
		       (cadr pnt)
		     )
	    )
	  )
	  (setq pt nil); OBLIGA A SALIR
	)
      )
    )
  )
  (PRINC)
)

 

 

Wow, 👏👏👏👏

that's exactly what I wanted.

Thank you so much for your effort.

 

 

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...