How to change annotation points?

How to change annotation points?

tencome
Contributor Contributor
217 Views
2 Replies
Message 1 of 3

How to change annotation points?

tencome
Contributor
Contributor

Hello,  everyone.

 

I use lisp to do point to point auto annotation, but 2nd points position is not I want( figure 2) .

 

I want linear annotation like  figure 3,  how to modify this lisp ?

 

 

image.png

 

;;;  DimXY.lsp  ——  Use linear annotation to indicate the ΔX and ΔY values from point 1 to the remaining points


(defun c:DimXY ( / N i ptLst basePt pt dX dY offX offY gap)
  (vl-load-com)

  ;; Line spacing, default is 1 graphic unit, can be adjusted as needed
  (setq gap 1.0)

  ;; inpu N
  (initget 7)
  (setq N (getint "\n input number of measurement points N(≥2):"))
  (if (< N 2)
    (progn (prompt "\n ≥2!") (exit))
  )

  ;; manual pick up measurement points
  (prompt "\n Please select N points in sequence:")
  (setq i 0 ptLst '())
  (while (< i N)
    (setq pt (getpoint (strcat "\n select Number " (itoa (1+ i)) " point :")))
    (if pt
      (setq ptLst (append ptLst (list pt))
            i     (1+ i))
      (prompt "\n No valid point has been selected. Please select again!")
    )
  )

  ;; Base point
  (setq basePt (nth 0 ptLst))

  ;; start
  (command "_.UNDO" "_BEGIN")
  (command "_.UNDO" "_GROUP")

  ;; from 2nd point
  (setq i 1)
  (foreach pt (cdr ptLst)
    (setq dX (- (car pt)  (car basePt)))   ; ΔX
    (setq dY (- (cadr pt) (cadr basePt)))  ; ΔY

    ;; Calculate the offset between two annotation lines to prevent overlap
    (setq offX (* (+ i 1) gap))   ; Horizontal annotation is staggered downward
    (setq offY (* (+ i 1) gap))   ; Shift the vertical annotation to the left

    ;; Horizontal annotation ΔX
    (command "_.DIMLINEAR"
             "_H"                            ; Horizontal
             (list (car basePt) (cadr basePt))  ; start point
             (list (car pt)     (cadr basePt))  ; End point(Y same base)
             (list (/ (+ (car basePt) (car pt)) 2.0)
                   (- (cadr basePt) offX))      ; Position of annotation line
    )
    ;; Change the default annotation text to“X=xxx”
    (command "_T" (strcat "X=" (rtos dX 2 3)) "")

    ;; Vertical annotation ΔY
    (command "_.DIMLINEAR"
             "_V"                            ; Vertical
             (list (car basePt) (cadr basePt))  ; start point
             (list (car basePt) (cadr pt))      ; End point(X same base)
             (list (- (car basePt) offY)
                   (/ (+ (cadr basePt) (cadr pt)) 2.0)) ; Position of annotation line
    )
    (command "_T" (strcat "Y=" (rtos dY 2 3)) "")

    (setq i (1+ i))
  )

  (command "_.UNDO" "_END")
  (princ "\nLinear annotation completed!")
  (princ)
)

(prompt "\nDimXY.lsp loaded,input DimXY annotation 。")
(princ)

 

0 Likes
Accepted solutions (1)
218 Views
2 Replies
Replies (2)
Message 2 of 3

Sea-Haven
Mentor
Mentor

I think maybe rearrange your approach.

 

Pick 1st point

Then pick to left

Then Pick up 

Enter offset for dims.

Inside a while pick points. No need for how many in code.

 

May have time later to do something.

0 Likes
Message 3 of 3

Sea-Haven
Mentor
Mentor
Accepted solution

This matches your request, I think it can display in a better way.

 

; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-change-annotation-points/m-p/13778176#M166110
; By Alanh Aug 2025

(defun c:dimhorver ( / pt1 pt2 pt3 pt4 dist inc)

(setq pt1 (getpoint "\Pick 1st point "))

(setq inc (getdist pt1 "\nEnter dim offset distance "))
(setq dist 0.0)

(while (setq pt2 (getpoint "\nPick next point Enter to exit"))
  (setq pt3 (polar pt1 pi (setq dist (+ dist inc))))
  (setq pt4 (polar pt1 (/ pi 2) dist))
  (command "dimvertical" pt1 pt2 pt3 "" "")
  (command "dimhorizontal" pt1 pt2 pt4 "" "")
)
(princ)
)