Tarz4n Posted Tuesday at 10:06 AM Posted Tuesday at 10:06 AM 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 Tuesday at 10:20 AM Posted Tuesday at 10:20 AM (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 Tuesday at 11:04 AM by GLAVCVS Quote
LanloyLisp Posted Tuesday at 12:00 PM Posted Tuesday at 12:00 PM 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 Tuesday at 12:53 PM Author Posted Tuesday at 12:53 PM 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 Tuesday at 02:46 PM Posted Tuesday at 02:46 PM (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 Tuesday at 02:47 PM by pkenewell 1 Quote
LanloyLisp Posted Tuesday at 02:48 PM Posted Tuesday at 02:48 PM 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 Tuesday at 02:55 PM Posted Tuesday at 02:55 PM 6 minutes ago, 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 Tuesday at 02:59 PM Author Posted Tuesday at 02:59 PM 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 Tuesday at 03:14 PM Posted Tuesday at 03:14 PM 14 minutes ago, 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.