IT Knowledge Base

~ Without sacrifice, there can be no victory ~

發佈日期:

如何在AutoCAD中‧使用AutoLISP‧將選擇物件快速轉成Block物件

在AutoCAD中,Block可能是比較少用的命令。使用Block的時候,只是為了方便將整堆的物件作複製或移動,故Block名稱、位置,某程度上根本沒有關係。

今次這一個Lisp程式目的,只需要使用者,選擇需變成Block的物件,其他則交由程式來控制。

;Main program.
(DEFUN C:W (/ A A1 B E F FN I G H)
(PROMPT "\\nWrite selected objects into block.")
(INITIAL)
(C:OF)
(PROMPT "\\nSelect object(s) to write block: ")
(SETQ A (SSGET))
(SETQ G (GETVAR "DWGPREFIX"))
(SETQ A1 (GETVAR "USERI1"))
(IF (= A1 0)
(PROGN
(PROMPT "\\nBlock is started at number 10000.\\n")
(SETVAR "USERI1" 10000)
(SETQ A1 10000)
)
)
(SETQ H (GETVAR "DIMZIN"))
(SETVAR "DIMZIN" 9)
(SETQ A1 (+ 1 A1))
(SETQ BB (RTOS A1))
(SETQ BE (TBLSEARCH "BLOCK" BB))
(WHILE (/= BE nil)
(SETQ A1 (+ 1 A1))
(SETQ BB (RTOS A1))
(SETQ BE (TBLSEARCH "BLOCK" BB))
)
(SETQ FN A1)
(IF (= A1 60000)
(PROG
(ALERT "Error: Cannot write more blocks.\\n\\nProgram halt.")
(EXIT)
)
)
(SETVAR "USERI1" A1)
(SETQ B (SSLENGTH A))
(SETQ I 0)
(REPEAT B
(SETQ E (SSNAME A I))
(SETQ F (ENTGET E))
(IF (= (CDR (ASSOC 0 F)) "POINT")
(COMMAND "ERASE" E "")
)
(SETQ I (+ 1 I))
)
(COMMAND "BLOCK" FN "0,0" A "")
(COMMAND "ERASE" A "")
(COMMAND "INSERT" FN "0,0" "" "" "")
(SETVAR "DIMZIN"H)
(C:ON)
(AFTER)
)

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *