1
使用AutoLISP(用於AutoCAD 2015)時,我正在研究腳本,該腳本可以計算放置在特定圖層上的所有矩形的總長度。如何總結圖層中所有矩形的長邊?
(具體目的:我有代表打算進行木地板的木橫樑多個矩形圖層我要計算有多少梁米將不得不購買這個樓。)
什麼到目前爲止,我已經計算了圖層上所有線條長度的總和。迄今爲止,這工作得很好。它將返回圖層上所有矩形的(圓周)線的總長度以及找到的矩形的數量。
(defun C:PLINELEN (/ ent sset obj len sum layer a)
(setvar "ERRNO" 0)
(while
(and (not (setq ent (car (entsel "Select object on layer: "))))
(/= (getvar "ERRNO") 52)
)
)
(cond ((and ent
(setq sset
(ssget
"X"
(list '(0 . "LWPOLYLINE")
(cons 8 (setq layer (cdr (assoc 8 (entget ent)))))
)
)
)
)
(setq a 0
sum 0
)
(repeat (sslength sset)
(setq obj (vlax-ename->vla-object (ssname sset a))
len (vlax-curve-getDistAtParam
obj
(- (vlax-curve-getEndParam obj)
(vlax-curve-getStartParam obj)
)
)
sum (+ sum len)
)
(setq a (1+ a))
)
(princ (strcat "\nTotal length of "
(itoa a)
(if (= a 1)
" pline on layer "
" plines on layer "
)
layer
": "
(rtos sum)
)
)
)
(T (princ "\nNo plines found"))
)
(princ)
)
現在缺少的卻又是功能撇開所有短矩形的兩側,並總結了只有長兩側。
對於我的理解,最簡單的解決辦法是:增加功能,以確定該層上發現了矩形的所有短邊的長度的總和,然後從「和」減去它)
在僞代碼:
(iterate through all rectangles on the layer
(measure all four sides of the rectangle)
(compare the four measurements and store [one of the] shortest into variable x)
(sumOfShortSides = sumOfShortSides + x)
)
我最那裏的方式,但我需要一個三分球,以提高我的現有代碼砸短邊。其他解決方案也很受歡迎。
如何總結圖層中所有矩形的長邊?
這不是它的方式,你需要自己開始,設置一些代碼,然後問這裏是否有你無法處理的東西。你可以編輯問題,並顯示你已經嘗試過的小樣本嗎? – kebs
好的,我會盡快發佈。 (我認爲需要幾個小時。) –
添加到問題的實驗腳本。 –