-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRenameBlkReplaceBlk.lsp
77 lines (74 loc) · 2.07 KB
/
RenameBlkReplaceBlk.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
; Author: Roy Klein Gebbinck (www.b-k-g.nl)
; Version: 20180711: First version.
; Created for: https://forum.bricsys.com/discussion/33839/anonymous-blocks?
(defun KGA_Sys_ApplyAlt (expr varLst)
(not (vl-catch-all-error-p (vl-catch-all-apply expr varLst)))
)
(defun c:RenameBlk ( / blk doc enm nme obj)
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(vla-endundomark doc)
(vla-startundomark doc)
(if
(and
(setq enm (car (entsel "\nSelect insert: ")))
(setq obj (vlax-ename->vla-object enm))
(or
(= "AcDbBlockReference" (vla-get-objectname obj))
(prompt "\nError: not an insert ")
)
(setq blk (vla-item (vla-get-blocks doc) (vla-get-name obj)))
(or
(= :vlax-false (vla-get-isxref blk))
(prompt "\nError: this is an insert of an xref ")
)
(setq nme (getstring T "\nNew name: "))
(or
(snvalid nme)
(prompt "\nError: name not valid ")
)
(or
(not (tblobjname "block" nme))
(princ "\nError: name is already in use ")
)
)
(if (KGA_Sys_ApplyAlt 'vla-put-name (list blk nme))
(princ "\nBlock successfully renamed ")
)
)
(vla-endundomark doc)
(princ)
)
(defun c:ReplaceBlk ( / doc nme res ss)
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(vla-endundomark doc)
(vla-startundomark doc)
(if
(and
(setq ss (ssget '((0 . "INSERT") (66 . 0)))) ; Only select inserts without attributes.
(setq nme (getstring T "\nName of replacement block or xref: "))
(or
(tblobjname "block" nme)
(princ "\nError: replacement not found ")
)
)
(progn
(setq res
(mapcar
'(lambda (enm) (KGA_Sys_ApplyAlt 'vla-put-name (list (vlax-ename->vla-object enm) nme)))
(vle-selectionset->list ss)
)
)
(princ
(strcat
"\n"
(itoa (length (vl-remove nil res)))
"/"
(itoa (length res))
" Block(s) successfully replaced "
)
)
)
)
(vla-endundomark doc)
(princ)
)