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:
and I need to revise 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)
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]?
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
@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 🙂 )
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
I can modify code to run: BNM- once if I need to, but normally I have to make sure if both revisions are current, so extra reminder won't hurt.
You guys are genious e s!
@abrusil33 wrote:I can modify code to run: BNM- once if I need to, but normally I have to make sure if both revisions are current, so extra reminder won't hurt.
Good for you, Holler if you need more help.
Guys,
Just figured out that this routine would not work if only 3D blocks in the drawing.
I have to make at least one 2D block within the drawing, and then it will do the rename, as long as I remove 2D block and purge, it is not renaming. I know it easy for you to fix, but not for me at this time...Thanx
I am attaching the file as an example that routine would not work as long as associative dimension is in there.
@abrusil33 wrote:I am attaching the file as an example that routine would not work as long as associative dimension is in there.
My bad abrusil33, error in blist evaluation, nothing to do with associative dimension.
(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)) ) ) (if (and FindList (progn (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) )
HTH
@abrusil33 wrote:Thanks, works like a charm... !!!!
I appresiate your work, Patrik.
Glad it works for you abrusil33
Cheers
Hi there,
I created OpenDCL form with text input for old rev and new rev
I changed in your routine:
(setq find (Strcase (strcat "rev" "." revN))) ;;(revN - is a text input from the form - old revision)
(setq replace (Strcase (strcat "rev" "." revNto))) ;;(revNto - is a text input for new rev. number)
I think option (while (and .... will not work here, I mean it is not working and I am stuck.. I am trying to make the form that will Rev up all the blocks in the drawing by taking two new inputs (1 - for number revision 2- for letter revision)
Thanx (I spent all my weekend time to figure it out and am afraid I won't ble to fix it on my own)
++++++++
(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)
)
@YankeeSteve wrote:
(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)
)
this worked wonders for me - is there a way to modify it to do the same for layer names?
....never mind, ran stuck, but then saw my mistake and got it to work. Thanks for starting me out in the right direction!
(defun C:LN- ( / blist bl b n)
(setq blist '() bl nil b 0 n "LAYER")
(while (setq bl (tblnext "layer" (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" "_la" (car blist)
(strcat n (if (< b 10) "0" "") (itoa b)))
(setq blist (cdr blist))
)
(princ)
)