多谢各位高手指点,现在做了两个小程序,主要用于统计元件的数量。现在把它拿出来供大家参考。
抛砖引玉,多谢,多谢!
根据图块名称在图中查找数量。
一、好像不太通用。
;Get the number of block for specified name
(defun c:GetNB(/ nBlk ssb numb ssb0)
(setq nBlk (getstring "lease input the BLOCK NAME : "))
(setq nlayer (getstring "lease input the Layer Name : "))
(setq ssb (ssget "x" (list (cons 2 nBlk) (cons 0 "INSERT") (cons 8 nlayer))))
(setq ssb0 (ssget "x" (list (cons 2 nBlk) (cons 0 "INSERT"))))
(ALERT (STRCAT "There are " (RTOS (SSLENGTH ssb0)) " Blocks: " nBlk "\n" (rtos (sslength ssb)) " in Layer : " nlayer))
(PRINC)
)
二、好像通用一点,但是麻烦一些。
;Get the number of the block specified name
(defun C:GETBLOCK (/ blk ss i j k ct)
(alert "This program is for calculate the number of specified blocks \nin the specified layer in the drawing,\nPlease input the block name and layer name,\npay attention to the UPERCASE AND LOWERCASE of character.")
(setq blk (getstring "lease input the block name : "))
(setq ct (getstring "lease input the layer name : "))
(setq ss (ssget "x"))
(setq k 0)
(setq j 0)
(setq i 0)
(repeat (sslength ss)
(setq ent (ssname ss i))
(if (= (cdr (assoc 0 (entget ent))) "INSERT")
(if (= (strcase blk) (strcase (cdr (assoc 2 (entget ent))))) ;change the upercase to lower case and compare
(progn
(if (= (strcase ct) (strcase (cdr (assoc 8 (entget ent)))))
(setq k (1+ k))
)
(setq j (1+ j))
)
)
)
(setq i (1+ i))
)
(alert (strcat "There are " (rtos j) " blocks : " blk "\n " (rtos k) " in Layer :" ct))
(princ) Exits quietly
)