Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Contributor
MAD_MONK42
Posts: 21
Registered: ‎01-25-2008
Message 1 of 18 (883 Views)

Batch Rename Blocks

883 Views, 17 Replies
02-29-2008 07:45 AM
Hi,
Please excuse if this question has already been posted.
(I couldn't find one exactly)

I would like to batch rename all blocks in a drawing to NEWJOB01, NEWJOB02 ,etc.
I can't use wildcards with RENAME command because the old names don't always have a common name.
I prefer to use a lisp routine.

Thanks,

Murtz
Valued Contributor
YankeeSteve
Posts: 70
Registered: ‎02-08-2008
Message 2 of 18 (885 Views)

Re: Batch Rename Blocks

03-03-2008 09:25 AM in reply to: MAD_MONK42
(defun C:BN- ( / blist bl b n)
(setq blist '() bl nil b 0 n "NEWJOB")
(while (setq bl (tblnext "block" (not bl)))
(and (zerop (logand 53 (cdr (assoc 70 bl))))
(not (wcmatch "`**" (setq bl (cdr (assoc 2 bl)))))
(or (member bl blist) (setq blist (cons bl blist)))
)
)
(while (and (car blist) (setq b (1+ b)))
(command "_.-rename" "_b" (car blist)
(strcat n (if (< b 10) "0" "") (itoa b)))
(setq blist (cdr blist))
)
(princ)
)
Contributor
MAD_MONK42
Posts: 21
Registered: ‎01-25-2008
Message 3 of 18 (884 Views)

Re: Batch Rename Blocks

03-03-2008 01:00 PM in reply to: MAD_MONK42
Thanks a lot.

Murtz
Active Contributor
abrusil33
Posts: 26
Registered: ‎01-31-2003
Message 4 of 18 (824 Views)

Batch Rename Blocks - HELP please, Thank you.

02-22-2013 10:57 AM in reply to: YankeeSteve

I would like to rename just a single revision Letter and or option Numbers in the name of multiple blocks

(text string "ZZZ-123-rev.A-object name-option.1-date").


For example, I have 15 blocks in the drawing with names similar to:

  • "blabla-REV.A-blabla-OPTION.1-blabla"

and I need to revise to

  • REV.B and / or (optional) OPTION.2 ("blabla-REV.B-blabla-OPTION.2-blabla"), so I have to 

"C:ren", and change one by one, coz wild cards not working if blocks have different characters among *REV.* and *OPTION.*

 

Would be awesome if it will work like: - > (lisp...) - > type: *REV.A* rename to *REV.B*, and *OPTION.1* to *OPTION.2* for all blocks in the set.

 

P.S. all blocks has same naming structure: "A-B-rev.A-<name>-option.1-<date>" 

<name> - Table 1 , or Table 34, ...(stays unchanged)

<date> - 2011, or 2013 ... (stays unchanged)

*Expert Elite*
Kent1Cooper
Posts: 5,242
Registered: ‎09-13-2004
Message 5 of 18 (815 Views)

Re: Batch Rename Blocks - HELP please, Thank you.

02-22-2013 01:32 PM in reply to: abrusil33

A few questions:

 

Would you always want to change both the REV.[letter] and the OPTION.[number] in every Block name?  Or might you at least sometimes want to change only one or the other?

 

Would something that automatically just increases the letter and the number by one, regardless of their starting values, without User input, be appropriate?  Or would you want the User to specify which letter/number values to change and what to change them to [for instance, if you might sometimes want to change from, say, A to C instead of to B]?

Kent Cooper
*Expert Elite*
pbejse
Posts: 2,406
Registered: ‎11-24-2009
Message 6 of 18 (800 Views)

Re: Batch Rename Blocks - HELP please, Thank you.

02-22-2013 09:19 PM in reply to: abrusil33

Same question as Kent 

 

Active Contributor
abrusil33
Posts: 26
Registered: ‎01-31-2003
Message 7 of 18 (794 Views)

Re: Batch Rename Blocks - HELP please, Thank you.

02-22-2013 11:13 PM in reply to: Kent1Cooper

The program "All File Renamer" http://www.altarsoft.com/all_file_renamer.shtml

will rename the portion of any name in all files in this format:

 

Find: REV.1

Replace with: REV.2

 

But this program is for windows explorer only.

If there is a LISP that will run Find and Replace in the Block names, that would be awesome.

 

Any Ideas?

Thanx

*Expert Elite*
pbejse
Posts: 2,406
Registered: ‎11-24-2009
Message 8 of 18 (787 Views)

Re: Batch Rename Blocks - HELP please, Thank you.

02-23-2013 12:28 AM in reply to: abrusil33

abrusil33 wrote:

 

Any Ideas?

Thanx


Ideas Yes, Need more info though, answer the question at Kent Coopers post, We do not  blindly write a program without knowing all the details. (sometimes we do :smileyhappy: )

 

 

*Expert Elite*
pbejse
Posts: 2,406
Registered: ‎11-24-2009
Message 9 of 18 (771 Views)

Re: Batch Rename Blocks - HELP please, Thank you.

02-23-2013 06:35 AM in reply to: pbejse

Find and replace approach

 

(defun C:BNM- (/ blist bl b find replace FindList Replacelist  NewName)
(defun _match (b l)
       (vl-every '(lambda (k)
          (wcmatch (strcase b) (strcat "*" k "*")))  l
                                        )
  )
  (setq blist '()
        bl nil
  FindList nil
  Replacelist nil)
  (while  (and
		  (setq find (Strcase (getstring "\nString to Find/Press Enter for none: ")))
		  (not (eq "" find))
		  (setq FindList (cons find FindList))
		  (setq replace (Strcase (getstring (strcat "\nReplace " find " with: "))))
		  (not (eq "" replace))
		  (setq replaceList (cons replace replaceList))
		  	)
		  )
  (and
  FindList
  (while (setq bl (tblnext "block" (not bl)))
    (and (zerop (logand 53 (cdr (assoc 70 bl))))
	 (_match (setq bl (cdr (assoc 2 bl))) FindList)
         (or (member bl blist) (setq blist (cons bl blist)))
    )
  )
  blist
  (foreach itm blist
    (setq Newname itm)
    (mapcar '(lambda (x y / p)
	(setq p (vl-string-search x (strcase itm))
    	      Newname	(strcat (strcat (substr Newname 1 p) y 
    			(substr Newname (+ p (strlen x) 1))))))
	   findlist Replacelist)
    (command "_rename" "_b" itm NewName)
  )
  )
  (print (length blist))(princ " Blocks Renamed")
  (princ)
)

 

