Re: [問題] autocad超新手想發問一下圖面數量計算( …

看板Cad_Cae (電腦輔助設計)作者 (Θ.Θ)時間16年前 (2009/10/20 17:48), 編輯推噓0(002)
留言2則, 1人參與, 最新討論串1/1
※ 引述《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

10/21 00:18, , 1F
試了加上四邊等長兩角垂直的條件,應該可符合原po的要求
10/21 00:18, 1F

10/21 00:21, , 2F
10/21 00:21, 2F
文章代碼(AID): #1AtOTNLB (Cad_Cae)
文章代碼(AID): #1AtOTNLB (Cad_Cae)