Tarz4n Posted January 28 Posted January 28 Hi everyone, I would like to create a Lisp routine to format various inputs into a single MText. The idea is that the routine should first ask three questions: "Enter text 1" "Enter text 2" "Enter text 3" These three inputs will form constant parts of the MText. Afterward, a fourth question will prompt: "Enter the number." Once the number is entered, the user can click anywhere in the drawing, and the MText will appear as shown in the attached image. The goal is to allow continuous input of new numbers, enabling the placement of new MTexts with each the entered number. If it is possible to let this MText always appear in a specific layer with a box around it in the same layer, then it would be perfect. Thanks in advance for your help! Quote
GLAVCVS Posted January 28 Posted January 28 (edited) All of that is done by the 'mtext' command. You don't need to write a lisp to ask for 3 texts and 1 number. That's more inefficient than using the 'mtext' command itself which allows you to put it all in one go As for the bounding box, take a look at Edited January 28 by GLAVCVS Quote
LanloyLisp Posted January 28 Posted January 28 For Tarz4n to be happy, here's a quick one. (defun c:Tarz4ntext (/ num pt str1 str2 str3) (if (and (setq str1 (getstring "\nEnter text 1:" T)) (setq str2 (getstring "\nEnter text 2:" T)) (setq str3 (getstring "\nEnter text 3:" T)) ) (while (setq num (getint "\nEnter the number: ")) (setq pt (getpoint "\nSpecify position of MText: ")) (entmakex (list (cons 0 "MTEXT") (cons 100 "AcDbEntity") (cons 100 "AcDbMText") (cons 10 pt) (cons 1 (strcat str1 " " str2 " " str3 " ,nr." (itoa num))) (cons 90 16) (cons 63 256) (cons 45 1.1) (cons 441 0) ) ) ) ) (princ) ) Quote
Tarz4n Posted January 28 Author Posted January 28 That's exactly what I needed! Iβm really grateful for the support. If I may be annoying..., is there a possibility to separate text1 and text 2 from text3 and the number with an "enter"? (like my image in the first post) Then i will be really happy indeed! Quote
pkenewell Posted January 28 Posted January 28 (edited) @Tarz4n Easy. Replace: (cons 1 (strcat str1 " " str2 " " str3 " ,nr." (itoa num))) with: (cons 1 (strcat str1 " " str2 "\\P" str3 " ,nr." (itoa num))) ;; The "\\P" is the MTEXT paragraph return code. NOTE: This forum was not made for free program requests, but for LISP programmers to help beginner LISP programmers to learn. If you are a beginner willing to learn, then Kudos to you. Otherwise - please remember we respond much better to those who rather try something and ask questions rather than just asking for a free program. Edited January 28 by pkenewell 1 Quote
LanloyLisp Posted January 28 Posted January 28 sure Tarz4n, you can edit by your own by simply adding replacing the string " " in between str2 and str1 with "\n". cheers. Quote (cons 1 (strcat str1 " " str2 "\n" str3 " ,nr." (itoa num))) Quote
pkenewell Posted January 28 Posted January 28 On 1/28/2025 at 2:48 PM, LanloyLisp said: sure Tarz4n, you can edit by your own by simply adding replacing the string " " in between str2 and str1 with "\n". cheers. @LanloyLisp Better to use the MTEXT paragraph code "\\P" instead of a string return, although both might work. Quote
Tarz4n Posted January 28 Author Posted January 28 Thank you for your feedback, and I completely understand your point. I want to clarify that Iβm genuinely trying to learn Lisp routines on my own, but Iβm starting completely from scratch, so itβs a bit overwhelming at times. My intention was never to take advantage of the forum but rather to seek guidance from more experienced programmers as I work through the learning process. Iβll make sure to continue trying on my own and come back with specific questions if I get stuck. Thanks again for pointing this out, and I appreciate the time and help from everyone here! 1 Quote
LanloyLisp Posted January 28 Posted January 28 On 1/28/2025 at 2:55 PM, pkenewell said: @LanloyLisp Better to use the MTEXT paragraph code "\\P" instead of a string return, although both might work. I agree to that @pkenewell , It quickly came to my mind to use "\n" instead of "\\P". 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.