Jump to content

Creating a Lisp Routine for Custom MText Input


Recommended Posts

Posted

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!

Screen MText lisp.png

Posted (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 by GLAVCVS
Posted

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)
  )

 

Posted

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!😋

Posted (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 by pkenewell
  • Agree 1
Posted

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)))

 

Posted
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.

Posted

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!

  • Like 1
Posted
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".🍻

  • Like 1

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...