SRXTEXT - search/replace with regular expressions (C)2011, CAD Studio a.s. http://www.cadstudio.cz -------------------------------------------------------- SRXTEXT is a LISP utility for AutoCAD 2000/i, 2002-2012, which can search and/or replace drawing texts (TEXT, MTEXT, DIMTEXT, ATTRIB, ATTDEF). You can choose from exact string match, substring match/replace or regular expressions. For the regular expression functionality, AutoCAD Express Tools are required (part of AutoCAD installation). You can search (and replace) the whole drawing, any specified layer or selected objects. SRXTEXT zooms to any matching text and offers to Replace, Autoreplace (Don't ask), Skip to next or Exit the search/replace loop. SRXTEXT contains three commands - SRXTEXT, SRXTEXTCSV and SRXMISSING. The "CSV" version loads the search-replace string pairs from a .CSV text file so you can predefine complex replacements e.g. in Excel. The .CSV file is in format: "whattofind1","whattoreplace1" "whattofind2","whattoreplace2" (sample file included) Since version 1.5 the quotes are optional and the delimiter can be "," or ";". The CSV version is in Trial mode only (first 2 pairs are processed). Use CADSTUDIOREG to authorize it. SRXMISING is a special command which can identify texts (numbers) missing from a given numeric interval. If you should have e.g. doors numbered 1-100, it can find the door with forgotten number in a series. Regular expressions: -------------------- Using regular expressions you can perform complex replacements like changing: D19-457-03667 to Part:457/03667 Code:D19 For this case you would use the search and replace strings: \([A-Z][0-9][0-9]\)\-\(...\)\-\(.*\) Part:\2/\3 Code:\1 Or you can append strings to the beginning of your texts: ^\(.\) newprefix\1 or to the end of your texts: \(.\)$ \1newsuffix Or you can replace just the first occurrence of a substring in text: search: \(.\)oldtext\(.\) replace: \1newtext\2 Another example of complex replacements: KWD-5-3, KW-4-2, KWP-1-5 to KCD-5-1, KC-4-1, KCP-1-1 search: \(.\)W\(.*\)\-\(.\)\-\(.\) replace: \1C\2-\3-1 Cutting the number of decimal places to 1: search: \([0-9]*\)\.\([0-9]\)[0-9]* replace: \1.\2 Adding a thousands separator (",") to numbers. search: -?\([0-9]+\)\([0-9][0-9][0-9]\) replace: \1,\2 (repeat it for milion/bilion/... triplets) Delete all text after the first period in text: search: ^\([^\.]*\)\..* replace: \1. Replace trailing "A"s with "B"s: search: \(.\)A$ replace \1B Delete color control codes in MTexts: search: \(.\)\{\\C[0-9]+;\(.\) replace: \1\2 Add prefix to all selected texts: search: \(.*\) replace: myprefix\1 Adding trailing text to texts not containing "*": search: ^\([^\*]+\)$ replace: \1 NewTrailingText Erasing the first character in the text: search: ^.\(.*\) replace: \1 Reaplacing hard returns with soft returns in MText: search: \\P replace: (single space character) Use replacement in scripts: --------------------------- You can use ScriptPro or other script processor to perform batch replacements on multiple DWG files. The script could look like e.g.: (load "srxtext.vlx") srxtext s oldtext newtext all all d - or just - (load "srxtext.vlx") (srxtext "Substring" "oldtext" "newtext" "All") Tip 1: MTEXT objects can contain hidden control character codes, so they may appear to not meet the exact matches (btw, you can use SRXTEXT to remove these control characters) Tip 2: You can use srxText to add, modify or delete control characters in MText texts - changing the string height, color, font, width, etc. E.g. {\T2.0;XXX} Tip 3: set _SRXTEXTNOZOOM to T (true) to disable running zooms: (setq _SRXTEXTNOZOOM T) set _srxTEXTCSVen to T (true) to use old "comma only" separators when processing CSV files Tip 4: SRXTEXTCSV honors the FILEDIA setting so you can enter the .CSV file name on the commandline (e.g. in batch scripts) with FILEDIA=0 Tip 5: If you need to enter regular expression strings in menu macros, you cannot use backslashes, use (chr 92) instead. E.g. the LISP version of srxtext (replace "\\"->"|"): (srxtext "Regular" (strcat(chr 92)(chr 92)) "|" "All") You cannot replace strings in text generated by Fields. Character case must match exactly (case-sensitive). Since version 1.1 you can replace MTexts longer than 256 characters. Since version 1.4 you can enter the searched text by picking en existing text entity. SRXTEXT contains also a LISP interface so you can use the srxText functionality in our LISP routines: (srxTEXT "" "" "" "") can be Substring or Regular or Exact (case sensitive) is the searched string is the replacement string can be "All", or a name of an existing layer, or "Select" to select objects interactively, or a selection set variable with selected objects returned value is the number of replacements done Examples: (srxTEXT "Substring" "Ford T1" "Ford Galaxy" "All") (srxTEXT "Exact" "Autocad" "AutoCAD" myselectionset) License: SRXTEXT is a free/trial utility by CAD Studio, do not publish it online on other than CADstudio's web servers, do not sell, lend or exchange it. ---------------------------------------------------- Contact: CAD Studio a.s. Tylova 17, 370 01 Ceske Budejovice, Czech Republic info@cadstudio.cz www.cadstudio.cz www.cadforum.cz