Lsp Error: Requires numeric distance or second point

Lsp Error: Requires numeric distance or second point

mikesteffy
Participant Participant
2,752 Views
6 Replies
Message 1 of 7

Lsp Error: Requires numeric distance or second point

mikesteffy
Participant
Participant
When running the attached lsp file I get this error. Requires numeric distance or second point ;error: Function cancelled This is as the text is being placed. The file used to run fine but I'm not sure when it started this behavior because a user just reported it to me this week. When the file works it should select the closed polyline object and place the text as nnnn Acres. Any help is appreciated. Thanks, Mike
0 Likes
Accepted solutions (1)
2,753 Views
6 Replies
Replies (6)
Message 2 of 7

Ranjit_Singh
Advisor
Advisor

no attachment.

0 Likes
Message 3 of 7

mikesteffy
Participant
Participant

sorry, must not have added the attachment

0 Likes
Message 4 of 7

ВeekeeCZ
Consultant
Consultant

The issue is the last line.

 

(command ".TEXT" "M" p1 "" ac)

 

Correct functionality depends on whether your current text style HAS defined text height, or not. If not, there must be one more "" (or the height) in your code.

 

(command ".TEXT" "M" p1 "" "" ac)

 

 

0 Likes
Message 5 of 7

ВeekeeCZ
Consultant
Consultant

@ВeekeeCZ wrote:

 

... 

Correct functionality depends on whether your current text style HAS defined text height, or not.

...

 


I added on test line that covers this behavior and put the correct number of "enters". See the SPOILER.

 

BTW One very ugly thing about your code - it set CMDECHO off and it NEVER gets it back!! Not nice!!

 

Spoiler
(defun C:ACRE ( / ss n en e ty b c d p1 ac)
   ;(setvar "cmdecho" 0)
   (prompt "\nSelect Polyline: ")
     (setq ss (ssget)
           n 0
           en (ssname ss n)
           e (entget en)
           ty (cdr (assoc 0 e))
      )
     (if (not (or (= ty "POLYLINE") (= ty "LWPOLYLINE")))
       (prompt "\nOBJECT SELECTED NOT A POLYLINE, TRY IT AGAIN") 
      )           

        (if (or (= ty "POLYLINE") (= ty "LWPOLYLINE")) 
           (progn          
              (command ".COPY" en "" "0,0" "0,0")
                  (setq b (entlast))

              (command ".AREA" "O" (entlast))
                  (setq c (getvar "AREA")
                        c (rtos c 2)
                        c (distof c 2)
                        d (/ c 43560)
                   )       

               (prompt (strcat "\nArea = " (rtos d 2 4) " acres"))
                   (setq p1 (getpoint "\nText center point - will use current settings - <*none*> "))
                   (setq ac (strcat (rtos d 2 3) " ACRES"))
                      (entdel (entlast))          
           )
        )

     (if p1
        (if (zerop (cdr (assoc 40 (tblsearch "STYLE" (getvar 'TEXTSTYLE)))))
          (command ".TEXT" "M" p1 "" "" ac)
          (command ".TEXT" "M" p1 "" ac)))

(princ)
)
;(C:ACRE)
0 Likes
Message 6 of 7

Kent1Cooper
Consultant
Consultant
Accepted solution

Some further suggestions for improvement....

 

You have a lot of variables that are used only once, so there's no benefit to putting them into variables -- just figure the values where they are used.  You even have at least one that is never used.  And Copying the selected Polyline doesn't seem to be doing anything for you, so I omitted that.

 

I don't see the point in rounding the area to 2 decimal places [in a rather round-about way], and then calculating the acreage and getting that in text form to 3 decimal places.  So I left the area value "raw" and rounded it directly to 3 decimal places only at the time of constructing the text content.

 

The following incorporates asking the User to try again, if they either miss picking or pick something other than a Polyline, within the command, rather than ending the command and requiring them to start it again.

 

It also uses (entsel) rather than (ssget), so you can have the prompt you want, and not have to see the "Select objects:" prompt [always in the plural] that (ssget) always provides.

 

[And I thought maybe the command echoing of one Area command and one Text command might not be too objectionable to just allow, but you can turn it off if you prefer, though I concur with @ВeekeeCZ that you must set it back afterwards.  But that would mean you should include *error* handling, which if you leave command echoing on, you don't really need.]

 

(defun C:ACRE ( / esel ent p1)
  (while
    (not
      (and
        (setq esel (entsel "\nSelect Polyline: "))
        (wcmatch (cdr (assoc 0 (entget (setq ent (car esel))))) "*POLYLINE")
      ); and
    ); not
    (prompt "\nOBJECT SELECTED NOT A POLYLINE, TRY IT AGAIN")
  ); while
  (if (setq p1 (getpoint "\nText center point - will use current settings - <*none*> "))
    (progn ; then
      (command
        "_.area" "_object" ent
        "_.text" "_middle" p1
      ); command -- leaves at height or rotation prompt
      (if (= (cdr (assoc 40 (tblsearch "style" (getvar 'textstyle)))) 0)
        (command "" "") (command ""); without or with fixed height
      ); if
      (command (strcat (rtos (/ (getvar 'area) 43560) 2 3) " ACRES"))
    ); progn
  ); if
  (princ)
); defun
(C:ACRE)

 

Kent Cooper, AIA
0 Likes
Message 7 of 7

mikesteffy
Participant
Participant
Thanks for the quick replies and for the detail. All of those worked and cleaned the routine up, Kent's was a little cleaner and worked flawlessly so it's the final version. Thanks again.
0 Likes