-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlockRename.lsp
43 lines (43 loc) · 1.46 KB
/
BlockRename.lsp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
(defun c:BlockRenamer (/ b f r n gl bl)
;; Alan J. Thompson, 03.26.10
(vl-load-com)
(cond
((and (/= "" (setq b (getstring t "Block name pattern: ")))
(/= "" (setq f (getstring t "String to replace: ")))
(/= "" (setq r (getstring t "Replacement string: ")))
) ;_ and
(or *AcadDoc* (setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object))))
(vlax-for x (vla-get-blocks *AcadDoc*)
(if
(and (not (wcmatch (setq n (vla-get-name x)) "*|*,_*")) (wcmatch (strcase n) (strcase b)))
(if (vl-catch-all-error-p
(vl-catch-all-apply (function vla-put-name) (list x (vl-string-subst r f n)))
) ;_ vl-catch-all-error-p
(setq bl (cons n bl))
(setq gl (cons (cons n (vla-get-name x)) gl))
) ;_ if
) ;_ if
) ;_ vlax-for
(if (or gl bl)
(alert
(strcat
(if gl
(strcat "The following blocks were renamed (Old . New):\n\n"
(vl-princ-to-string (vl-sort gl (function (lambda (a b) (< (car a) (car b))))))
) ;_ strcat
""
) ;_ if
(if bl
(strcat "\n\n\nThe following blocks could NOT be renamed:\n\n"
(vl-princ-to-string (vl-sort bl '<))
) ;_ strcat
""
) ;_ if
) ;_ strcat
) ;_ alert
(alert "Nothing renamed.")
) ;_ if
)
) ;_ cond
(princ)
) ;_ defun