ERROR AND MTEXT

ERROR AND MTEXT

etilley327KA
Advocate Advocate
912 Views
23 Replies
Message 1 of 24

ERROR AND MTEXT

etilley327KA
Advocate
Advocate

I really could use some help. I keep getting an error somewhere in my math functions, but I dont see it. Also, my mtext isnt working either. Im trying to add text with the variables. 

 
(defun c:XC (/ tmn tdp mtof mtoc mdis slope mdn apron pt1)
            (setq tmn (getreal "\nEnter SLOPE tolerance: "))
            (setq tdp
              (cond
                (XSTRCASE(getreal "\nEnter standard drop or <Enter for 0.67>: "))
                (0.67)
              )
            )
            (setq mtof (getreal "\nEnter TOF: "))
            (setq mtoc (getreal "\nEnter TOC: "))
            (setq mdis (getreal "\nEnter Distance: "))
              (setq slope (rtos (* (/ (- mtof tdp mtoc) mdis) 100) 2 0))
              (setq mdn (- mtof (+ mtoc (* (/ tmn 100) mdis)) 0.375))
              (setq apron (- mtof (+ 0.375 mdn)))
                (if (< slope tmn)
                  (progn
                    (alert "Too High")
                    (command "mtext" (setq pt1 (getpoint "\nSelect Point: ") ) pt1 slope apron mtof mtoc mdis tdp "")
                  )
                    (command "mtext" (setq pt1 (getpoint "\nSelect Point: ") ) pt1 (strcat slope "%") "")
                )
  (princ)
)
0 Likes
Accepted solutions (1)
913 Views
23 Replies
Replies (23)
Message 2 of 24

ВeekeeCZ
Consultant
Consultant

Comparing "slope" being a string to "tmn" being a real...

0 Likes
Message 3 of 24

ВeekeeCZ
Consultant
Consultant

slope apron mtof mtoc mdis tdp ... all have to be STRINGs and (strcat .... ) together into one string.

0 Likes
Message 4 of 24

ВeekeeCZ
Consultant
Consultant

XSTRCASE is something undocumented that I don't know. What is it? That could be your issue - if that returns a string.

 

Edit: 

(xstrcase) An international-friendly version of (strcase).
0 Likes
Message 5 of 24

etilley327KA
Advocate
Advocate

Someone helped me with that, it looks to be something similar to strcase, but I can't see the difference. I guess ill just switch it to strcase.

0 Likes
Message 6 of 24

ВeekeeCZ
Consultant
Consultant

@etilley327KA wrote:

Someone helped me with that, it looks to be something similar to strcase, but I can't see the difference. I guess ill just switch it to strcase.


 

I would remove it. STRCASE does not make sense to use there.

0 Likes
Message 7 of 24

etilley327KA
Advocate
Advocate

Slope should be a real, where did I switch it? Also, if I cant use strcat, how do I add text to the variable in my mtext?

0 Likes
Message 8 of 24

ВeekeeCZ
Consultant
Consultant

@etilley327KA wrote:

Slope should be a real, where did I switch it? Also, if I cant use strcat, how do I add text to the variable in my mtext?


 

(setq slope (rtos (* (/ (- mtof tdp mtoc) mdis) 100) 2 0))

 

2nd... Why can not you? IMHO you can, but first you need to convert all the reals to strings.

0 Likes
Message 9 of 24

etilley327KA
Advocate
Advocate

OK, so I just need to convert all my reals to strings, got it. On my math function, even when I remove the rtos I still get an error, do you know why?

0 Likes
Message 10 of 24

ВeekeeCZ
Consultant
Consultant

Did you remove that xstrcase?

 

 

