这是对我的一些其他代码的修改,它现在可以作为输入块的快捷方式,例如B1会说“Block1”。唯一的规则是你必须使用B或B作为第一个字符,你可以使用数字或字母,这无关紧要,你需要更改几件事目录名并创建一个新的lst。这是版本1,因此使用当前图形中的现有块,该图形预计将成为dwg模板。正如其他人所建议的那样,我会将所有块加载到当前的dwg中,并在以后使用lee mac steal时清除它们。lsp首先从dwg加载所有块。
- ; original code and methology by Alan H
- ; assistance and code that worked by Lee-Mac
- ; Insert blocks by shortcut June 2017
- (vl-load-com)
- ( (lambda nil
- (foreach obj (cdar (vlr-reactors :vlr-command-reactor))
- (if (= "Blk-reactor" (vlr-data obj))
- (vlr-remove obj)
- )
- )
- (vlr-command-reactor "Blk-reactor" '((:vlr-unknowncommand . Blk-reactor-callback)))
- )
- )
- (defun blkins ( / blkname ans lst len acdoc x pt ptstr fname)
- (setq acdoc (vla-get-activedocument (vlax-get-acad-object))) ; open database
- (setq lst (list "1" "001" "2" "002" "3" "003" "4" "Northn")) ; test lst of blocks
- (setq len (length lst)) ; how many items in lst
- (setq ans (substr com 2)) ; return the characters after B or b
- (setq x 0)
- (repeat len
- (if (= (nth x lst) ans)
- (setq blkname (nth (+ x 1) lst)) ; find blockname in lst can be improved with a while
- ) ; if
- (setq x (+ x 2)) ; lst is pairs
- ) ; repeat
- (setq pt (getpoint "Select insertion point"))
- (setq ptstr (strcat (rtos (car pt) 2 3) "," (rtos (cadr pt) 2 3))) ; convert pt to xy
- (setq fname "C:\\Alan\\blkins.scr") ; script filename
- (setq fo (open fname "w"))
- (write-line (strcat "-insert " blkname " " ptstr " 1 1 0") fo)
- (write-line "filedia 1" fo) ; turn dialouges abck on
- (close fo) ; close file
- (vla-sendcommand acdoc "filedia 0 ") ; turn off dialouges
- (vla-sendcommand acdoc "_.script C:\\Alan\\blkins.scr") ; run script file as insert will read entire line
- (vla-sendcommand acdoc (chr 13)) ; need a Cr press Enter
- )
- (defun Blk-reactor-callback ( obj com )
- (setq com (vl-string-translate "-" "." (strcase (car com)))) ; strcase so B or b
- (cond
- ( (and
- (wcmatch com "~*[~B.0-9]*")
- (wcmatch com "B*")
- (wcmatch com "~B*B*")
- (wcmatch com "~*.*.*")
- ) ; and
- (blkins)
- )
- ) ; master cond
- ) ; defun
- ; make block list to file
- ; by Alan H june 2017
- (vl-load-com)
- (setq fo (open "c:\\alan\\block-names.txt" "w"))
- (setq doc (vla-get-activedocument (vlax-get-acad-object)))
- (vlax-for blk (vla-get-blocks doc)
- (write-line (vla-get-name blk) fo)
- (princ (vla-get-name blk))
- )
- (close fo)
编辑文件块名称。我粘贴到excel的txt已排序并删除了一些块名。第二遍将数字添加到块名,并使LST粘贴到代码中。
|