作者phragmite (Θ.Θ)
看板Cad_Cae
标题Re: [问题] autocad超新手想发问一下图面数量计算( …
时间Tue Oct 20 17:48:04 2009
※ 引述《dogcatbig (123)》之铭言:
: 如题
: 因为小弟最近在看autocad程式设计
: autolisp+dcl+visual lisp篇这本
: (作者:吴永进、林美樱)
: 范例50
: 做到一个例题是有统计图面上的图案
: (例如:圆形、正方形、直线)
: 书上的程式描述能够自已点出数量
: 并绘出表格
: 可是小弟试的话并不行~
: 是不是小弟有什麽地方疏忽了
: 可以请教一下版上的高手吗?
: 给小弟指点一下^^
: 谢谢
回文顺便问一个条件式:
总算是做到这个范例了,可是很奇怪,题目要求是统计"图块"而不是"图案",
莫非是版本的差异? (我的书上个月买进,版次:2008年6月初版)
我在执行这个范例时并没什麽大问题(不知道原po能不能再详细描述一下问题
是什麽?)不过有一个取出图块名称字首的条件式,看不懂它的用意是什麽:
(setq blk_key (substr (cdr blkn) 1 1))
(if (/= blk_key "*")…
知道用意的热心板友请回板或站内信皆可,感谢!
另外,若如原po要求统计图案,好像只要把10test3 的例题和范例50的内容拼
凑一下就行了。但也遇到一个难解的情况:"正方形"的群码中似乎没有独立於
矩形、pline 的四边封闭围线或三段线的特徵码,计算数量时会把上述所有图
元全算进去…当然,也包括画在图面上的表格,所以会愈算愈多。
以下试作原po形容的问题,以及范例50的内容,(断行请记得接上):
=====================================================================
(defun c:lsp50a()
(setvar "cmdecho" 0)
(setq os (getvar "osmode"))
(setvar "osmode" 0)
(command "style" "cc" "txt,chineset" "" "" "" "" "" "")
;画出表头
(setq pt1 (getpoint "\n左上角: "))
(setq ww (getdist pt1 "\n宽度 <60>: "))
(if (null ww) (setq ww 60.0))
(setq hh (getdist pt1 "\n每格高度 <8>: "))
(if (null hh) (setq hh 8.0))
(setq pt2 (polar pt1 0 ww))
(setq pt3 (polar pt2 (* pi 1.5) hh))
(setq pt4 (polar pt1 (* pi 1.5) hh))
(command "pline" pt1 pt2 pt3 pt4 "c")
(setq pt5 (polar pt1 0 (/ ww 2)))
(setq pt6 (polar pt5 (* pi 1.5) hh))
(command "pline" pt5 pt6 "")
(command "text" "m" (inters pt1 pt6 pt4 pt5) (/ hh 2) 0 "图元类别")
(command "text" "m" (inters pt5 pt3 pt2 pt6) (/ hh 2) 0 "数量")
(setq type (getstring "\nChosse entity type:circle、line、arc、rectang: "))
(while (/= type "")
(if (= type "rectang")
(progn
(setq type "LWPOLYLINE")
(setq ss (ssget "x" (list (cons 0 type) (cons 90 4))))
(setq type "rectang")
)
(setq ss (ssget "x" (list (cons 0 type))))
);endif
(if (null ss)
(setq count 0)
(setq count (sslength ss))
);endif
;画出表格
(setq pt1 pt4 pt5 pt6 pt2 pt3)
(setq pt4 (polar pt1 (* pi 1.5) hh))
(setq pt6 (polar pt5 (* pi 1.5) hh))
(setq pt3 (polar pt2 (* pi 1.5) hh))
(command "pline" pt2 pt3 pt4 pt1 "")
(command "pline" pt5 pt6 "")
(command "text" "m" (inters pt1 pt6 pt4 pt5) (/ hh 2) 0 type)
(command "text" "m" (inters pt5 pt3 pt2 pt6) (/ hh 2) 0 (itoa count))
(setq type (getstring "\nEnter entity type (circle、line、arc、
rectang): "))
);end while
(setvar "osmode" os)
(prin1)
)
(prompt "***************<<c:lsp50a>>***************")
(prin1)
==============================================================================
(defun c:lsp_50()
(setvar "cmdecho" 0)
(setq os (getvar "osmode"))
(setvar "osmode" 0)
(setq pt1 (getpoint "\n左上角: "))
(setq ww (getdist pt1 "\n宽度 <50>: "))
(if (null ww) (setq ww 40.0))
(setq hh (getdist pt1 "\n每格高度 <8>: "))
(if (null hh) (setq hh 8.0))
(setq pt2 (polar pt1 0 ww))
(setq pt3 (polar pt2 (* pi 1.5) hh))
(setq pt4 (polar pt1 (* pi 1.5) hh))
(command "pline" pt1 pt2 pt3 pt4 "c")
(setq pt5 (polar pt1 0 (/ ww 2)))
(setq pt6 (polar pt5 (* pi 1.5) hh))
(command "line" pt5 pt6 "")
(command "text" "m" (inters pt1 pt6 pt4 pt5) (/ hh 2) 0 "图块名称")
(command "text" "m" (inters pt5 pt3 pt2 pt6) (/ hh 2) 0 "数量")
(setq blk (tblnext "block" t))
(while blk
(setq blkn (assoc 2 blk))
;这里看不懂用意是什麽
(setq blk_key (substr (cdr blkn) 1 1))
(if (/= blk_key "*")
(progn
(setq ss (ssget "X" (list blkn)))
(if (null ss)
(setq ssn 0)
(setq ssn (sslength ss))
)
(setq blknn (cdr blkn))
(setq pt1 pt4 pt5 pt6 pt2 pt3)
(setq pt4 (polar pt1 (* pi 1.5) hh))
(setq pt6 (polar pt5 (* pi 1.5) hh))
(setq pt3 (polar pt2 (* pi 1.5) hh))
(command "pline" pt2 pt3 pt4 pt1 "")
(command "line" pt5 pt6 "")
(command "text" "m" (inters pt1 pt6 pt4 pt5) (/ hh 2) 0 blknn)
(command "text" "m" (inters pt5 pt3 pt2 pt6) (/ hh 2) 0 (itoa
ssn))
)
)
(setq blk (tblnext "block"))
)
(setvar "osmode" os)
(prin1)
)
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 61.228.204.242
1F:→ phragmite:试了加上四边等长两角垂直的条件,应该可符合原po的要求 10/21 00:18
2F:→ phragmite: 线 10/21 00:21