Jump to content

Help-move text or mtext to midpoint of 2 points, then move 1 unit above


barristann

Recommended Posts

Hi all. Is it possible to modify this ronjonp & Alan H code to also move the Text or Mtext 1 unit above (the imaginary line created by these 2 points)? Thank you.

 

https://www.cadtutor.net/forum/topic/65000-lisp-routine-to-move-text-or-mtext-to-midpoint-of-2-points/

 

;; Ronjonp - 03.22.2018 mid pt of two pts
(defun _mid (p1 p2) (polar p1 (angle p1 p2) (/ (distance p1 p2) 2.)))
; modified by Alan H basicly supports any object that can have a bounding box 03.23.2018

(defun c:foo (/ e p p1 p2)
(setq e (vlax-ename->vla-object (car (entsel "pick object"))))
(vla-getboundingbox e 'll 'ur)
(setq p (mapcar 'vlax-safearray->list (list ll ur)))
(setq p1 (getpoint "pick 1st point"))
(setq p2 (getpoint "pick 2nd point"))
(vlax-invoke e 'move (_mid (car p) (cadr p)) (_mid p1 p2))
(princ)
)
(vl-load-com)
(c:foo)

Edited by barristann
Link to comment
Share on other sites

  • barristann changed the title to Help-move text or mtext to midpoint of 2 points, then move 1 unit above

I changed it a bit.

I use (vla-move instead of (vlax-invoke e 'move

I hope you don't mind.

 

I'm not sure which you want,

foo puts the point 1 unit up vertically

foo2 puts the point 1 unit offset to the imaginary line p1-p2

 

I think you want foo2.  Anyway, here's both.

change the bottom line if needed to

(c:foo2)

 

;; Ronjonp - 03.22.2018 mid pt of two pts
(defun _mid (p1 p2) (polar p1 (angle p1 p2) (/ (distance p1 p2) 2.)))
; modified by Alan H basicly supports any object that can have a bounding box 03.23.2018

;; raise a point by a certain amount, vertically
(defun raise (p1 by / )
	(list 
		(nth 0 p1)
		(+ (nth 1 p1) by)
	)
)
;; raise a point by a certain amount, vertically
(defun offset_by (p1 ang by / )
	(polar p1 (+ ang (/ pi 2.0)) by)  ;; angle of p1-p2 + 90°
)

(defun c:foo (/ e e_ p p1 p2 p3)
	(setq e (vlax-ename->vla-object (car (entsel "pick object"))))
	(vla-getboundingbox e 'll 'ur)
	(setq p (mapcar 'vlax-safearray->list (list ll ur)))
	(setq p1 (getpoint "pick 1st point"))
	(setq p2 (getpoint "pick 2nd point"))
	(setq p3(_mid p1 p2) )
	;; raise it by 1 unit
	(setq p3 (raise p3 1.0))
	(vla-move e (vlax-3d-point (_mid (car p) (cadr p))) (vlax-3d-point p3))
	(princ)
)

(defun c:foo2 (/ e e_ p p1 p2 p3)
	(setq e (vlax-ename->vla-object (car (entsel "pick object"))))
	(vla-getboundingbox e 'll 'ur)
	(setq p (mapcar 'vlax-safearray->list (list ll ur)))
	(setq p1 (getpoint "pick 1st point"))
	(setq p2 (getpoint "pick 2nd point"))
	(setq p3(_mid p1 p2) )
	;; offset it by 1 unit
	(setq p3 (offset_by p3 (angle p1 p2) 1.0))
	(vla-move e (vlax-3d-point (_mid (car p) (cadr p))) (vlax-3d-point p3))
	(princ)
)

(vl-load-com)
(c:foo)

 

Edited by Emmanuel Delay
  • Like 3
Link to comment
Share on other sites

I was so busy at work so sorry for the late reply. I thought it could not be done. But wow, you've nailed it, Emmanuel! It's exactly what I was hoping for. Thank you Emmanuel! 

Edited by barristann
  • Like 1
Link to comment
Share on other sites

On 1/30/2023 at 7:17 AM, Emmanuel Delay said:

I changed it a bit.

I use (vla-move instead of (vlax-invoke e 'move

I hope you don't mind.

 

I'm not sure which you want,

foo puts the point 1 unit up vertically

foo2 puts the point 1 unit offset to the imaginary line p1-p2

 

I think you want foo2.  Anyway, here's both.

change the bottom line if needed to

(c:foo2)

 

;; Ronjonp - 03.22.2018 mid pt of two pts
(defun _mid (p1 p2) (polar p1 (angle p1 p2) (/ (distance p1 p2) 2.)))
; modified by Alan H basicly supports any object that can have a bounding box 03.23.2018

;; raise a point by a certain amount, vertically
(defun raise (p1 by / )
	(list 
		(nth 0 p1)
		(+ (nth 1 p1) by)
	)
)
;; raise a point by a certain amount, vertically
(defun offset_by (p1 ang by / )
	(polar p1 (+ ang (/ pi 2.0)) by)  ;; angle of p1-p2 + 90°
)

(defun c:foo (/ e e_ p p1 p2 p3)
	(setq e (vlax-ename->vla-object (car (entsel "pick object"))))
	(vla-getboundingbox e 'll 'ur)
	(setq p (mapcar 'vlax-safearray->list (list ll ur)))
	(setq p1 (getpoint "pick 1st point"))
	(setq p2 (getpoint "pick 2nd point"))
	(setq p3(_mid p1 p2) )
	;; raise it by 1 unit
	(setq p3 (raise p3 1.0))
	(vla-move e (vlax-3d-point (_mid (car p) (cadr p))) (vlax-3d-point p3))
	(princ)
)

(defun c:foo2 (/ e e_ p p1 p2 p3)
	(setq e (vlax-ename->vla-object (car (entsel "pick object"))))
	(vla-getboundingbox e 'll 'ur)
	(setq p (mapcar 'vlax-safearray->list (list ll ur)))
	(setq p1 (getpoint "pick 1st point"))
	(setq p2 (getpoint "pick 2nd point"))
	(setq p3(_mid p1 p2) )
	;; offset it by 1 unit
	(setq p3 (offset_by p3 (angle p1 p2) 1.0))
	(vla-move e (vlax-3d-point (_mid (car p) (cadr p))) (vlax-3d-point p3))
	(princ)
)

(vl-load-com)
(c:foo)

 

Hi Emmanuel, why  do you prefer?  

(vla-move instead of (vlax-invoke e 'move

Thanks in advance 

Link to comment
Share on other sites

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