LISP with multiple mtext entries using different textstyles

LISP with multiple mtext entries using different textstyles

evietmeier_1207
Enthusiast Enthusiast
1,725 Views
30 Replies
Message 1 of 31

LISP with multiple mtext entries using different textstyles

evietmeier_1207
Enthusiast
Enthusiast

After some wonderful help from some great people here on some other routines, my survey department saw what was possible, or at least probable, and have asked for a routine of their own. However, I keep getting a malformed error when I try to load the code.

 

(defun c:nf ( / ml_txt)
(setq oldlayer (getvar "clayer"))
(setvar "clayer" "0")
(setq lot (getstring T "\nWhat is the Lot number of this parcel?\n(Only the lot number is needed.)"))
(setq add (getstring T "\nWhat is the street address for this parcel?\n(User entry is not case senstive.)"))
(setq owner (getstring T "\nWho is(are) the current owner(s) of this parcel?\n(User entry is not case senstive.)"))
(setq dbp (getstring T "\nWhat is the current deed book and page for this parcel?\n(Example 22560 / 1200)"))
(setq asf (getreal T "\nWhat is the area of this parcel in square feet?"))
(setq pt1 (getpoint))
(setpoint pt1)
(setvar "textstyle" "Anno Plan 0.14")
(command "_.mtext" (polar pt1 (dtr 90) (0.04)) "_J" "BC" "R" "0" "W" "0" (strcat "LOT " lot)" "")
(setvar "textstyle" "Anno Plan 0.08")
(command "_.mtext" (polar pt1 (dtr 270 (0.04)) "_J" "MC" "R" "0" "W" "25" (strcase add) "PROPERTY N/F OF" (strcase owner) dbp "")
(setvar "textstyle" "Anno Plan 0.14")
(command "_.mtext" (polar pt1 (dtr 270) (0.20)) "_J" "TC" "R" "0" "W" "0" (rtos asf 2 0) " SQ.FT. OR" (rtos (/ asf 43560) 2 3) " ACRES" "")
(setvar 'clayer oldlayer)
(setvar "CMDECHO" 1)
)

 

I'm hoping someone here can tell me what I'm doing wrong or what I just missed. I don't necessarily need one instance of mtext with three different textstyles or sizes, but I do need at least three different mtexts with the information my surveyors are looking for.

 

Additionally, is there a way to allow a getstring or getreal to be blank without causing other mtext issues and have the results truncate accordingly? Sometimes my surveyors don't always need to provide all the information on adjacent parcels.

 

Thanks again for any help anyone is able to provide.

0 Likes
Accepted solutions (2)
1,726 Views
30 Replies
Replies (30)
Message 2 of 31

Kent1Cooper
Consultant
Consultant

@evietmeier_1207 wrote:

..., I keep getting a malformed error when I try to load the code. ....


If you mean a malformed list error, that usually means a parentheses problem.  There's one missing in the second (command) function:


(command "_.mtext" (polar pt1 (dtr 270) (0.04)) "_J" "MC" "R" ....

 

EDIT:  Also, the distance number there should not be in parentheses:

 

(command "_.mtext" (polar pt1 (dtr 270) 0.04) "_J" "MC" "R" ....

 

Kent Cooper, AIA
0 Likes
Message 3 of 31

evietmeier_1207
Enthusiast
Enthusiast

@Kent1Cooper Thanks for spotting that missing parathesis. But I'm still getting ...\nf.lsp") ; error: malformed string on input Any ideas what could be causing that?

0 Likes
Message 4 of 31

Kent1Cooper
Consultant
Consultant

@evietmeier_1207 wrote:

... is there a way to allow a getstring or getreal to be blank without causing other mtext issues ....


Since (getstring) and (getreal) have different results if you hit Enter, you would need to test for them in different ways:

 

(if (/= StringVariable ""); typed other than Enter at (getstring) [Enter returns ""]

  (...then include appropriate part in text content...); then

  "" ; else -- no content entry

); if

 

(if RealVariable; typed number at (getreal) [Enter returns nil]

  (...then include appropriate part in text content...)

  "" ; else -- no content entry

); if

 

Those can be inside (strcat) functions inside Mtext commands.  [It looks like you need (strcat) in some where you don't have it].

Kent Cooper, AIA
0 Likes
Message 5 of 31

evietmeier_1207
Enthusiast
Enthusiast

@Kent1Cooper Thanks, but If/Then is still one of my weak points and I'm not sure how to complete the code. As allowing blank entries is a secondary request, I'll put this on the back burner and try to learn the rest later. Unless, that is, someone is feeling frisky and wants to make this horse drink and complete the necessary code, I can use that to learn from for later/other routines as I've been able to from other forum posts.

0 Likes
Message 6 of 31

Kent1Cooper
Consultant
Consultant

Extraneous quotation mark:

...."W" "0" (strcat "LOT " lot)" "")

Kent Cooper, AIA
0 Likes
Message 7 of 31

evietmeier_1207
Enthusiast
Enthusiast

That solved one error.

Now I get   ; error: too many arguments   after answering all the questions.

0 Likes
Message 8 of 31

Kent1Cooper
Consultant
Consultant

@evietmeier_1207 wrote:

.... Now I get   ; error: too many arguments   after answering all the questions.


I don't see any obvious reason for that.  Could it be coming from your (setpoint) function [not included]?

Yes, I do now.  Remove the T from the (getreal) function -- that's appropriate for (getstring) to allow spaces, but has no place in (getreal).

Kent Cooper, AIA
0 Likes
Message 9 of 31

evietmeier_1207
Enthusiast
Enthusiast

I saw that too, after the last reply. But I now get asked the area question twice and get...

; error: no function definition: SETPOINT

...as the return in the command line. I thought (setq pt1 (getpoint)) would ask the user for a point and set that as the coordinates for pt1 and the next line (setpoint pt1) would use that setpoint as the point for the mtext insertion. Did I not do this correctly?

 

Thanks for your patience. I'm trying to learn.

0 Likes
Message 10 of 31

Kent1Cooper
Consultant
Consultant

(setpoint) is not an AutoLisp function, as the error message makes clear.  I assumed that was something you had defined elsewhere, and couldn't know what it does without seeing the definition.  Nothing is needed between (setq)-ing a value into the pt1 variable and the using of that in the Mtext command.  Try eliminating that (setpoint) line entirely.

Kent Cooper, AIA
0 Likes
Message 11 of 31

evietmeier_1207
Enthusiast
Enthusiast

Progress! Omitting (setpoint pt1) allowed me to select a point for the mtext insertion. However, the   (setq asf (getreal "\nWhat is the area of this parcel in square feet?"))   still asks the user the area of parcel question twice and the select point for the mtext goes straight into a standard mtext command with nothing from the setq questions being placed.

 

I'm sure the answer is looking me in the face, but it's not coming to me.

0 Likes
Message 12 of 31

Kent1Cooper
Consultant
Consultant

Time to post the current state of your code with all corrections/amendments.  Pick on the  </>  item in the toolbar to paste it into a code window that will preserve any indentation.

Kent Cooper, AIA
0 Likes
Message 13 of 31

evietmeier_1207
Enthusiast
Enthusiast

@Kent1Cooper As requested, here's the current state of the code.

(defun c:nf ( / ml_txt)
	(setq oldlayer (getvar "clayer"))
	(setvar "clayer" "0")
	(setq lot (getstring T "\nWhat is the Lot number of this parcel?\n(Only the lot number is needed.)"))
	(setq add (getstring T "\nWhat is the street address for this parcel?\n(User entry is not case senstive.)"))
	(setq owner (getstring T "\nWho is(are) the current owner(s) of this parcel?\n(User entry is not case senstive.)"))
	(setq dbp (getstring T "\nWhat is the current deed book and page for this parcel?\n(Example 22560 / 1200)"))
	(setq asf (getreal "\nWhat is the area of this parcel in square feet?"))
	(setq pt1 (getpoint))
	(setvar "textstyle" "Anno Plan 0.14")
	(command "_.mtext" (polar pt1 (dtr 90) (0.04)) "_J" "BC" "R" "0" "W" "0" (strcat "LOT " lot) "")
    (setvar "textstyle" "Anno Plan 0.08")
	(command "_.mtext" (polar pt1 (dtr 270) (0.04)) "_J" "MC" "R" "0" "W" "25" (strcase add) "PROPERTY N/F OF" (strcase owner) dbp "")
	(setvar "textstyle" "Anno Plan 0.14")
	(command "_.mtext" (polar pt1 (dtr 270) (0.20)) "_J" "TC" "R" "0" "W" "0" (rtos asf 2 0) " SQ.FT. OR" (rtos (/ asf 43560) 2 3) " ACRES" "")
	(setvar 'clayer oldlayer)
	(setvar "CMDECHO" 1)
)

Thanks

0 Likes
Message 14 of 31

evietmeier_1207
Enthusiast
Enthusiast

Sorry. The last had a commented out line

(defun c:nf ( / ml_txt)
	(setq oldlayer (getvar "clayer"))
	(setvar "clayer" "0")
	(setq lot (getstring T "\nWhat is the Lot number of this parcel?\n(Only the lot number is needed.)"))
	(setq add (getstring T "\nWhat is the street address for this parcel?\n(User entry is not case senstive.)"))
	(setq owner (getstring T "\nWho is(are) the current owner(s) of this parcel?\n(User entry is not case senstive.)"))
	(setq dbp (getstring T "\nWhat is the current deed book and page for this parcel?\n(Example 22560 / 1200)"))
	(setq asf (getreal "\nWhat is the area of this parcel in square feet?"))
	(setq pt1 (getpoint))
	(setvar "textstyle" "Anno Plan 0.14")
	(command "_.mtext" (polar pt1 (dtr 90) (0.04)) "_J" "BC" "R" "0" "W" "0" (strcat "LOT " lot) "")
    (setvar "textstyle" "Anno Plan 0.08")
	(command "_.mtext" (polar pt1 (dtr 270) (0.04)) "_J" "MC" "R" "0" "W" "25" (strcase add) "PROPERTY N/F OF" (strcase owner) dbp "")
	(setvar "textstyle" "Anno Plan 0.14")
	(command "_.mtext" (polar pt1 (dtr 270) (0.20)) "_J" "TC" "R" "0" "W" "0" (rtos asf 2 0) " SQ.FT. OR" (rtos (/ asf 43560) 2 3) " ACRES" "")
	(setvar 'clayer oldlayer)
	(setvar "CMDECHO" 1)
)
0 Likes
Message 15 of 31

Kent1Cooper
Consultant
Consultant

You still have the distances in the (polar) functions [last argument] in parentheses.  See Message 2's EDIT [maybe you didn't catch that before, though it was pretty soon after the first posting].

 

EDIT:  A little suggestion:  Do both the first and third Mtexts after setting the 0.14 Style current, then change the Style to the 0.08 one to do the second Mtext, rather than switching the Style and then switching back to the previous one.

 

Oh, and I assume you have the (dtr) function loaded already -- if not necessarily, include it in this routine.

Kent Cooper, AIA
0 Likes
Message 16 of 31

evietmeier_1207
Enthusiast
Enthusiast

I didn't have the dtr function included. Didn't know I needed to. I hope I added it correctly.

I still get the parcel area question twice and no resulting text placed in my drawing. Here is the entire code as it currently stands.

(defun c:nf ( / ml_txt)
(defun dtr ( deg ) (* pi (/ deg 180.0)))
	(setq oldlayer (getvar "clayer"))
	(setvar "clayer" "0")
	(setq lot (getstring T "\nWhat is the Lot number of this parcel?\n(Only the lot number is needed.)"))
	(setq add (getstring T "\nWhat is the street address for this parcel?\n(User entry is not case senstive.)"))
	(setq owner (getstring T "\nWho is(are) the current owner(s) of this parcel?\n(User entry is not case senstive.)"))
	(setq dbp (getstring T "\nWhat is the current deed book and page for this parcel?\n(Example 22560 / 1200)"))
	(setq asf (getreal "\nWhat is the area of this parcel in square feet?"))
	(setq pt1 (getpoint))
	(setvar "textstyle" "Anno Plan 0.14")
	(command "_.mtext" (polar pt1 (dtr 90) 0.04) "_J" "BC" "R" "0" "W" "0" (strcat "LOT " lot) "")
	(command "_.mtext" (polar pt1 (dtr 270) 0.20) "_J" "TC" "R" "0" "W" "0" (rtos asf 2 0) " SQ.FT. OR" (rtos (/ asf 43560) 2 3) " ACRES" "")
    (setvar "textstyle" "Anno Plan 0.08")
	(command "_.mtext" (polar pt1 (dtr 270) 0.04) "_J" "MC" "R" "0" "W" "25" (strcase add) "PROPERTY N/F OF" (strcase owner) dbp "")
	(setvar 'clayer oldlayer)
	(setvar "CMDECHO" 1)
)

  Any more advice?

Thanks

0 Likes
Message 17 of 31

Kent1Cooper
Consultant
Consultant
Accepted solution

It functions for me, though I commented out the TextStyle changes since I don't have your Styles, and just let it use my current Style.  Are you getting any messages?  Could a Style be missing, or misspelled?

 

I don't get the double question.  I can't think of what could be causing that.

 

Other advice:
Remove the unused ml_txt from the localized variables list, but add the variables that are used:

(defun c:nf (/ dtr oldlayer lot add owner dbp asf pt1)

Add a prompt to the (getpoint) function.

Add a space before the closing quotation marks in the prompts -- it looks better to be typing in your information not hard up against the end of the prompt.

Wrap some (strcat) functions around some of the pieces, to put some things into single lines in the result that are now coming out on two lines, for example:

(strcat (rtos asf 2 0) " SQ.FT. OR") (strcat (rtos (/ asf 43560) 2 3) " ACRES")

 

 

Kent Cooper, AIA
0 Likes
Message 18 of 31

Kent1Cooper
Consultant
Consultant

@evietmeier_1207 wrote:

I didn't have the dtr function included. Didn't know I needed to. I hope I added it correctly.

....


That is not a built-in AutoLisp function, but a very commonly defined one that a lot of people use [some might call it something else like d2r, and/or might arrange the mathematical functioning in a different order], so it does need to be loaded on its own or included within routines.  In the case of common values such as you are using, you could do without it, and just use radian values directly without converting from degrees -- it costs little or nothing in terms of code length:
(dtr 90) is the same as (/ pi 2)

(dtr 270) is the same as (* pi 1.5)

Kent Cooper, AIA
0 Likes
Message 19 of 31

evietmeier_1207
Enthusiast
Enthusiast

That seems to do the trick!! I now need to work on my line spacing and rtos format. Thanks @Kent1Cooper 

0 Likes
Message 20 of 31

Kent1Cooper
Consultant
Consultant

You're welcome.  I just noticed one other thing worth addressing:  At the end, it turns command echoing [back?] on, without ever having turned it off earlier.

Kent Cooper, AIA
0 Likes