https://totthi.bbs.fc2.com/?act=reply&tid=16680411#24232957
このトピックのLispをちょっと変更しました。
(defun c:flen
(/ ename vlobj obid pt mt fstr dsc c_unt pref suff pr_0 pr)
(setq pref "") ;接頭辞を指定
(setq suff "m") ;接尾辞を指定
(setq c_unt "1e-003") ;変換単位を指定 ただし、浮動小数点表示
(setq pr_0 "pr2") ;精度を指定 小数点以下の桁数をpr0~pr8で表示 現在の精度の場合は空白
(setq pr (if (= pr_0 "")
""
(strcat "\%" pr_0)
)
) ;精度を示す文字列を作成
(vl-load-com)
(setq ename (car (entsel)))
(setq vlobj (vlax-ename->vla-object ename))
(setq obid (itoa (vla-get-objectid vlobj)))
;図形IDを10進法に変換 itoa必要(rtosだと64bitで不具合)
(setq fstr (strcat
"\%\<\\AcObjProp Object(\%\<\\_ObjId "
obid "\>\%).Length \\f \"%lu2"
pr "\%ps["
pref ","
suff "]%ct8["
c_unt "]\" \>\%"
)
) ;フィールド文字列を作成
;(setq tsty (getvar "TEXTSTYLE"));現在の文字スタイルを取得
(setq dsc (getvar "DIMSCALE")) ;DIMSCALEの値を取得
(setq mt (* dsc 2.8)) ;DIMSCALEのを2.8倍を文字高さとする
(setq pt (getpoint "\n文字挿入位置を指定: "))
;異尺度対応の文字スタイル・文字高さを設定した文字スタイルを分岐
(if (or (LM:isAnnotative) (textHeight))
(command "text" pt "" fstr)
(command "text" pt mt "" fstr)
)
(princ)
)
'異尺度対応の文字スタイルかどうかを判定
(defun LM:isAnnotative ( / object annotx )
(and
(setq object (tblobjname "STYLE" (getvar "TEXTSTYLE")))
(setq annotx (cadr (assoc -3 (entget object '("AcadAnnotative")))))
(= 1 (cdr (assoc 1070 (reverse annotx))))
)
)
'文字高さ設定した文字スタイルかどうかを判定
(defun textHeight ( / object txtH )
(and
(setq object (tblobjname "STYLE" (getvar "TEXTSTYLE")))
(setq txtH (cdr (assoc 40 (entget object))))
(/= 0 txtH)
)
)