Halsy Posted February 1 Posted February 1 Hello All, I need lisp, which will replace Width X length text to Length X width text i.g 600 X 1200 to 1200 X 600 800 X 2400 to 2400 X 800 Quote
Steven P Posted February 1 Posted February 1 (edited) Are all the texts the same format, with [space]x[space] between the 2 dimensions? Have a look at Lee Macs string to List routine and use " X " as the deliminator, then use his list to string and use the same deliminator. If you are OK to modify a LISP, my first routine here does most of this - just change the deliminator I think Edited February 1 by Steven P Quote
fuccaro Posted February 1 Posted February 1 (defun c:pp() (setq ss (ssget '((0 . "TEXT")))) (repeat (setq i (sslength ss)) (setq el (entget (ssname ss (setq i (1- i)))) txt1 (cdr (assoc 1 el))) (setq posX (vl-string-search " X " txt1) txt2 (strcat (substr txt1 (+ posX 3)) " X " (substr txt1 1 posX))) (setq el (subst (cons 1 txt2) (assoc 1 el) el)) (entmod el) ) ) Does this work for you? You can select all the texts to be changed and process them in one run. 1 Quote
Halsy Posted February 1 Author Posted February 1 (edited) When X = code which is vary string by string then above @fuccaro code is not working i.e 600 D 2450 , 500 B1 400, 300 B3 400 Edited February 1 by Halsy Quote
Steven P Posted February 1 Posted February 1 (edited) Does the 'X' change? So in your example D, B1, B3 ? and is there always a space either side of that? LISPs work really well if there is a rule that you can apply but got to work out the rule, and need all the information. Fuccaro works according to your first post with an 'X' in the middle. For Fuccaros code to work well for every circumstance we'll need to know whatever is in between the numbers for every instance. Edited February 1 by Steven P 1 Quote
Steven P Posted February 1 Posted February 1 (edited) Modified my link above to give: (defun c:RevHW ( / MySS SSCountMyEnt MyEntGet Mytext TextList OrderList NewText n acount) ; Reverse Height Width ;;Sub Functions: ;;Starting with LM: Refer to Lee Macs website (defun LM:str->lst ( str del / pos ) (if (setq pos (vl-string-search del str)) (cons (substr str 1 pos) (LM:str->lst (substr str (+ pos 1 (strlen del))) del)) (list str) ) ) (defun LM:lst->str ( lst del ) (if (cdr lst) (strcat (car lst) del (LM:lst->str (cdr lst) del)) (car lst) ) ) (princ "\nSelect MText") ;; Note in command line "Select text" (setq MySS (ssget '((0 . "TEXT")))) ;; Select objects with a selection set, filtered to 'MTEXT' entity type (setq SSCount 0) ;; Just a counter set to 0 (while (< SSCount (sslength MySS)) ;; loop through length or selection set using SSCount (setq MyEnt (ssname MySS SSCount)) ;; get the nth item in the selection set entity name (setq MyEntGet (entget MyEnt)) ;; get the entity definition from the above (setq MyText (cdr (assoc 1 MyEntGet))) ;; get the text from the entity (first 256 characters) (setq TextList (LM:str->lst MyText " "));; Convert the text string to a list, deliminator " " (setq MyEntGet (subst (cons 1 (LM:lst->str (reverse TextList) " ")) (assoc 1 MyEntGet) MyEntGet)) (entmod MyEntGet) ;; Modify the text (setq SSCount (+ SSCount 1)) ) ; end while ); end function Edited February 1 by Steven P Quote
Halsy Posted February 1 Author Posted February 1 Yes X changes in each string just like above metion examples and space either side of X i.e 400 B1 500 to 500 B1 400 600 D3 900 to 900 D2 600 Quote
Steven P Posted February 1 Posted February 1 Only D, B1, B3, D2 and D3 ? (from your examples?) Or is it any text Quote
ronjonp Posted February 1 Posted February 1 @Steven P You could modify your selection set filter like so to weed out bad items (setq myss (ssget '((0 . "TEXT") (1 . "*# ?? #*")))) 1 Quote
BIGAL Posted February 2 Posted February 2 A question not asked, do you want always longer length first so 1200 x 600 does not change. 1 Quote
fuccaro Posted February 2 Posted February 2 Halsy is happy with Steven's Lisp, so I came returned too late to this party. Anyway, here is my version. It is pretty close to my previously posted program but now it searches for the sequence "space-something-space". Also I extended it a bit to process Mtexts as well. Here it is: (defun c:pp() (setq ss (ssget '((0 . "*TEXT")))) (repeat (setq i (sslength ss)) (setq el (entget (ssname ss (setq i (1- i)))) txt1 (cdr (assoc 1 el)) pos1 (1+ (vl-string-search " " txt1 1)) pos2 (1+ (vl-string-search " " txt1 (1+ pos1))) pos3 (strlen txt1) txt2 (strcat (substr txt1 (+ pos2 1)) (substr txt1 pos1 (- pos2 pos1 -1)) (substr txt1 1 pos1)) el (subst (cons 1 txt2) (assoc 1 el) el) el (entmod el)) ) ) 1 Quote
Halsy Posted February 3 Author Posted February 3 @fuccaro thank you sir your code also work fine Quote
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.