Fix Automation Error. Key not found another drawing !

Fix Automation Error. Key not found another drawing !

Anonymous
Not applicable
1,152 Views
3 Replies
Message 1 of 4

Fix Automation Error. Key not found another drawing !

Anonymous
Not applicable

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

0 Likes
1,153 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable

ahhh,

 

add more some check with if and property and no error.

 

^_^

 

Thanks all for see this topic. 

0 Likes
Message 3 of 4

devitg
Advisor
Advisor

please upload some dwg samples 2016 or less

0 Likes
Message 4 of 4

Anonymous
Not applicable

Uhm, i fixed done.

 

Thanks for repply Devitg. ^_^

0 Likes