AutoCAD顧問
還沒有註冊嗎...即日起免費註冊,所有最完整的AutoCAD討論、教學及資源都在論壇裡喔~

Join the forum, it's quick and easy

AutoCAD顧問
還沒有註冊嗎...即日起免費註冊,所有最完整的AutoCAD討論、教學及資源都在論壇裡喔~
AutoCAD顧問
Would you like to react to this message? Create an account in a few clicks or log in to continue.
[已解決] 計算面積 Ioaoe110[已解決] 計算面積 2020-310[已解決] 計算面積 Oiu15010[已解決] 計算面積 2020-211[已解決] 計算面積 Ia15010[已解決] 計算面積 Aizyao10[已解決] 計算面積 Uos15010[已解決] 計算面積 BPl3tjj[已解決] 計算面積 Ziao1510
[已解決] 計算面積 Oo-2-110[已解決] 計算面積 Zuoiy_10[已解決] 計算面積 Aizyao11[已解決] 計算面積 Iyb_1510[已解決] 計算面積 Aoe1-111[已解決] 計算面積 Uos15011[已解決] 計算面積 Aoe2da10[已解決] 計算面積 Aoe2da11[已解決] 計算面積 Aoe10

[已解決] 計算面積

4 posters

向下

[已解決] 計算面積 Empty [已解決] 計算面積

發表 由 salad123 2012-04-28, 01:18

以下是本人近日寫既lisp
我想框選出一堆object, 計算出其總面積~
用area / aa, 去加總, 要一個個點選, 有點費時
程式在框選到text 或沒有面積的物件時, 會出現錯誤, 使其不能計算出總面積, 我要怎樣做才可解決?
我已經用if, 定出某些物件才執行程式, 為何還會出現錯誤?
如只框選polyline, circle, epllise等, 才能計算出答案

;;;-----------------------------------------------------
; Function : Sum Area Boundary
; Command Key : ABC
;

