Fix Automation Error. Key not found another drawing !

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all, ^_^
I writed another lisp with DBX following (i found some function of Lee). But lisp return error "Automation Error. Key not found" for drawing not have block name selected in current drawing.
How can fix it ?
Thank you.
(defun c:test (/ ename old_name new_name lst lst_name tmp tmpf fo aline)
(setq ename (car (entsel "\nSelect block to RENAME:")))
(setq old_name (vla-get-effectivename (vlax-ename->vla-object ename)))
(setq new_name (getstring T "\nSelect new name block to RENAME: "))
;temp txt
(setq tmp "C:/Users/Public/temp.txt")
(if (findfile tmp)
(vl-file-delete tmp)
)
;write temp txt
(setq tmpf (open tmp "w"))
(write-line old_name tmpf)
(write-line new_name tmpf)
(close tmpf)
(if (setq lst (LM:getfiles "Select Drawings to Process" nil "dwg;dws;dwt")
);setq
(LM:odbx '(lambda (doc)
(setq tmp (strcat "C:/Users/Public/temp.txt"))
(setq lst_name nil)
(if (findfile tmp)
(progn
(setq fo (open tmp "r"))
(while (setq aline (read-line fo)) (setq lst_name (cons aline lst_name)));while
(close fo)
;return lst is (old_name new_name)
(setq lst_name (reverse lst_name))
);progn
);if
(rename_blk doc lst_name)
)
lst
t
)
(princ "\n*Cancel*")
);if
(princ)
)
(defun rename_blk ( doc lst / blc)
(setq blc (vla-get-blocks doc));setq
(if (and (not (tblsearch "BLOCK" (cadr lst)))
(tblsearch "BLOCK" (car lst))
);and
(vla-put-Name (vla-item blc (car lst)) (cadr lst))
);if
);defun