Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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 ?
;;; 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)
Solved! Go to Solution.