(defun c:XC (/ tmn tdp mtof mtoc mdis slope mdn apron pt1)
  (setq tmn (getreal "\nEnter SLOPE tolerance: "))
  (setq tdp (cond ((getreal "\nEnter standard drop or <0.67>: "))
		  (0.67)))
  (setq mtof (getreal "\nEnter TOF: "))
  (setq mtoc (getreal "\nEnter TOC: "))
  (setq mdis (getreal "\nEnter Distance: "))
  (setq slope (* (/ (- mtof tdp mtoc) mdis) 100))
  (setq mdn (- mtof (+ mtoc (* (/ tmn 100) mdis)) 0.375))
  (setq apron (- mtof (+ 0.375 mdn)))
  (if (< slope tmn)
    (progn
      (alert "Too High")
      (command "mtext" (setq pt1 (getpoint "\nSelect Point: ")) pt1 (strcat (rtos slope) ", " (rtos apron) ", " (rtos mtof) ", " (rtos mtoc) ", " (rtos mdis) ", " (rtos tdp) "" ""))
      )
    (command "mtext" (setq pt1 (getpoint "\nSelect Point: ") ) pt1 (strcat slope "%") "" "")
    )
  (princ)
  )

 

I didn't check the math, just the syntax. 

0 Likes
Message 11 of 24

Kent1Cooper
Consultant
Consultant

@etilley327KA wrote:

.... even when I remove the rtos I still get an error, do you know why?


What error?  Show the way the edited code line ended up.

Kent Cooper, AIA
0 Likes
Message 12 of 24

etilley327KA
Advocate
Advocate
(defun c:XC (/ tmn tdp mtof mtoc mdis slope mdn apron pt1)
            (setq tmn (getreal "\nEnter SLOPE tolerance: "))
            (setq tdp
              (cond
                (STRCASE(getreal "\nEnter standard drop or <Enter for 0.67>: "))
                (0.67)
              )
            )
            (setq mtof (getreal "\nEnter TOF: "))
            (setq mtoc (getreal "\nEnter TOC: "))
            (setq mdis (getreal "\nEnter Distance: "))
              (setq slope (* (/ (- mtof tdp mtoc) mdis) 100))
              (setq mdn (- mtof (+ mtoc (* (/ tmn 100) mdis)) 0.375))
              (setq apron (- mtof (+ 0.375 mdn)))
                (if (< slope tmn)
                  (progn
                    (alert "Too High")
                    (command "mtext" (setq pt1 (getpoint "\nSelect Point: ") ) pt1
                             (strcat (rtos slope 2 0) "%"
                              "\\PApron " (rtos apron 2 2)
                              "\\PTOF " (rtos mtof 2 2)
                              "\\PTOC " (rtos mtoc 2 2)
                              "\\PDist " (rtos mdis 2 2)
                              "\\PDrop " (rtos tdp 2 2)) "")
                  )
                    (command "mtext" (setq pt1 (getpoint "\nSelect Point: ") ) pt1 (strcat (rtos slope 2 0) "%") "")
                )
  (princ)
)
0 Likes
Message 13 of 24

ВeekeeCZ
Consultant
Consultant

Ok, I guess it's just me... Would you explain to me what purpose serves the STRCASE there?

0 Likes
Message 14 of 24

Kent1Cooper
Consultant
Consultant

This is why I asked what the error was [saying "I still get an error" is never enough information].  It's apparently not from the removing of the (rtos) part, but from the attempt to change the case of a number, or of nil if you hit Enter to accept the default.

Kent Cooper, AIA
0 Likes
Message 15 of 24

etilley327KA
Advocate
Advocate

etilley327KA_0-1670855206301.png

bad argument type: numberp: nil :error#2

0 Likes
Message 16 of 24

etilley327KA
Advocate
Advocate
Not really sure. I was trying to ask for a number but have a standard input if the user didnt have one.
0 Likes
Message 17 of 24

ВeekeeCZ
Consultant
Consultant
Accepted solution

@etilley327KA wrote:
Not really sure. I was trying to ask for a number but have a standard input if the user didnt have one.

 

Well, it's your code. Who else should know?! If you don't know something, look in HELP.

 

Message 18 of 24

etilley327KA
Advocate
Advocate
I removed the stcase, thanks.
0 Likes
Message 19 of 24

Kent1Cooper
Consultant
Consultant

Even if it were possible to make a number uppercase, you would be missing a set of parentheses:

              (cond
                ((STRCASE(getreal "\nEnter standard drop or <Enter for 0.67>: ")))
                (0.67)
              )
Kent Cooper, AIA
0 Likes
Message 20 of 24

etilley327KA
Advocate
Advocate

Yeah, it seems that variable was causing the problem. Thanks

0 Likes