(defun c:abc(/ ss i j sslist sum ssn ssdata sstype st1)
(setvar "cmdecho" 0)

; Set the Value
; ss = Selection of Object
; i = Define the Selection(ss) Starting No.
; j = Define the Number Code of the List(sslist)
; sslist = Set the list to store each area value (st1)
; sum = total area value
(prompt "\nSelect Object:")
(setq ss (ssget))
(setq i 0 j 0)
(setq sslist '())
(setq sum 0)

; ssn = Idenify Each Selection in the Selection Group
; ssdata = Get Selection' Information
; sstype = Get Selection' Type
; st1 = Object Area (Text)
(repeat (sslength ss)
(setq ssn (ssname ss i))
(setq ssdata (entget ssn))
(setq sstype (cdr (assoc 0 ssdata)))
(if (or (= sstype "CIRCLE")(= sstype "LWPOLYLINE")(= sstype "REGION")(= sstype "ELLIPSE"))
(progn
(command "area" "o" ssn)
(setq st1 (rtos (getvar "area") 2 4))
(princ)
(princ "\n")
(princ st1)
(princ "\n")
(setq sslist (cons st1 sslist))
(setq i (1+ i))
)))

(repeat (length sslist)
(setq st1 (atof (nth j sslist)))
(setq sum (+ st1 sum))
(setq j (1+ j)))
(setq sum (rtos sum 2 3))
(princ "\nSelected Total Area= ")(princ sum)
(princ))


salad123 在 2012-04-28, 11:51 作了第 2 次修改
salad123
salad123
一般會員
一般會員

文章總數 : 61
年齡 : 41
來自 : 香港
職業 : 建築
愛好 : 寫lisp
個性 : 追求簡潔, 快捷
使用年資 : 5
使用版本 : 2011
經驗值 : 5201
威望值 : 108
注冊日期 : 2011-01-06
藍鵲407號
男 水瓶座 狗

回頂端 向下

[已解決] 計算面積 Empty 回復: [已解決] 計算面積

發表 由 Atsai 2012-04-28, 08:46

在選集的時候先篩選物件型式,
再把原本判斷物件型式的程式碼拿掉就好了!
下面是修改後的程式碼!


;;;-----------------------------------------------------
; Function : Sum Area Boundary
; Command Key : ABC
;

(defun c:abc (/ ss i j sslist sum ssn ssdata sstype st1)
(setvar "cmdecho" 0)

; Set the Value
; ss = Selection of Object
; i = Define the Selection(ss) Starting No.
; j = Define the Number Code of the List(sslist)
; sslist = Set the list to store each area value (st1)
; sum = total area value
(prompt "\nSelect Object:")

;;;先在下面這一列篩選圖元型式
(setq ss (ssget '((0 . "CIRCLE,LWPOLYLINE,REGION,ELLIPSE"))))

(setq i 0
j 0
)
(setq sslist '())
(setq sum 0)

; ssn = Idenify Each Selection in the Selection Group
; ssdata = Get Selection' Information
; sstype = Get Selection' Type
; st1 = Object Area (Text)
(repeat (sslength ss)
(setq ssn (ssname ss i))
; (setq ssdata (entget ssn))
; (setq sstype (cdr (assoc 0 ssdata)))
; (if (or (= sstype "CIRCLE")
; (= sstype "LWPOLYLINE")
; (= sstype "REGION")
; (= sstype "ELLIPSE")
; )
; (progn

(command "area" "o" ssn)
(setq st1 (rtos (getvar "area") 2 4))
(princ)
(princ "\n")
(princ st1)
(princ "\n")
(setq sslist (cons st1 sslist))
(setq i (1+ i))
; )
; )

)

(repeat (length sslist)
(setq st1 (atof (nth j sslist)))
(setq sum (+ st1 sum))
(setq j (1+ j))
)
(setq sum (rtos sum 2 3))
(princ "\nSelected Total Area= ")
(princ sum)
(princ)
)
Atsai
Atsai
中級會員
中級會員

文章總數 : 159
年齡 : 48
來自 : 台中
職業 : 工程
愛好 : 看漫畫
個性 : 樂天
使用年資 : 10
使用版本 : 2010
AutoCAD基礎篇等級 : 10星級
積分 : 8
經驗值 : 5619
威望值 : 490
注冊日期 : 2012-04-06
男 金牛座 兔

回頂端 向下

[已解決] 計算面積 Empty 回復: [已解決] 計算面積

發表 由 salad123 2012-04-28, 11:44

謝謝你~~成功了!!!
這樣子我便可再進一步, 深化此程式了~
salad123
salad123
一般會員
一般會員

文章總數 : 61
年齡 : 41
來自 : 香港
職業 : 建築
愛好 : 寫lisp
個性 : 追求簡潔, 快捷
使用年資 : 5
使用版本 : 2011
經驗值 : 5201
威望值 : 108
注冊日期 : 2011-01-06
藍鵲407號
男 水瓶座 狗

回頂端 向下

[已解決] 計算面積 Empty 回復: [已解決] 計算面積

發表 由 salad123 2012-04-28, 11:55

能不能多問一句, 為什麼我加入(= sstype "CIRCLE")這些句法, 會出現錯誤? 能不能加以解釋一下? 我想在編寫其他程式時, 不會再犯這個錯誤
salad123
salad123
一般會員
一般會員

文章總數 : 61
年齡 : 41
來自 : 香港
職業 : 建築
愛好 : 寫lisp
個性 : 追求簡潔, 快捷
使用年資 : 5
使用版本 : 2011
經驗值 : 5201
威望值 : 108
注冊日期 : 2011-01-06
藍鵲407號
男 水瓶座 狗

回頂端 向下

[已解決] 計算面積 Empty 回復: [已解決] 計算面積

發表 由 Atsai 2012-04-28, 12:44

看你原來的程式碼好像是OK的!
但是執行時先選到文字,則結果會都是0。

所以出錯的部份應該是在建立 sslist的部份!



____________________________________________________________________________________
[已解決] 計算面積 Ioaoe110 [已解決] 計算面積 Zuoiy_10 [已解決] 計算面積 2020-211 [已解決] 計算面積 Aizyao11 [已解決] 計算面積 Iyb_1510
[已解決] 計算面積 Aizyao10 [已解決] 計算面積 BPl3tjj.png [已解決] 計算面積 Ziao1510 [已解決] 計算面積 Oo-2-110 [已解決] 計算面積 Oooa_110
Atsai
Atsai
中級會員
中級會員

文章總數 : 159
年齡 : 48
來自 : 台中
職業 : 工程
愛好 : 看漫畫
個性 : 樂天
使用年資 : 10
使用版本 : 2010
AutoCAD基礎篇等級 : 10星級
積分 : 8
經驗值 : 5619
威望值 : 490
注冊日期 : 2012-04-06
男 金牛座 兔

回頂端 向下

[已解決] 計算面積 Empty 回復: [已解決] 計算面積

發表 由 salad123 2012-04-28, 14:04

原來是這樣, 謝謝你~
那麼我再修改一下, 再問各位啦
thx~
salad123
salad123
一般會員
一般會員

文章總數 : 61
年齡 : 41
來自 : 香港
職業 : 建築
愛好 : 寫lisp
個性 : 追求簡潔, 快捷
使用年資 : 5
使用版本 : 2011
經驗值 : 5201
威望值 : 108
注冊日期 : 2011-01-06
藍鵲407號
男 水瓶座 狗

回頂端 向下

[已解決] 計算面積 Empty 回復: [已解決] 計算面積

發表 由 gt.adan 2012-05-04, 12:23

原來salad大也會寫程式啊~
高手一堆呢! 竊喜
gt.adan
gt.adan
初級會員
初級會員

文章總數 : 59
年齡 : 46
來自 : 彰化
職業 : 五金製造
愛好 : 研發
個性 : 和群、有耐心
使用年資 : 3年
使用版本 : 2006
積分 : 4
經驗值 : 4867
威望值 : 113
注冊日期 : 2011-11-11
經典問與答讀者 藍鵲372號
男 獅子座 蛇

回頂端 向下

[已解決] 計算面積 Empty 回復: [已解決] 計算面積

發表 由 ianlcc 2012-06-25, 20:25

這個很好用,不錯,省掉很多一個一個選擇的時間;不過若能夠將所選的物體列成一個文字檔,裡面有計算式的話,應該會更棒!!
再來繼續爬文研究,謝謝您的分享!

____________________________________________________________________________________
[已解決] 計算面積 Ioaoe110 [已解決] 計算面積 Zuoiy_10 [已解決] 計算面積 2020-211 [已解決] 計算面積 Aizyao11 [已解決] 計算面積 Iyb_1510
[已解決] 計算面積 Aizyao10 [已解決] 計算面積 BPl3tjj.png [已解決] 計算面積 Ziao1510 [已解決] 計算面積 Oo-2-110 [已解決] 計算面積 Oooa_110
ianlcc
ianlcc
一般會員
一般會員

文章總數 : 152
年齡 : 49
來自 : 高雄市
職業 : 營建業
愛好 : 拍照、喝咖啡、看電演、上網
個性 : 平靜
使用年資 : 5
使用版本 : 2012
經驗值 : 5107
威望值 : 63
注冊日期 : 2012-06-24
顧問外掛程式 藍鵲486號
男 雙魚座 兔

回頂端 向下

回頂端


 
這個論壇的權限:
無法 在這個版面回復文章
[已解決] 計算面積 Ioaoe110[已解決] 計算面積 2020-310[已解決] 計算面積 Oiu15010[已解決] 計算面積 2020-211[已解決] 計算面積 Ia15010[已解決] 計算面積 Aizyao10[已解決] 計算面積 Uos15010[已解決] 計算面積 BPl3tjj[已解決] 計算面積 Ziao1510
[已解決] 計算面積 Oo-2-110[已解決] 計算面積 Zuoiy_10[已解決] 計算面積 Aizyao11[已解決] 計算面積 Iyb_1510[已解決] 計算面積 Aoe1-111[已解決] 計算面積 Uos15011[已解決] 計算面積 Aoe2da10[已解決] 計算面積 Aoe2da11[已解決] 計算面積 Aoe10