mike_ribeiro Posted April 9 Posted April 9 (edited) Good afternoon I really need to have a lisp routine that: - Let me select a main block - answer for the prefix to rename all nested blocks - rename all nested blocks in the block i selected and keep the name of the "main block" equal (without rename). I found this routine here in the forum (thanks to who posted) but also renames the main block and i dont know how to change it... (defun c:rnb (/ getNestedNames remove_duplicates ss n ent name lst) (vl-load-com) (or *acdoc* (setq *acdoc* (vla-get-ActiveDocument (vlax-get-acad-object)))) (or *blocks* (setq *blocks* (vla-get-Blocks *acdoc*))) ;; Returns a list of the nested block names (defun getNestedNames (name / lst) (vlax-for o (vla-Item *blocks* name) (if (= (vla-get-ObjectName o) "AcDbBlockReference") (setq lst (append (list (vla-get-Name o)) (getNestedNames (vla-get-Name o)) lst ) ) ) ) lst ) ;; Removes all duplicates from a list (defun remove_duplicates (lst) (if lst (cons (car lst) (remove_duplicates (vl-remove (car lst) lst))) ) ) ;; Main (if (setq pref (getstring "\nEnter the prefix to add: ")) (progn (vla-StartUndoMark *acdoc*) (princ "\Select bloc to rename (or Enter for all)") (if (ssget '((0 . "INSERT"))) ;; selection (progn (vlax-for b (setq ss (vla-get-ActiveSelectionSet *acdoc*)) (setq name (vla-get-name b)) (if (not (vl-position name lst)) (setq lst (append (list name) (getNestedNames name) lst)) ) ) (vla-delete ss) (foreach n (remove_duplicates lst) (vla-put-Name (vla-item *blocks* n) (strcat pref n)) ) ) ;; all (vlax-for b *blocks* (if (and (= (vla-get-IsLayout b) :vlax-false) (= (vla-get-IsXref b) :vlax-false) (not (wcmatch (setq name (vla-get-Name b)) "*|*")) ) (vla-put-Name b (strcat pref name)) ) ) ) (vla-EndUndoMark *acdoc*) ) ) (princ) ) Thanks in advance Edited April 9 by SLW210 Added Code Tags Quote
SLW210 Posted April 9 Posted April 9 Please use Code Tags in the future. (the <> in the editor toolbar) Quote
mike_ribeiro Posted April 10 Author Posted April 10 Thanks SLW210. I''ll keep that in mind for the next time Quote
pkenewell Posted April 10 Posted April 10 (edited) @mike_ribeiroTry commenting out the following lines: ;; (if (not (vl-position name lst)) ;; (setq lst (append (list name) (getNestedNames name) lst)) ;; ) EDIT - AND add this line right below the commented lines (setq lst (getNestedNames name)) Edited April 10 by pkenewell Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.