Jump to content

Renaming nested blocks


mike_ribeiro

Recommended Posts

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 by SLW210
Added Code Tags
Link to comment
Share on other sites

@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 by pkenewell
Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...