寫個lisp,把下面的文字粘進記事本,存成AVE.lsp(檔名可自定,命令名稱就是下面 c: 後的內容,也可以自己改),在CAD中APPLOAD這個lisp程式,AVE命令,選擇數字(可以框選,選到別的型別的物件也沒問題),然後點取放置平均數的位置。要注意,當前文字樣式的高度必須為0。(defun c:AVE ()(setq ss (ssget))(setq n 0 total (sslength ss))(repeat total(setq name (ssname ss n))(setq ent (entget name))(if (= (cdr (assoc 1 ent)) nil)(progn (ssdel name ss) (setq total (1- total)))(setq n (1+ n))))(setq i 0 sum 0 u 0)(repeat (sslength ss)(setq en (ssname ss i))(setq en_data (entget en))(setq en_type (cdr (assoc 0 en_data)))(setq entxt (cdr (assoc 1 en_data)))(setq n 1 nn 1)(repeat (strlen entxt)(if (and (>= 57 (ascii (substr entxt nn 1)))(<= 46 (ascii (substr entxt nn 1))))(setq n (+ 1 n)))(setq nn (+ 1 nn)))(if (equal n nn)(progn (setq sum (+ sum (atof entxt))) (setq u (+ 1 u))))(setq i (+ 1 i)))(setq ave (/ sum u))(setq pt (getpoint "/n點取平均數放置位置:"))(command "text" pt "350" "" ave ""))
寫個lisp,把下面的文字粘進記事本,存成AVE.lsp(檔名可自定,命令名稱就是下面 c: 後的內容,也可以自己改),在CAD中APPLOAD這個lisp程式,AVE命令,選擇數字(可以框選,選到別的型別的物件也沒問題),然後點取放置平均數的位置。要注意,當前文字樣式的高度必須為0。(defun c:AVE ()(setq ss (ssget))(setq n 0 total (sslength ss))(repeat total(setq name (ssname ss n))(setq ent (entget name))(if (= (cdr (assoc 1 ent)) nil)(progn (ssdel name ss) (setq total (1- total)))(setq n (1+ n))))(setq i 0 sum 0 u 0)(repeat (sslength ss)(setq en (ssname ss i))(setq en_data (entget en))(setq en_type (cdr (assoc 0 en_data)))(setq entxt (cdr (assoc 1 en_data)))(setq n 1 nn 1)(repeat (strlen entxt)(if (and (>= 57 (ascii (substr entxt nn 1)))(<= 46 (ascii (substr entxt nn 1))))(setq n (+ 1 n)))(setq nn (+ 1 nn)))(if (equal n nn)(progn (setq sum (+ sum (atof entxt))) (setq u (+ 1 u))))(setq i (+ 1 i)))(setq ave (/ sum u))(setq pt (getpoint "/n點取平均數放置位置:"))(command "text" pt "350" "" ave ""))