Jump to content

Recommended Posts

Posted

Hi am am trying to write a very simple code but i can not understand why gives me this error

 

Error: incorrect type - nil

 

 

(defun c:cost ( / a k) 
        (progn
              (setq a (getreal "\nGive Area in m2 : "))
			  (setq k ( / (+ (* a 2.5) 75) 1.24))
	        (princ
                (strcat
                    "\n Calculate cost "
                    "\n --------------------------------"
                    "\n   Area  = " a " m2"
                    "\n   Cost = " (rtos k 2 2) 
                    "\n ------------------------------"
                )
            )
        )

    (princ)
)

 

Posted (edited)
(defun c:cost ()
  (setq a (getreal "\nEnter Area in m2: ")) ; Get area input
  (setq k (/ (+ (* a 2.5) 75) 1.24)) ; Calculate cost
  (princ (strcat
          "\nCalculate cost"
          "\n--------------------------------"
          "\n   Area  = " (rtos a 2 2) " m2"
          "\n   Cost  = " (rtos k 2 2)
          "\n--------------------------------"))
  (princ)
)

I fix it.

 

Thanks

Edited by mhy3sx
  • Like 1
Posted

To indicate areas and volumes, lisp also accepts the superscript, using the keys Alt+0178 and Alt+0179

Posted (edited)

and \U+00B2 for squared or \U+00B3 for cubed as an alternative to Alt+ ("\U+.... " works better in LISP)

 

Can also use (chr 178) and (chr 179)

 

... which is why LISP is brilliant - so many ways to do the same thing!

"\n Area = " (rtos a 2 2) " m\U+00B2" 

"\n Area = " (rtos a 2 2) " m " (chr 178) 

Edited by Steven P
  • Like 2
  • Agree 1
Posted

Usually fonts follow the same chr # but different languages or a custom font might not be the right number you can use this to find the corrrect #

 

image.png.e4c4632193bdddd1150beb74adceaf8e.png

 

