Nikon Posted December 13, 2023 Author Posted December 13, 2023 (edited) Yes! It works for text and мtext!!! Thank you very much, EnM4st3r! (defun c:pp(/ el nr str) (setq el (entget (car (entsel "pick (m)text"))) nr (itoa (getint "enter number")) ) (cond ((wcmatch (cdr (assoc 0 el)) "MTEXT") (setq str (strcat "{\\L" nr " - " nr "}")) ) ((wcmatch (cdr (assoc 0 el)) "TEXT") (setq str (strcat "%%u" nr " - " nr)) ) (t (alert "thats no text obj") (exit) ) ) (entmod (subst (cons 1 str) (assoc 1 el) el)) ) Edited December 13, 2023 by Nikon Quote
Steven P Posted December 13, 2023 Posted December 13, 2023 (edited) 38 minutes ago, EnM4st3r said: @Steven P i think yours was not working since he is using spaces in between the numbers That's a easy fix, ta. (defun c:test ( / MyEnt MyEntGet MyTExt MyStart OldNumber NewNumber NewText) (vl-load-com) (setq MyEnt (car (entsel "\nSelect Text"))) (while ;; while loop, checking that text was selected (and (/= (cdr (assoc 0 (entget MyEnt))) "TEXT") (/= (cdr (assoc 0 (entget MyEnt))) "MTEXT") ) (princ "\nWell, that isn't text is it now? ") (setq MyEnt (car (entsel "Please select Text"))) ) (setq MyEntGet (entget MyEnt)) ; get text entity definition (setq MyText (cdr (assoc 1 MyEntGet))) ; get text string (setq MyStart (vl-string-search "-" MyText)) ; look for first instance of "-" in text string. Error check it exists? (setq NewNumber (getstring "\nEnter New Number : " t)) ; ask for replacement number, t to allow for spaces in text (if (wcmatch MyText "*#`-#*") (setq OldNumber (substr MyText (- MyStart 0) 3))) ; for 0-0 to 9-9 (if (wcmatch MyText "*##`-##*") (setq OldNumber (substr MyText (- MyStart 1) 5))) ; for 10-10 to 99-99 (if (wcmatch MyText "*###`-###*") (setq OldNumber (substr MyText (- MyStart 2) 7))) ; for 100-100 to 999-999 (if (wcmatch MyText "*# `- #*") (setq OldNumber (substr MyText (- MyStart 1) 5))) ; for 0-0 to 9-9 (if (wcmatch MyText "*## `- ##*") (setq OldNumber (substr MyText (- MyStart 2) 7))) ; for 10-10 to 99-99 (if (wcmatch MyText "*### `- ###*") (setq OldNumber (substr MyText (- MyStart 3) 9))) ; for 100-100 to 999-999 (if (= OldNumber nil) ; if text contained a valid format, update text (princ "Text string does not contain 'xx-xx' format text. Going for a nap now.") (progn (if (wcmatch MyText "*#`-#*") (setq NewText (vl-string-subst (strcat NewNumber "-" NewNumber) OldNumber MyText)) ; substitute new text in (setq NewText (vl-string-subst (strcat NewNumber " - " NewNumber) OldNumber MyText)) ; substitute new text in ) (vla-put-TextString (vlax-ename->vla-object MyEnt) Newtext) ) ) (princ) ; exit quietly ) Edited December 13, 2023 by Steven P 1 Quote
EnM4st3r Posted December 13, 2023 Posted December 13, 2023 so @Nikon the diffrence between Stevens code and the other, is that Stevens code looks for the part with x-x within the text and replaces only that part. The other code replaces everything inside the text obj Quote
Steven P Posted December 13, 2023 Posted December 13, 2023 Benefit for that way is it retains any other formatting in the text string, (such as mtext colour over rides (except in the required text portion), italics, and so on) and can be used to replace the text if it is in a larger text block 1 Quote
Nikon Posted December 13, 2023 Author Posted December 13, 2023 (edited) see the last post Edited December 13, 2023 by Nikon Quote
Nikon Posted December 13, 2023 Author Posted December 13, 2023 2 hours ago, Steven P said: Это легко исправить, ta. (defun c:test ( / MyEnt MyEntGet myText, MyStart oldNumber, NewNumber, newText) (vl-load-com) (setq MyEnt (car (entsel "\nSelect Text"))) (while ;; цикл while, проверяющий, был ли выделен текст (и (/= (cdr (assoc 0 (entget MyEnt))) "ТЕКСТ") (/= (cdr (assoc 0 (entget MyEnt))) "MTEXT") ) (принц "\ N Ну, это ведь не текст, не так ли? ") (setq MyEnt (car (укажите "Пожалуйста, выберите текст"))) ) (setq MyEntGet (entget MyEnt)) ; получить определение текстовой сущности (setq myText (cdr (assoc 1 MyEntGet))) ; получить текстовую строку (setq MyStart (vl-string-search "-" myText)) ; найдите первый экземпляр "-" в текстовой строке. Проверьте, существует ли ошибка? (setq NewNumber (getstring "\nEnter New Number : " t)) ; запросите номер замены, t, чтобы разрешить пробелы в тексте (если (wcmatch myText "*#`-#*") ( установите старый номер (substr myText (- MyStart 0) 3))) ; от 0-0 до 9-9 (если (wcmatch myText "*##`-##*") ( установите старый номер (substr myText (- MyStart 1) 5))) ; от 10-10 до 99-99 (если (wcmatch myText "*###`-###*") ( установите старый номер (substr myText (- MyStart 2) 7))) ; от 100-100 до 999-999 (если (wcmatch myText "*# `- #*") ( установите старый номер (substr myText (- MyStart 1) 5))) ; от 0-0 до 9-9 (если (wcmatch myText "*## `- ##*") ( установите старый номер (substr myText (- MyStart 2) 7))) ; от 10-10 до 99-99 (если (wcmatch myText "*### `- ###*") ( установите старый номер (substr myText (- MyStart 3) 9))) ; от 100-100 до 999-999 (if (= oldNumber nil) ; если текст содержит допустимый формат, обновите текст (принц "Текстовая строка не содержит текст в формате 'xx-xx'. Сейчас пойду вздремну.") (progn (if (wcmatch myText "*#`-#*") (setq newText (vl-string-subst (strcat NewNumber "-" Новый номер) oldNumber myText)) ; замените новый текст в (setq newText (vl-string-subst (strcat NewNumber " - " Новый номер) Старый номер myText)) ; замените новый текст в ) (vla-put-TextString (vlax-ename-> vla-object MyEnt) Новый текст) ) ) (принцип) ; тихо завершите работу ) (если (wcmatch myText "*# `- #*") ( установите старый номер (substr myText (- MyStart 1) 5))) ; от 0-0 до 9-9 (если (wcmatch myText "*## `- ##*") ( установите старый номер (substr myText (- MyStart 2) 7))) ; от 10-10 до 99-99 (если (wcmatch myText "*### `- ###*") ( установите старый номер (substr myText (- MyStart 3) 9))) ; от 100-100 до 999-999 (if (= oldNumber nil) ; если текст содержит допустимый формат, обновите текст (принц "Текстовая строка не содержит текст в формате 'xx-xx'. Сейчас пойду вздремну.") (progn (if (wcmatch myText "*#`-#*") (setq newText (vl-string-subst (strcat NewNumber "-" Новый номер) oldNumber myText)) ; замените новый текст в (setq newText (vl-string-subst (strcat NewNumber " - " Новый номер) Старый номер myText)) ; замените новый текст в ) (vla-put-TextString (vlax-ename-> vla-object MyEnt) Новый текст) ) ) (принцип) ; тихо завершите работу ) Steven P, thank you. Your code is very complex, but it works well for my simple task... Quote
Nikon Posted December 13, 2023 Author Posted December 13, 2023 (edited) Is it difficult to make such an option: first write the number 1 (for example), the specify the insertion point and get the underlined text 1-1? Edited December 13, 2023 by Nikon Quote
EnM4st3r Posted December 13, 2023 Posted December 13, 2023 1 hour ago, Nikon said: Is it difficult to make such an option: first write the number 1 (for example), the specify the insertion point and get the underlined text 1-1? like this? (defun c:pp2 (/ nr str ip) (setq nr (itoa (getint "\nEnter number: ")) str (strcat "{\\L" nr " - " nr "}") ip (vlax-3d-point (getpoint "\nPick Insertion Point: ")) ) (vla-addmtext (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) ip 0 str) (princ) ) 1 Quote
Nikon Posted December 13, 2023 Author Posted December 13, 2023 I like it! Thank you very much, EnM4st3r ! Bravo! Thanks for the quick reaction! Quote
Steven P Posted December 13, 2023 Posted December 13, 2023 39 minutes ago, Nikon said: Steven P, thank you. Your code is very complex, but it works well for my simple task... No problem, sometimes a few extra minutes to make something a little more versatile is worth it (and of course, sometimes it isn't). As above for Nikon, adding new text is often simpler than modifying existing text Quote
EnM4st3r Posted December 13, 2023 Posted December 13, 2023 @Nikon you can also add a while loop so you can continue the placement. Dont know if that would be useful: (defun c:pp2 (/ nr str ip) (setq nr (itoa (getint "\nEnter number: ")) str (strcat "{\\L" nr " - " nr "}") ) (while (setq ip (vlax-3d-point (getpoint "\nPick Insertion Point: "))) (vla-addmtext (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) ip 0 str) ) (princ) ) 1 Quote
Nikon Posted December 13, 2023 Author Posted December 13, 2023 (edited) 18 minutes ago, EnM4st3r said: @Nikon you can also add a while loop so you can continue the placement. Dont know if that would be useful: (defun c:pp2 (/ nr str ip) (setq nr (itoa (getint "\nEnter number: ")) str (strcat "{\\L" nr " - " nr "}") ) (while (setq ip (vlax-3d-point (getpoint "\nPick Insertion Point: "))) (vla-addmtext (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) ip 0 str) ) (princ) ) This is also useful, many thanks ... Edited December 13, 2023 by Nikon Quote
ronjonp Posted December 13, 2023 Posted December 13, 2023 3 hours ago, EnM4st3r said: @Nikon you can also add a while loop so you can continue the placement. Dont know if that would be useful: (defun c:pp2 (/ nr str ip) (setq nr (itoa (getint "\nEnter number: ")) str (strcat "{\\L" nr " - " nr "}") ) (while (setq ip (vlax-3d-point (getpoint "\nPick Insertion Point: "))) (vla-addmtext (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) ip 0 str) ) (princ) ) FWIW, You should move the vlax-3d-point into the loop so it does not error out. (defun c:pp2 (/ nr str ip) (setq nr (itoa (getint "\nEnter number: ")) str (strcat "{\\L" nr " - " nr "}") ) (while (setq ip (getpoint "\nPick Insertion Point: ")) (vla-addmtext (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) (vlax-3d-point ip) 0 str ) ) (princ) ) 1 1 Quote
Nikon Posted December 14, 2023 Author Posted December 14, 2023 (edited) ronjonp, thank you. Your code does not give an error. Edited December 14, 2023 by Nikon Quote
Nikon Posted December 14, 2023 Author Posted December 14, 2023 EnM4st3r, Please teach me how you create usernames. Quote
EnM4st3r Posted December 14, 2023 Posted December 14, 2023 58 minutes ago, Nikon said: EnM4st3r, Please teach me how you create usernames. you just have to type @ and then the username after that. A selection will pup up automatically @Nikon Quote
Nikon Posted December 14, 2023 Author Posted December 14, 2023 (edited) @EnM4st3r Nothing came of it... @EnM4st3r You need to start writing, and then select from the drop-down list Edited December 14, 2023 by Nikon 1 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.