barristann Posted January 29, 2023 Posted January 29, 2023 (edited) 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 January 29, 2023 by barristann Quote
Emmanuel Delay Posted January 30, 2023 Posted January 30, 2023 (edited) 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 January 30, 2023 by Emmanuel Delay 3 Quote
barristann Posted February 1, 2023 Author Posted February 1, 2023 (edited) 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 February 1, 2023 by barristann 1 Quote
devitg Posted February 1, 2023 Posted February 1, 2023 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 Quote
Recommended Posts
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.