LISP with multiple mtext entries using different textstyles

LISP with multiple mtext entries using different textstyles

evietmeier_1207
Enthusiast Enthusiast
1,727 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,728 Views
30 Replies
Replies (30)
Message 21 of 31

evietmeier_1207
Enthusiast
Enthusiast

Got it thanks. I added a command to turn it off at the beginning.

0 Likes
Message 22 of 31

evietmeier_1207
Enthusiast
Enthusiast

After a little tweaking, I have this code finally giving my surveyors the results they were looking for.

(defun c:nf (/ dtr oldlayer lot add owner asf pt1)
(defun dtr ( deg ) (* pi (/ deg 180.0)))
    (setvar "CMDECHO" 0)
    (setq dim (getvar "dimzin"))
    (command "_dimzin" "11")
	(setq oldlayer (getvar "clayer"))
	(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 or DB 22560 / PG 1200)"))
	(setq asf (getreal "\nWhat is the area of this parcel in square feet?"))
	(setq pt1 (getpoint "\nSelect insertion oint for N/F note group:"))
	(setvar "clayer" "XLot Numbers")
	(setvar "textstyle" "Anno Plan 0.14")
	(command "_.mtext" (polar pt1 (dtr 90) 5.8) "_J" "BC" "R" "0" "W" "0" (strcat "LOT " lot) "")
    (setvar "clayer" "XProperty Data - Now or Formally")
    (setvar "textstyle" "Anno Plan 0.08")
	(command "_.mtext" (polar pt1 (dtr 270) 0) "_J" "MC" "R" "0" "W" "30" (strcase add) "PROPERTY N/F OF" (strcase owner) (strcase dbp) "")
	(setvar "clayer" "XLot Dimension and Square Footage")
	(setvar "textstyle" "Anno Plan 0.10")
	(command "_.mtext" (polar pt1 (dtr 270) 6) "_J" "TC" "R" "0" "W" "0" (strcat (rtos asf 2 0) " SQ.FT. OR") (strcat (rtos (/ asf 43560) 2 3) " ACRES") "")
	(command "_dimzin" dim)
	(setvar 'clayer oldlayer)
	(setvar "CMDECHO" 1)
)

But now they are asking for more and hoping to get this line (the nerve of some people 😉) ;

(command "_.mtext" (polar pt1 (dtr 270) 6) "_J" "TC" "R" "0" "W" "0" (strcat (rtos asf 2 0) " SQ.FT. OR") (strcat (rtos (/ asf 43560) 2 3) " ACRES") "")

...to have the appropriate thousands and millions comma separators. Unfortunately, I am not able to find anything overly helpful in the forums that gives the RTOS results with the necessary commas. The nearest I could find involved inserting the actual number in the code, and I don't need the street address to have commas. If anyone is able to help, I would be greatfull for helping to get some of my LISP users off my back. Thanks

0 Likes
Message 23 of 31

Kent1Cooper
Consultant
Consultant

@evietmeier_1207 wrote:

....to have the appropriate thousands and millions comma separators. Unfortunately, I am not able to find anything overly helpful in the forums that gives the RTOS results with the necessary commas. ....


Does my (commify) routine, >here<, do it for you?

Kent Cooper, AIA
0 Likes
Message 24 of 31

evietmeier_1207
Enthusiast
Enthusiast

@Kent1Cooper There's a lot going on in that post. I did find your (commify) code and tried it in a few places in the code you helped me develop, but I am not getting the correct or desired results. Does this need to be integrated and mixed into my code or positioned before or after?  I guess RTOS doesn't have any native functions or controls for this to simplify the process?

 

I also tried one of Lee Mac's and was not successful with that either.

 

Thanks

0 Likes
Message 25 of 31

Kent1Cooper
Consultant
Consultant
Accepted solution

@evietmeier_1207 wrote:

.... Does this need to be integrated and mixed into my code or positioned before or after?  ....


You could have it as its own file and ensure it's loaded first, or (load) it within your routine, or include its definition inside yours.

 

You don't show how you incorporated it, but might you have tried to apply the function to the already-(rtos)-converted text string?  It wants the number as argument.

 

Assuming it's loaded, and that you won't have 1000 Acres or more [i.e. you need to apply it only to the square footage], does this work for that piece of Mtext?

(command "_.mtext"
  (polar pt1 (dtr 270) 6) "_J" "TC" "R" "0" "W" "0"
  (strcat (commify asf 0) " SQ.FT. OR")
  (strcat (rtos (/ asf 43560) 2 3) " ACRES")
  ""
)

 

Kent Cooper, AIA
0 Likes
Message 26 of 31

evietmeier_1207
Enthusiast
Enthusiast

That works! Gives me the SQ FT just as my surveyors want it. Is there a way to get your (commify) to with with the acres and still get three decimals?

0 Likes
Message 27 of 31

evietmeier_1207
Enthusiast
Enthusiast

Looks like this gave me the decimals on the acres

(command "_.mtext" (polar pt1 (dtr 270) 6) "_J" "TC" "R" "0" "W" "0" (strcat (commify asf 0) " SQ.FT. OR") (strcat (commify (/ asf 43560) 3) " ACRES") "")

 Does this look right?

0 Likes
Message 28 of 31

Kent1Cooper
Consultant
Consultant

Looks right to me, but try it out.  I didn't do that before because I couldn't imagine lots with enough acres to need the comma, but I guess I shouldn't assume....

Kent Cooper, AIA
Message 29 of 31

evietmeier_1207
Enthusiast
Enthusiast

Here's the completed code, if this helps anyone with their routines.

(defun commify (num prec / numstr intstr decstr comstr)
  (setq
    numstr (rtos num 2 prec); eliminates any scientific-notation E+ element
    intstr ; integer portion as string
      ;; (itoa (fix num)) has problem with calculated returns in scientific notation,
      ;; so use (rtos) to 0 decimal places, but that rounds, possibly upward, so:
      (if (< (- num (fix num)) 0.5)
        (rtos num 2 0)
        (rtos (1- num) 2 0)
      ); if & intstr
    decstr (substr numstr (1+ (strlen intstr))); decimal portion as string ["" if no decimal places]
    comstr (substr intstr 1 (rem (strlen intstr) 3)); begin commified string w/ part before first comma [if any]
    intstr (substr intstr (1+ (strlen comstr)))
  ); setq
  (while (>= (strlen intstr) 3)
    (setq
      comstr (strcat comstr (if (> (strlen comstr) 0) "," "") (substr intstr 1 3)); [no comma if starts with 3 digits]
      intstr (substr intstr 4)
    ); setq
  ); while
  (strcat comstr decstr); add decimals back [if any]
)

(defun c:nf (/ dtr oldlayer lot add owner asf pt1)
(defun dtr ( deg ) (* pi (/ deg 180.0)))
    (setvar "CMDECHO" 0)
    (setq dim (getvar "dimzin"))
    (command "_dimzin" "11")
	(setq oldlayer (getvar "clayer"))
	(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 or DB 22560 / PG 1200)"))
	(setq asf (getreal "\nWhat is the area of this parcel in square feet?\n(This command will round your entry to the nearest square foot.)\n(Do not include commas. Commas will be added as needed.)"))
	(setq pt1 (getpoint "\nSelect insertion point for N/F note group:"))
	(setvar "clayer" "XLot Numbers")
	(setvar "textstyle" "Anno Plan 0.14")
	(command "_.mtext" (polar pt1 (dtr 90) 5.8) "_J" "BC" "R" "0" "W" "0" (strcat "LOT " lot) "")
	(setvar "clayer" "XLot Dimension and Square Footage")
	(setvar "textstyle" "Anno Plan 0.10")
    (command "_.mtext" (polar pt1 (dtr 270) 6) "_J" "TC" "R" "0" "W" "0" (strcat (commify asf 0) " SQ.FT. OR") (strcat (commify (/ asf 43560) 3) " ACRES") "")
    (setvar "clayer" "XProperty Data - Now or Formally")
    (setvar "textstyle" "Anno Plan 0.08")
	(command "_.mtext" (polar pt1 (dtr 270) 0) "_J" "MC" "R" "0" "W" "30" (strcase add) "PROPERTY N/F OF" (strcase owner) (strcase dbp) "")
	(command "_dimzin" dim)
	(setvar 'clayer oldlayer)
	(setvar "CMDECHO" 1)
)

Enjoy!

0 Likes
Message 30 of 31

Sea-Haven
Mentor
Mentor

Would you not say pick a point inside lot can do boply and return area of dummy pline made. Limits errors.

(setq asf (getreal "\nWhat is the area of this parcel

(command "bpoly" (getpoint "\nTo get Area pick point inside lot ") "")
(setq obj (vlax-ename->vla-object  (entlast)))
(setq area (rtos (vlax-get obj 'Area) 2 2))
(vla-delete obj) ; remove dummy pline object

 

Message 31 of 31

evietmeier_1207
Enthusiast
Enthusiast

@Sea-Haven This looks like a great idea to me. However, my surveyors are typically placing the note resulting from this routine after most of the line work is in. If they request this functionality, I will definitory look into incorporating this into the LISP. Thanks for the suggestion.

0 Likes