Jump to content

Displaying delta X & delta Y of two points (an alteration to Lee's code is needed)


Recommended Posts

Posted

Hi again,

 

I found following code of Lee here and it is pretty close to what I need but I need to change it slightly to print X and Y coordinate differences (dX,dY) pair instead of distances. Can anyone help?

 

(defun c:dist2 (/ doc spc pt1 pt2 tObj gr)
(vl-load-com)
(or *Mac$Rot* (setq *Mac$Rot* 0.0))
(setq doc (vla-get-ActiveDocument (vlax-get-Acad-Object)) spc (if (zerop (vla-get-activespace doc)) (if (= (vla-get-mspace doc) :vlax-true)(vla-get-modelspace doc)(vla-get-paperspace doc)) (vla-get-modelspace doc))) 
(while
	(and (setq pt1 (getpoint "\nSelect First Point: "))
		 (setq pt2 (getpoint "\nSelect Second Point: " pt1)))
	(vla-put-Alignment (setq tObj (vla-addText spc (rtos (distance pt1 pt2)) (vlax-3D-point '(0 0 0))(getvar "TEXTSIZE"))) acAlignmentMiddleCenter)
	(while
		(or
			(and (setq gr (grread t 7 0))
				 (eq 5 (car gr))
			)
			(and (eq 2 (car gr))
				 (eq 32 (cadr gr)))
		)
		(cond ((and (eq 5 (car gr)) 
					(listp (cadr gr))
				)
			 (vla-move tObj (vla-get-TextAlignmentPoint tObj) (vlax-3D-point (cadr gr))))
			(	(and 	(eq 2 (car gr)) 
						(eq 32 (cadr gr))
				)
			 (vla-put-Rotation tObj (setq *Mac$Rot* (+ *Mac$Rot* (/ pi 2.))))
			)
		)
	)
)
 (princ))

Posted

You have over 100 posts you should by now be able to do this mvery simple request yourself at least have a go we will help if you get it wrong.

 

You need to change this (setq tObj (vla-addText spc (rtos (distance pt1 pt2)) instead of distance get the difference between the two X & Y values

 

(nth pt1 0)
(nth pt1 1)
(nth pt2 0)
(nth pt2 1)
or (car pt1) (cadr pt1)

Screen Shot 06-03-16 at 12.15 PM.PNG

Posted

Thanks BIGAL for the motivation. The problem was that I didn't know where to look at. As long as you pointed out to that line of code, I think I cracked it.

 

See how did I go (perhaps it looks to medieval to you !)

 

(defun c:dist2 (/ doc spc pt1 pt2 tObj gr)
 (vl-load-com)
 (or *Mac$Rot* (setq *Mac$Rot* 0.0))
 (setq	doc (vla-get-ActiveDocument (vlax-get-Acad-Object))
spc (if	(zerop (vla-get-activespace doc))
      (if (= (vla-get-mspace doc) :vlax-true)
	(vla-get-modelspace doc)
	(vla-get-paperspace doc)
      )
      (vla-get-modelspace doc)
    )
 )
 (while
   (and (setq pt1 (getpoint "\nSelect First Point: "))
 (setq pt2 (getpoint "\nSelect Second Point: " pt1))
   )
(setq	pt1x (car pt1)
		pt1y (cadr pt1)
		pt2x (car pt2)
		pt2y (cadr pt2)
		dx	(- pt1x pt2x)
		dy	(- pt1y pt2y)
)

    (vla-put-Alignment
      (setq tObj (vla-addText spc (strcat "(" (rtos dx) " , " (rtos dy) ")") (vlax-3D-point '(0 0 0)) (getvar "TEXTSIZE") ) )
      acAlignmentMiddleCenter
    )
    (while
      (or
 (and (setq gr (grread t 7 0))
      (eq 5 (car gr))
 )
 (and (eq 2 (car gr))
      (eq 32 (cadr gr))
 )
      )
(cond ((and (eq 5 (car gr))
	    (listp (cadr gr))
       )
       (vla-move tObj
		 (vla-get-TextAlignmentPoint tObj)
		 (vlax-3D-point (cadr gr))
       )
      )
      ((and (eq 2 (car gr))
	    (eq 32 (cadr gr))
       )
       (vla-put-Rotation
	 tObj
	 (setq *Mac$Rot* (+ *Mac$Rot* (/ pi 2.)))
       )
      )
)
    )
 )
 (princ)
 

)

Posted

Its a common problem to have to get X Y values, glad you worked it out.

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