PabloS Posted December 11, 2023 Posted December 11, 2023 Hello: Hope you are all doing fine and thanks for taking time to read my post. I'm strugling to make an automatic text replacement. I currently have many text with rebar quantity and separation like this: ∅10 c/15 (26) and I would like to replace distance and recalculate quantity. for example ∅10 c/20 (19). As you may notice, the number between parenthesis is the quantity of rebars and c/XX represents distance between rebars in cm. Can you help me making a lisp routine to change this selecting texts by window and indicating new separation in cm through command line after selection? Greetings, Pablo Quote
PabloS Posted December 11, 2023 Author Posted December 11, 2023 Bigal: Thanks for taking time to answer my question. Obviously, I know the command find, the problem is sometimes I have thousands of texts and each and every single text have different numbers inside the parentheses. So I need to replace every single text computing the new quantity of bars (the number between parentheses) based on the new rebar distance which is proportional to the previous one. Changing the distance, which is represented by “c/xx” is simple using the find command, but new quantity must be calculated from every number to write the new value which is proportional to the original one. Regards, Pablo Quote
PabloS Posted December 11, 2023 Author Posted December 11, 2023 For example: I have the following, meaning I have 25 rebars with 10 mm diameter with a 15 cm separation: ∅10 c/15 (25) Now I want to change the text to match a new separation of 20 cm and recompute the rebar quantity to rewrite text as: ∅10 c/20 (18) As you see quantity must be rounded down. This must be done for all selected texts matching original separation 15 cm Hope this helps understanding the problem. Thanks, Pablo Quote
fuccaro Posted December 12, 2023 Posted December 12, 2023 Here is a quick one. Waiting for feedback. (defun c:pp() (setq ss (ssget "i") i (sslength ss)) (setq new (getint "enter new separation ...")) (repeat i (setq en (ssname ss (setq i (1- i))) el (entget en)) (setq tx (cdr (assoc 1 el))) (setq n1 (+ 2 (vl-string-search "/" tx 2)) tx1 (read (substr tx n1)) n2 (+ 2 (vl-string-search "(" tx n1)) tx2 (read (substr tx n2))) (setq tx (strcat (substr tx 1 (1- n1)) (itoa new) " (" (itoa (/ (* tx1 tx2) new)) ")")) (entmod (subst (cons 1 tx) (assoc 1 el) el)) ) ) Select the texts to be changed before you run the lisp... Quote
fuccaro Posted December 12, 2023 Posted December 12, 2023 Oh, and... Welcome in the forum, PabloS! 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.