自动标注面积代码的问题
请教下面的代码运行中会出现“指定第一个角点或 [对象(O)/加(A)/减(S)]: object
选择对象:
面积 = 666.6670,周长 = 153.3334
命令: MJ 未知命令“MJ”。按 F1 查看帮助。
命令:”
另外有没有办法让平方米和亩都写在一起?(defun c:mj ()
;;;; get area A1
(setq p1 (getpoint "\n请在要标注封闭区域内点一下:"))
(command "-boundary" p1 "")
(setq bj (entlast))
(command "area" "object" bj "")
(setq mj (rtos (getvar "area") 2 3))
(setq area1 (strcatmj "m2^"))
;;;;change to A2
(setq ans (* (/ (atof area1) 10000.0) 15.0))
(setq ans (rtos ans 2 3))
(setq area2 (strcat ans "mu"))
;;;; write answer
(setq pt1 (getpoint "\n请选择标注文字的位置:(平方米)"))
(command "text" pt1 "" "" area1)
(setq pt2 (getpoint "\n请选择标注文字的位置:(亩)"))
(command "text" pt2 "" "" area2)
(setvar "osmode" oldos)
(setvar "cmdecho" 1)
(setq *error* olderr)
(princ)
)
哪个哥哥来帮我优化一下嘛!谢谢
本帖最后由 作者 于 2007-4-7 15:12:56 编辑
修改了一下:
(defun c:mj ()
;;;; get area A1
(setq os (getvar "osmode"))
(setq cmd (getvar "cmdecho"))
(setvar "osmode" 0)
(setvar "cmdecho" 0)
(setq p1 (getpoint "\n请在要标注封闭区域内点一下:"))
(command "-boundary" p1 "")
(setq bj (entlast))
(command "area" "object" bj)
(entdel bj)
(setq mj (rtos (getvar "area") 2 3))
(setq area1 (strcat mj "{\\fSimSun|b0|i0|c134|p2;平方米 (}"))
;;;;change to A2
(setq ans (* (/ (atof area1) 10000.0) 15.0))
(setq ans (rtos ans 2 3))
(setq area2 (strcat area1 ans "{\\fSimSun|b0|i0|c134|p2;亩)}"))
;;;; write answer
(entmake (list '(0 . "MTEXT")
'(100 . "AcDbEntity")
'(100 . "AcDbMText")
(cons 10 p1)
(cons 40 5)
(cons 41 0)
(cons 71 0)
(cons 50 0)
'(72 . 5)
(cons 1 area2)
)
)
(setvar "osmode" os)
(setvar "cmdecho" cmd)
;;;(setq *error* olderr)
(princ)
)
本帖最后由 作者 于 2007-4-7 12:10:06 编辑 <br /><br /> <p>老问题已经解决,新问题出现!我试过把m2^ 和mu换成平方米和亩,显示出来实在太难看了!</p><p>现在我想在一行里用mtext来把AREA1和AREA2的单位也给弄出来(平方米 亩)!定义字体为宋体字,大小为5,角度为0。</p><p>如:1000平方米(15亩)</p><p> 或者1000m<sup>2 </sup>(15亩)</p><p></p><p>弄了半天总觉得不满意,请高手帮忙!</p> 2楼已修改过了,你试试 <p> <font color="#ff0000">(</font><a href="http://www.mjtd.com/object/autolisp/setq.htm" target="_black"><font color="#0000ff">setq</font></a> area1 <font color="#ff0000">(</font><a href="http://www.mjtd.com/object/autolisp/strcat.htm" target="_black"><font color="#0000ff">strcat</font></a> mj <font color="#ff00ff">"{\\fSimSun|b0|i0|c134|p2;平方米 <font color="#ff0000">(</font>}"</font><font color="#ff0000">)</font><font color="#ff0000">)</font></p><p><font color="#ff0000">这一句?看都看不懂,第一次见到</font></p><p><font color="#ff0000">我是新手</font></p> 为何不把“平方米”改成“㎡”不是更好看?
页:
[1]