Sambuddy Posted June 18 Share Posted June 18 This is a sample of a *text I have. I am trying to select a bunch of Single and Multiline texts and then change their values from example this 311/312/313/314 to this 311/312/313/314 or from this A10/A11/A16/A18 to this A20/A21/A26/A28. In Summary the ones to twos or threes. What is consistant is the number 1 either in 3(1)1 or A(1)0 or E(1) in a set of numbers that are separated by / that I would like to change to 2s or 3s. Can someone help me either improve what I have so far or get me there please? (defun c:sector ( / ss newValue ent entData text segments newSegments newText ) (prompt "\nSelect Mtext objects to modify: ") (setq ss (ssget '((0 . "MTEXT")))) ; Select Mtext objects (if ss (progn (setq newValue (getint "\nEnter the new middle value (1, 2, or 3): ")) (if (member newValue '(1 2 3)) (progn (setq newValue (itoa newValue)) (repeat (sslength ss) (setq ent (ssname ss (setq count (1- (sslength ss))))) (setq entData (entget ent)) (setq text (cdr (assoc 1 entData))) (if (and text (> (strlen text) 0)) (progn ;; Split the text into segments (setq segments (split-string text "/")) ;; Update each segment (setq newSegments (mapcar (lambda (seg) (if (>= (strlen seg) 3) ;; Replace the middle digit (strcat (substr seg 1 1) newValue (substr seg 3)) seg ) ) segments ) ) ;; Join the segments back together (setq newText (apply 'strcat (mapcar (lambda (s) (strcat s "/")) newSegments))) ;; Remove the trailing "/" (setq newText (substr newText 1 (1- (strlen newText)))) ;; Update the Mtext object (entmod (subst (cons 1 newText) (assoc 1 entData) entData)) (entupd ent) ) (prompt "\nSkipped: Mtext is empty.") ) ) (princ "\nMtext objects updated.") ) (prompt "\nInvalid value. Please enter 1, 2, or 3.") ) ) (prompt "\nNo Mtext objects selected.") ) (princ) ) (defun split-string (str sep / pos start result) (setq result '() start 1) (while (setq pos (vl-string-search sep str start)) (setq result (append result (list (substr str start (- pos start))))) (setq start (+ pos (strlen sep)))) (append result (list (substr str start))) ) Quote Link to comment Share on other sites More sharing options...
mhupp Posted June 19 Share Posted June 19 (edited) getkword will only allow user to input 1 2 or 3 before continuing. Changed the lambda to work with either 3 or 2 string lengths. UMV.lsp Edited June 20 by mhupp Quote Link to comment Share on other sites More sharing options...
Sambuddy Posted June 19 Author Share Posted June 19 10 hours ago, mhupp said: getkword will only allow user to input 1 2 or 3 before continuing. Changed the lambda to work with either 3 or 2 string lengths. UMV.lsp 1.9 kB · 1 download I could not get it to work. it tells me that the Mtexts are updated, but no changes for values. Quote Link to comment Share on other sites More sharing options...
CyberAngel Posted June 20 Share Posted June 20 As usual, Lee Mac is way ahead of us. On this page you'll find a regular expression find/replace. Or you may only need to work the wcmatch command into your code. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted June 21 Share Posted June 21 Over at "Theswamp" is a section called Challenges it is for this type of problem, a generic answer to list manipulation. I have asked there and is a very helpful section. Give it a try. http://www.theswamp.org/index.php?board=77.0 Quote Link to comment Share on other sites More sharing options...
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.