TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: JohnCamper on May 13, 2021, 12:24:06 PM
-
I have thousands of Texts on CAD.I made a mistake and forgot to divide the Texts with specific number(i.e. 3.2 to be precise).
For eg: I have 50m in CAD as text and i want to divide it with 3.2 and replace that 50m with ≈16m (rounded up).
I searched the whole internet & the forums for the lisp or any other solution but i could not find anything that I could work upon as a reference or a foundation. Could anyone help me with it ?
-
Well you can use qselect, select the text, and in contents put the string you are looking for and then in properties replace the contents for what you want.
Or also use this code.
;;; Divides and replaces a text
;;; By Isaac A. 20210513
;;; http://www.theswamp.org/index.php?action=post;topic=56742.0;last_msg=604663
(defun c:d&r (/ div i ss srch srch1 str)
(setq srch (getstring T "\nType the text to divide and replace: ")
div (getreal "\nType the divisor: ")
srch1 (atof srch)
rplc (strcat (rtos (/ srch1 div) 2 0) "m")
)
(if (setq ss (ssget "_X" (list (cons 0 "*TEXT") (cons 1 (strcat "*" srch "*"))
(cons 410 (getvar 'ctab)))))
(progn
(setq i -1)
(repeat (sslength ss)
(setq i (1+ i))
(setq enam (entget (ssname ss i)))
(entmod (subst (cons 1 rplc) (cons 1 srch) enam))
)
)
)
(princ)
)
-
Thanks for the reply !
Your solution partly works Sir, bcoz it works as search & replace. But in this case it is tedious to search the individual texts and replace as there are thousands of texts.So how can it me made such that it :-Divides all the Selected texts with divisor at once.
ie 1st step : To select all the required texts (manually).
2nd step: Ask for a divisor and replace all the selected texts with their respective divided results.
-
Have you tried the lisp?
-
Yes sir, I did ! It asks for the text to divide and replace.
Pic for reference
-
Ok, so I missunderstood before and This is what you want.
;;; Divides texts by 3.2 and replaces the texts
;;; By Isaac A. 20210513
;;; http://www.theswamp.org/index.php?action=post;topic=56742.0;last_msg=604663
(defun c:d&r (/ div enam i rplc ss srch srch1 str)
(if (setq ss (ssget "_X" (list (cons 0 "*TEXT") (cons 1 (strcat "*" "m"))
(cons 410 (getvar 'ctab)))))
(progn
(setq i -1)
(repeat (sslength ss)
(setq i (1+ i))
(setq enam (entget (ssname ss i))
srch (cdr (assoc 1 enam))
srch1 (atof srch)
rplc (strcat (rtos (/ srch1 3.2) 2 0) "m")
)
(entmod (subst (cons 1 rplc) (cons 1 srch) enam))
)
)
)
(princ)
)
-
Wow !! Exactly what i wanted. Thank you so much, sir ! Saved me a ton of time.:smitten: If there was a selection option of texts on the code of which i wanted to divide, it would be even better .
-
Here's something else you can try as well.
-
Welcome to TheSwamp, zak26.
-
Thanks John Kaul
-
It may be worthwhile adding an option pick a text and get the layer name as the ssget "X" gets all text also maybe a (410 . "Model"), these can be added pretty easy into the ssget. Can also use variables extmin extmax to pick window so no need for user to pick an area.
(if (setq ss (ssget "_X" (list (cons 0 "*TEXT") (cons 1 "*m")(cons 8 lay)(cons 410 "Model"))))
-
Valid points BigAl, but the user wanted everything in just a click or a command call, and I don't know if there were many or just one layer, but thanks, is something to consider.
P.S. I didn't know that I could use "*m" instead of (strcat "*" "m") There still too much that I have to learn. And also I'd like you to give me some opinions on my programs but those are to sell, so can I send you emails?
-
The single click would be pick a text hence get layer.
Perhaps describe what your other lisps are, there is so much free stuff out there and selling is almost impossible.
-
Well maybe you're right, and besides I'm not discovering the wheel, but I'll keep posting and asking for advice and solutions for my programs when I can't find myself a solution. Thank you.
-
Did you look at the doc file ? Its a fraction of what I have 40 years at it.
-
Didn't until now that you posted the comment, I don't get used to Theswamp way of showing posts, that doesn't show the pics and the attachment's if you're not logged.
It's impressive your work, and I'm glad and want to thank you for sharing your knowledge with us. You have helped me a lot, (more in CadTutor) but thanks.