;;----------------------------------------------------------------------------;;
;; Output Character ASCii number table
(defun C:text_table (/ vars vals base i c tx base_n)
  (setq vars '(snapmode osmode cmdecho ATTDIA ATTREQ LUPREC)  ;list of variables
        vals (mapcar 'getvar vars)      ;store old values
  )
  (mapcar 'setvar vars '(0 0 0 0 1 0))  ;set new values
  (setq base (getpoint "\nEnter Starting Point :")
        i 0
        c 0
        n (/ (getvar 'textsize) 8)
        H (getvar 'textsize)
  )
  (while (< i 1000)
    (setq tx (strcat (AT:NumFix (itoa i) 4) " = " (chr i))
          base_n (list (+ (car base) (* (fix (* (/ c 25) n)) 100)) (- (cadr base) (* 20 (* c n))))
    )
    (entmake (list '(0 . "TEXT")
                   (cons 8 (getvar 'clayer))
                   (cons 10 base_n)
                   (cons 40 H)
                   (cons 1 tx)
                   (cons 7 (getvar 'textstyle))
             )
    )
    (setq i (1+ i))
    (setq c (1+ c))
    (if (eq c 25)  ;simple counter to step over
      (progn
        (setq base (polar base 0 3))
        (setq c 0)
      )
    )
  )
  (mapcar 'setvar vars vals)  ;restore old values
  (princ)
)
(defun AT:NumFix (s n)
 ;; Fix number string with leading zeros
 ;; s - Number string to fix
 ;; n - Number of characters for final string
 ;; Alan J. Thompson, 10.29.09
 ;; (AT:NumFix i 3) i= 1 = 001
  (if (< (strlen s) n)
    (AT:NumFix (strcat "0" s) n)
    s
  )
)

 

  • Like 3
  • 2 weeks later...
Posted

I try to add an filter in the code and now is not working . The idea is if the calculation  from t1 is biger than t2 then as res1 print the t2. Can any one help me to fix it?

 

 

(defun c:foo(/ *error* dch dcl des a)
             
            (defun *error* ( msg )
                (if (and (= 'int (type dch)) (< 0 dch))
                    (unload_dialog dch)
                )
                (if (= 'file (type des))
                    (close des)
                )
                (if (and (= 'str (type dcl)) (findfile dcl))
                    (vl-file-delete dcl)
                )
                (if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*")))
                    (princ (strcat "\nError: " msg))
                )
                (princ)
            )
         
            (cond
                (   (not
                        (setq dcl (vl-filename-mktemp nil nil ".dcl")
                              des (open dcl "w")
                        )
                    )
                    (princ "\nUnable to open DCL for writing.")
                )
                (   (progn
                        (foreach str
                           '(
                                "ed : edit_box"
                                "{"
                                "    alignment = left;"
                                "    width = 20;"
                                ;"    edit_width = 10;"
                                ;"    fixed_width = true;"
                                "}"
                                ""
                                "peacost : dialog"
                                "{"
                                "    spacer;"
                                "    key = \"dcl\";"
                                "    : row"
                                "    {"
                                "        : ed { key = \"a\"; label = \"Area:\"; }"
                                "        : ed { key = \"res1\"; label = \"Calc:\"; is_enabled = false; }"
                                "    }"
                                "    : row"
                                "    {"
                                "         : ed { key = \"res2\"; label = \"Text :\"; is_enabled = false; }"
                                "    }"
                                "    spacer;"
                                "    : row"
                                "    {" 
                                "    : column { width = 10;"
                                "    }"	 ; end column
                                "    : column { width = 17;"
                                "      : button { key = \"cal\"; label = \"Calc\"; is_default = true;"
                                "                 is_cancel = false; fixed_width = true; width = 10; }" 
                                "    }"	 ; end column
                                "    : column { width = 17;"
                                "      : button { key = \"OK\"; label = \"OK\"; is_default = true;"
                                "                 is_cancel = true; fixed_width = true; width = 10; }"
                                "    }" ; end column
				              "    }"	 ; end row
                                "}"
                            )
                        (write-line str des)
                        )
                        (setq des (close des)
                              dch (load_dialog dcl)
                        )
                        (<= dch 0)
                    )
                    (princ "\nUnable to load DCL file.")
                )
                (   (not (new_dialog "peacost" dch))
                    (princ "\nUnable to display 'peacost' dialog.")
                )
                (   t
                (set_tile "dcl" "Any name ")
                (action_tile "a" "(setq a $value)")
                (action_tile "cal"
                    (vl-prin1-to-string
                       '(
                            (lambda ( / x)
                                (set_tile "res1" "")
                                (set_tile "res2" "")
								       (setq t1 (rtos (/ (+ (* e 2.5) 75) 1.24) 2 2))  								   
								       (setq t2 322.58)   									   
                                (cond
                                    ((or (not a) (= "" a))
                                     (alert " !!!")
                                     (mode_tile "a" 2)
                                    )
                                    ((not (setq e (distof a)))
                                     (alert " !!!")
                                     (mode_tile "a" 2)
                                    )
                                    ((<= e 250)
                                     (mode_tile "a" 2)
								 (if (> t1 t2)
                                     (set_tile "res1" t1)
								 (set_tile "res1" t2)	 
								 )
                                     (set_tile "res2" "text text text ")
                                    )
                                    ((and (> e 250) (<= e 1000))
                                     (mode_tile "a" 2)
								(if (> t1 t2)
                                     (set_tile "res1" t1)
								 (set_tile "res1" t2)	 
								 )
                                     (set_tile "res2" "text text text")
                                    )
                                    ((> e 1000)
                                     (mode_tile "a" 2)
								 (if (> t1 t2)
                                     (set_tile "res1" t1)
								 (set_tile "res1" t2)	 
								 )
                                     (set_tile "res2" "text text text")
                                    )
                                ) ; end cond
                            )
                        )
                    )
                )
                (start_dialog)
            )
        )
        (*error* nil)
        (princ)
    ); end defun

 

 

Thanks

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