Create text with Delta Y of the distance between a given point and where to click.

Create text with Delta Y of the distance between a given point and where to click.

ClaudioRosevel
Explorer Explorer
3,044 Views
22 Replies
Message 1 of 23

Create text with Delta Y of the distance between a given point and where to click.

ClaudioRosevel
Explorer
Explorer
If I click on a reference point and then click on another location, lisp creates a text with the delta y value between the reference point and the new click and asks where to position the text
Thanks!

 

0 Likes
Accepted solutions (1)
3,045 Views
22 Replies
Replies (22)
Message 2 of 23

komondormrex
Mentor
Mentor

check the following

(defun c:y_difference (/ ref_point other_point y_dif)
  (setq ref_point (getpoint "\nPick reference point: ")
	other_point (getpoint ref_point "\nPick other point: ")
  )
  (vla-addtext (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
    	       (setq y_dif (rtos (abs (cadr (mapcar '- ref_point other_point)))))
    	       (vlax-3d-point (getpoint (strcat "\nPick point to place Y difference {" y_dif "} between selected points: ")))
	       (getvar 'textsize)
  )
  (princ)
)
0 Likes
Message 3 of 23

hak_vz
Advisor
Advisor

 

(defun c:y_diff ( / *error* a b c)
	(defun *error* ( msg )
		(if (not (member msg '("Function cancelled" "quit / exit abort")))
			(princ)
		)
	)
	(while 
		(setq 
			a (getpoint "\nPick first point >")
			b (getpoint  a "\nPick second point >")
			c (getpoint b "\nPick y differance location text point >")
		)
		(if 
			(and a b c)
				(entmake
					(list
						(cons 0 "TEXT")
						(cons 100 "AcDbEntity")
						(cons 100 "AcText")
						(cons 1 (rtos (apply '- (mapcar 'cadr (list a b))) 2 2))
						(cons 10 c)
						(cons 40 (getvar 'textsize))
					)
				)
		)
	)
	(princ)
)

 

Or more general solution

 

(defun c:xyz_diff ( / *error* a b c d dir)
	(defun *error* ( msg )
		(if (not (member msg '("Function cancelled" "quit / exit abort")))
			(princ)
		)
	)
	(initget 1 "x y z")
	(setq dir (getkword "\nDifferance direction x y z >"))
	(while 
		(setq 
			a (getpoint "\nPick first point >")
			b (getpoint  a "\nPick second point >")
			c (getpoint b (strcat "\nPick " dir " differance text location point >"))
		)
		(if 
			(and a b c)
				(progn
					(cond 
						((= dir "x") (setq d (apply '- (mapcar 'car (list a b)))))
						((= dir "y") (setq d (apply '- (mapcar 'cadr (list a b)))))
						((= dir "z") (setq d (apply '- (mapcar 'last (list a b)))))	
					)
					(entmake
						(list
							(cons 0 "TEXT")
							(cons 100 "AcDbEntity")
							(cons 100 "AcText")
							(cons 1 (rtos d  2 2))
							(cons 10 c)
							(cons 40 (getvar 'textsize))
						)
					)
				)
		)
	)
	(princ)
)

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 4 of 23

ClaudioRosevel
Explorer
Explorer

(defun c:xyz_diff ( / *error* a b c d dir)
(defun *error* ( msg )
(if (not (member msg '("Function cancelled" "quit / exit abort")))
(princ)
)
)
(initget 1 "x y z")
(setq dir (getkword "\nDifferance direction x y z >"))
(setq
a (getpoint "\nPick first point >"))

(while
(setq
b (getpoint a "\nPick second point >")
c (getpoint b (strcat "\nPick " dir " differance text location point >"))
)
(if
(and a b c)
(progn
(cond
((= dir "x") (setq d (apply '- (mapcar 'car (list a b)))))
((= dir "y") (setq d (apply '- (mapcar 'cadr (list a b)))))
((= dir "z") (setq d (apply '- (mapcar 'last (list a b)))))
)
(entmake
(list
(cons 0 "TEXT")
(cons 100 "AcDbEntity")
(cons 100 "AcText")
(cons 1 (rtos d 2 2))
(cons 10 c)
(cons 40 (getvar 'textsize))
)
)
)
)
)
(princ)
)

0 Likes
Message 5 of 23

Kent1Cooper
Consultant
Consultant

Here's one that makes the Text and then has you position it, so you can see the size of it as you do so, to avoid having it write over something.

 

(defun C:DeltaYText (/ p1 p2)
  (setq
    p1 (getpoint "\nFirst point: ")
    p2 (getpoint "\nSecond point: ")
  )
  (command "_.text" "_mc" (getvar 'viewctr))
  (if (member '(40 . 0.0) (tblsearch "style" (getvar 'textstyle)))
    (command "" 0) (command 0); current height + rotation, or just rotation
  )
  (command
    (rtos (abs (cadr (mapcar '- p1 p2)))); in current mode/precision
    "_.move" "_last" "" "@"
  )
)

 

It uses the current Text Style and height [whether or not the Style has a fixed height], on the current Layer, with the text content in whatever the current mode and precision settings are.  All of that can be forced to particular values if needed. 

Kent Cooper, AIA
0 Likes
Message 6 of 23

ClaudioRosevel
Explorer
Explorer
In this Lisp we click on the first point (reference point), then we click on the second point and click on the text position. Lisp asks you to click again on the reference point that was previously informed. I wanted to fix the first point, increase a value and then click on the second point and the location.
0 Likes
Message 7 of 23

ClaudioRosevel
Explorer
Explorer
In this Lisp we click on the first point (reference point), then we
click on the second point and click on the text position. Lisp asks
you to click again on the reference point that was previously
informed. I wanted to fix the first point, increase a value and then
click on the second point and the location.
0 Likes
Message 8 of 23

Kent1Cooper
Consultant
Consultant

Or, how about one that, after you've picked the first point, shows you the Text you'll get as you move the cursor around, until you pick the second point and lock it in?

 

(defun C:DeltaYText (/ elistbase p1 done txt)
  (setq elistbase
    (list '(0 . "TEXT") '(10  0.0 0.0 0.0) (cons 40 (getvar 'textsize)) '(72 . 1) '(73 . 2))
  ); setq
  (setq p1 (getpoint "\nFirst point: "))
  (prompt "\nSecond point: ")
  (while (and (not done) (setq cur (grread T 12 0)))
    (cond
      ((= (car cur) 5); moved cursor
        (if txt (entdel txt))
        (setq p2 (cadr cur)); cursor location
        (redraw)
        (grdraw p1 p2 40 1)
        (setq txt
          (entmakex
            (append
              elistbase
              (list
                (cons 11 (mapcar '/ (mapcar '+ p1 p2) '(2 2 2))); insertion
                (cons 1 (rtos (abs (cadr (mapcar '- p1 p2))))); content
              ); list
            ); append
          ); entmakex
        ); setq
      ); 5 condition
      ((= (car cur) 3) (setq done T)); picked point - leave drawn Text, end (while) loop
    ); cond
  ); while
  (prin1)
)

 

It puts the Text midway between the two points.  It could follow up with letting you re-position it, as in my other suggestion.  [Unfortunately, while it honors Object Snap for the first point, it doesn't for the second.  I think there may be something around that can make that possible, but don't remember the topic.]

 

Another suggestion:  Define a DIMENSION Style with both extension lines and both dimension lines suppressed, and simply use the DIMVERTICAL command.  You'll be left with the text content as the Y difference between the definition points you give, with all the options about text position and rotation and style and so on that Dimension Styles offer.

 

EDIT:  Adjusted to add rubber-banding between points:

DeltaYText.gif

Kent Cooper, AIA
0 Likes
Message 9 of 23

Kent1Cooper
Consultant
Consultant

@Kent1Cooper wrote:

.... Another suggestion:  Define a DIMENSION Style with both extension lines and both dimension lines suppressed, and simply use the DIMVERTICAL command.  ....


That looks like this:

DeltaYText-DimV.gif

You can reposition the text part after drawing it, if you like, as I did with the first one after drawing the second one.

It has the advantage over Message 8 of working with Object Snap for both points.

And it has the additional advantage that if you Stretch stuff including the definition point locations, the Y-distance text content will update automatically.

You could also do things like include a prefix in the Dimension Style, such as "ΔY=" [the same could also be added to other routines].

Kent Cooper, AIA
0 Likes
Message 10 of 23

komondormrex
Mentor
Mentor

this like?

 

(defun c:y_difference (/ ref_point other_point y_dif)
  (setq ref_point (getpoint "\nPick reference point: "))
  (while (setq other_point (getpoint ref_point "\nPick other point: "))
	  (vla-addtext (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
	    	       (setq y_dif (rtos (abs (cadr (mapcar '- ref_point other_point)))))
;;;	    	       (vlax-3d-point (getpoint (strcat "\nPick point to place Y difference {" y_dif "} between selected points: ")))
	    	       (vlax-3d-point other_point)
		       (getvar 'textsize)
	  )
    	  (command "_move" (entlast) "" other_point pause)	
  )
  (princ)
)

updated

 

0 Likes
Message 11 of 23

Kent1Cooper
Consultant
Consultant

Message 1 did not say anything about multiple second points relative to one common first point, but if that's what you're looking for [such as in @komondormrex's adjusted code in Message 10], that could be added to various routines.

 

But first, I confess to being curious about what you plan to use this for.  What is the meaning of a piece of Text floating somewhere that contains the Y-coordinate difference between two points somewhere, to which the Text makes no reference?  How can one know what that Text represents after the fact?  This is something I would think is better done with a vertical Dimension, including extension lines [unlike my earlier Dimension suggestion], so the text content has an identifiable relationship to what it represents.  So I'm just curious about the application.

Kent Cooper, AIA
0 Likes
Message 12 of 23

hak_vz
Advisor
Advisor

Maybe this, using fixed first point.

(defun c:xyz_diff_from_reffpoint ( / *error* a b c d dir)
	(defun *error* ( msg )
		(if (not (member msg '("Function cancelled" "quit / exit abort")))
			(princ)
		)
	)
	(initget 1 "x y z")
	(setq dir (getkword "\nDifferance direction x y z >"))
	(setq a (getpoint "\nPick referance point >"))
	(while 
		(setq 
			b (getpoint  a "\nPick second point >")
			c (getpoint b (strcat "\nPick " dir " differance location point >"))
		)
		(if 
			(and a b c)
				(progn
					(cond 
						((= dir "x") (setq d (apply '- (mapcar 'car (list b a)))))
						((= dir "y") (setq d (apply '- (mapcar 'cadr (list b a)))))
						((= dir "z") (setq d (apply '- (mapcar 'last (list b a)))))	
					)
					(entmake
						(list
							(cons 0 "TEXT")
							(cons 100 "AcDbEntity")
							(cons 100 "AcText")
							(cons 1 (rtos d  2 2))
							(cons 10 c)
							(cons 40 (getvar 'textsize))
						)
					)
				)
		)
	)
	(princ)
)

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 13 of 23

ClaudioRosevel
Explorer
Explorer

This is correct, but is it possible to increase a value to the values ​​found? Immediately after entering the reference point, enter an increment value, for example 100, then the final value would be the value y + 100.

0 Likes
Message 14 of 23

ClaudioRosevel
Explorer
Explorer

That is it!

0 Likes
Message 15 of 23

ClaudioRosevel
Explorer
Explorer

That is it!XYZ.jpg

0 Likes
Message 16 of 23

Kent1Cooper
Consultant
Consultant

ORDINATE Dimensions may be able to do what you want without any routine.

Kent Cooper, AIA
0 Likes
Message 17 of 23

ClaudioRosevel
Explorer
Explorer

ORDINATE Dimensions uses the ucs as a reference for the final value. I need the delta Y value to be added to the chosen value.

0 Likes
Message 18 of 23

Kent1Cooper
Consultant
Consultant

@ClaudioRosevel wrote:

ORDINATE Dimensions uses the ucs as a reference for the final value. I need the delta Y value to be added to the chosen value.


You can put the reference location anywhere you want.  Draw some Ordinate Dimensions, and with them all selected, go find the grip at 0,0 and drag it to your preferred reference location, and they'll all adjust themselves.  You can incorporate that "chosen value" to be added, by just grip-moving the common reference to that far below the "nominal" reference Y position.

 

Or temporarily change the UCS Origin while you make them, then set it back.  Their values won't change [unless and until you drag their reference grips somewhere else].

 

You can turn off their extension lines if you don't want to see those, with DIMOVERRIDE, setting both DIMSE1 and DIMSE2 Off [they don't show up in the Properties palette for Ordinate Dimensions, for some reason].

Kent Cooper, AIA
0 Likes
Message 19 of 23

Sea-Haven
Mentor
Mentor

Pick a point for datum, enter 210 do offset for text ie point to left, how many more and at what increment 2 & 5.0 all done from a lisp point of view. A good lisp learning task have a go. Advanced front end.

SeaHaven_0-1704938425390.png

 

0 Likes
Message 20 of 23

calderg1000
Mentor
Mentor
Accepted solution

Regards @ClaudioRosevel 

Try this code...

;;;___
(defun c:lev (/ Dt dp hp ht np dh tx)
  (setq	Dt (Getreal "\nEnter Datum Value: ")
	dp (getpoint "\nPick Point Datum : ")
	ht (getreal "\nEnter Text Height: ")
  )
  (while
    (setq
      hp (getpoint dp "\nPick Point Cota Value: ")
    )
     (setq
       np (getpoint hp "\Pick Point to text insertion: ")
       dh (- (cadr hp) (cadr dp))
       tx (rtos (+ Dt dh) 2 2)
     )
     (entmakex (list '(0 . "text")
		     (cons 1 tx)
		     (cons 10 np)
		     (cons 11 np)
		     (cons 40 ht)
		     (cons 72 2)
	       )
     )
  )
  (princ)
)

 


Carlos Calderon G
EESignature
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

0 Likes