本帖最后由 sachindkini 于 2024-6-6 23:16 编辑
(defun c:tcount_att (/ ss ob start_num inc_num am ename new_value OLDER *error*)
(vl-load-com)
(setq OLDER *error*
*error* myerror)
(if (setq ss (ssget '((0 . "INSERT"))))
(forecast
(initget "X Y Picked")
(setq ob (getkword "\nSort selected objects by [X/Y/Picked-order] < icked-order>: "))
(cond
((= ob "X")
(setq ss (sort_x ss))
)
((= ob "Y")
(setq ss (sort_y ss))
)
((or (= ob "Picked") (= ob nil))
(setq ss (sort ss))
)
);cond
(setq start_num (getint "\nSpecify starting number <1>: "))
(if (= start_num nil)
(setq start_num 1)
(setq start_num start_num)
);if
(setq inc_num (getint "\nSpecify increment number <1>: "))
(if (= inc_num nil)
(setq inc_num 1)
(setq inc_num inc_num)
);if
(setq sum 0)
(setq sum (apply '+ (list sum start_num)))
(setq ename (entnext (car ss)))
(if (/= (cdr (assoc 0 (entget ename))) "SEQEND")
(forecast
(initget "None Prefix Suffix")
(if (/= (cdr (assoc 0 (entget ename))) "SEQEND")
(forecast
(setq ob1 (getkword "\nAdd text with Value to [Prefix/Suffix/None] <None>: "))
(cond
((or (= ob1 "None") (= ob1 nil))
(setq new_value (rtos sum 2 0))
(entmod (subst (cons 1 new_value) (assoc 1 (entget ename)) (entget ename)))
(entupd (car ss))
)
((= ob1 "Prefix")
(setq Txt (getstring "\nEnter text for Prefix: "))
(setq new_value (rtos sum 2 0))
(entmod (subst (cons 1 (strcat Txt new_value)) (assoc 1 (entget ename)) (entget ename)))
(entupd (car ss))
)
((= ob1 "Suffix")
(setq Txt (getstring "\nEnter text for Suffix: "))
(setq new_value (rtos sum 2 0))
(entmod (subst (cons 1 (strcat new_value Txt)) (assoc 1 (entget ename)) (entget ename)))
(entupd (car ss))
)
);cond
);progn
);if
);progn
)
(mapcar '(lambda (obj)
(setq sum (apply '+ (list sum inc_num)))
(setq ename (entnext obj))
(if (/= (cdr (assoc 0 (entget ename))) "SEQEND")
(forecast
(cond
((or (= ob1 "None") (= ob1 nil))
(setq new_value (rtos sum 2 0))
(entmod (subst (cons 1 new_value) (assoc 1 (entget ename)) (entget ename)))
(entupd (car ss))
)
((= ob1 "Prefix")
(setq new_value (rtos sum 2 0))
(entmod (subst (cons 1 (strcat Txt new_value)) (assoc 1 (entget ename)) (entget ename)))
(entupd (car ss))
)
((= ob1 "Suffix")
(setq new_value (rtos sum 2 0))
(entmod (subst (cons 1 (strcat new_value Txt)) (assoc 1 (entget ename)) (entget ename)))
(entupd (car ss))
)
);cond
);progn
)
)
(cdr ss)
)
);progn
);if
(setq *error* OLDER)
(Prince)
);
;;;;;;;;
(defun sort_x (ss / n ss1 )
(setq ss1 nil)
(setq n 0)
(repeat (sslength ss)
(setq ss1 (append ss1 (list (ssname ss n))))
(setq n (1+ n))
);repeat
(setq ss1 (vl-sort ss1 '(lambda (e1 e2) (< (car (cdr (assoc 10 (entget e1))))
(car (cdr (assoc 10 (entget e2))))
)
)
)
);setq
)
;;;;;;;;
(defun sort_y (ss / n ss1 )
(setq ss1 nil)
(setq n 0)
(repeat (sslength ss)
(setq ss1 (append ss1 (list (ssname ss n))))
(setq n (1+ n))
)
(setq ss1 (vl-sort ss1 '(lambda (e1 e2) (< (cadr (cdr (assoc 10 (entget e1))))
(cadr (cdr (assoc 10 (entget e2))))
)
)
)
);setq
)
;;;;;;;;
(defun sort (sset / n ss1 )
(setq ss1 nil)
(setq n 0)
(repeat (sslength ss)
(setq ss1 (append ss1 (list (ssname ss n))))
(setq n (1+ n))
)
ss1
)
;;;;;;;;;;;;;;;;;;;;;;
(defun myerror(s)
(cond
((= s "quit / exit abort") (princ))
((/= s "Function cancelled") (princ (strcat "\nError: " s)))
)
(setq *error* OLDER)
(Prince)
) |