This demo will look for REV.A and OPTION.1

 

"A-B-REV.A-Table 2-OPTION.1-2011" 

"A-B-REV.A-Table 3-OPTION.1-2012" 

"A-B-REV.B-Table 4-OPTION.3-2012" 

 

command:BNM-

String to Find/Press Enter for none: Rev.A

Replace REV.C with: Rev.B

String to Find/Press Enter for none: option.1

Replace OPTION.1 with: Option.2

 

now if and only if these two items are found on the block name

("OPTION.1" "REV.A")

Only then it will renamed the block with this new values

("OPTION.2" "REV.B") 

 

2  Blocks Renamed

 

"A-B-REV.B-Table 2-OPTION.2-2011" 

"A-B-REV.B-Table 3-OPTION.2-2012"

"A-B-REV.B-Table 4-OPTION.3-2012" 

 

Now if you only need to find 1 "string match" on the block name, This will look for REV.B regardless of option number

 

command:BNM-

String to Find/Press Enter for none: Rev.B

Replace REV.C with: Rev.C

String to Find/Press Enter for none:

 

3  Blocks Renamed

 

"A-B-REV.C-Table 2-OPTION.2-2011" 

"A-B-REV.C-Table 3-OPTION.2-2012"

"A-B-REV.C-Table 4-OPTION.3-2012" 

 

Another one would be a "Bump" to next value. without prompting for "replace with" 

 

HTH

Active Contributor
abrusil33
Posts: 26
Registered: ‎01-31-2003
Message 10 of 18 (752 Views)

Re: Batch Rename Blocks - HELP please, Thank you.

02-23-2013 10:40 PM in reply to: pbejse

THAT IS BRILLIANT. 100% PURE WHAT I NEEDED.


Thank you "pbejse" you are a quiet Expert Elite ++

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community