DCL : Call a function (Autolisp) iside an action_tile

DCL : Call a function (Autolisp) iside an action_tile

Kh.mbkh
Advocate Advocate
565 Views
5 Replies
Message 1 of 6

DCL : Call a function (Autolisp) iside an action_tile

Kh.mbkh
Advocate
Advocate
Having some "edit_box"s with key "key1" "key2"...
The object is to get the values of these Boxes after click on the OK button; so we define a function (GatVal) and call it inside the click button action _tile:

 

 

(action_tile "accept" "(GetVal) (done_dialog)"
(start_dialog)
(unload_dialog dcl_id)

 

 

 

(defun GetVal()
  (setq MuValue1   (atof (get_tile "Key1" ))
        MuValue2   (atof (get_tile "Key2" ))
  ...
)
)

 

 

However, this does not work, This is the error when taping OK button:

 

error: bad argument type: stringp nil

 

 

0 Likes
566 Views
5 Replies
Replies (5)
Message 2 of 6

Sea-Haven
Mentor
Mentor

Try

 

 

(action_tile "accept" "(setq MuValue1   (atof (get_tile \"Key1\" ))(setq MuValue2   (atof (get_tile \"Key2\" )) (done_dialog)"

 

If the dcl is all edit boxes this may be useful. Can have as many as you want.

 

 

0 Likes
Message 3 of 6

john.uhden
Mentor
Mentor

Exactly, since the action must be in the form of a string.

Now if Key1 and Key 2 were symbols containing the names "Key1" and "Key2", then he could use (get_tile Key1) etc.

In reality he should set the values of his symbols when there is action taken on "Key1" and "Key2."  Then there's no need to use get_tile.

In fact if the symbol name were the tile name, then he could use a generic form...

(action_tile "Key1" "(set (read $key) $value)")

(action_tile "Key2" "(set (read $key) $value)")

or even "(set (read $key)(atof $value))"

But that's taking a chance that the user entered "2point33" for what is supposed to be a numeric value.

That's why I always use a function I named @Anonymous_numtile and set the error_tile if it's not a number or even explicitly an integer or real.

John F. Uhden

0 Likes
Message 4 of 6

Sea-Haven
Mentor
Mentor

Yes john the main flaw with the multi getvals is just that you are entering a string and its converted to a number but you could do "1x2" will return some form of number.

 

Interested in your @_check_tile 

0 Likes
Message 5 of 6

john.uhden
Mentor
Mentor

This is old, so change the trim thing to something current.

(defun @Anonymous_err ()(setq_tile "error" ""))
;;------------------------------------------------
;; CHECKNUM (c)1994-2000, John F. Uhden, CADvantage
;; Check if edit box returns a specified number, and return if T:
;;
(defun @Anonymous_check_numtile (|val |tile |sym |bit |min |max / |str)
;; Input parameters:
;;    |val = value of tile (as a string)
;;   |tile = name of tile
;;    |sym = name of symbol (as a string)
;;    |bit = boolean value specified for number
;;          1 = integer only
;;          2 = non-zero
;;          4 = non-negative
;;    |min = minimum permitted value (may be 'INT or 'REAL or nil)
;;    |max = maximum permitted value (may be 'INT or 'REAL or nil)
;;
   (set_tile |tile (setq |val (@cv_ltrim (@cv_rtrim |val)))) ; strip spaces
   (if (= (logand |bit 1) 1)
      (progn
         (setq |errmsg "Integer must be ")
         (if (eval (read |sym))
            (setq |str (itoa (eval (read |sym))))
            (setq |str "")
         )
      )
      (progn
         (setq |errmsg "Number must be ")
         (if (eval (read |sym))
            (setq |str (rtos (eval (read |sym))))
            (setq |str "")
         )
      )
   )
   (cond
      ((= (logand |bit 6) 6)(setq |errmsg (strcat |errmsg "positive and non-zero.")))
      ((= (logand |bit 4) 4)(setq |errmsg (strcat |errmsg "positive.")))
      ((= (logand |bit 2) 2)(setq |errmsg (strcat |errmsg "non-zero.")))
      (1 (setq |errmsg (strcat |errmsg "real.")))
   )
   ;; Convert the current edit_box string to a real
   (if |val (setq |val (distof (@cv_ltrim (@cv_rtrim |val)))))
   (if (and |val (= (logand |bit 1) 1))
      (if (zerop (rem |val 1))
         (setq |val (fix |val))
         (setq |val nil)
      )
   )
   (if (and |val (= (logand |bit 2) 2)(zerop |val))(setq |val nil))
   (if (and |val (= (logand |bit 4) 4)(minusp |val))(setq |val nil))
   (cond
      ((not |val)
         (set_tile |tile |str)
         (mode_tile |tile 2) ; focus on tile
      )
      ((and |min (< |val |min))
         (if (= (type |val) 'INT)
            (setq |errmsg (strcat "Minimum permitted value is " (itoa |min)))
            (setq |errmsg (strcat "Minimum permitted value is " (rtos |min)))
         )
         (set_tile |tile |str)
         (mode_tile |tile 2) ; focus on tile
      )
      ((and |max (> |val |max))
         (if (= (type |val) 'INT)
            (setq |errmsg (strcat "Maximum permitted value is " (itoa |max)))
            (setq |errmsg (strcat "Maximum permitted value is " (rtos |max)))
         )
         (set_tile |tile |str)
         (mode_tile |tile 2) ; focus on tile
      )
      (1 (set (read |sym) |val)
         (setq |errmsg nil)
      )
   )
   (@reset_err)
)

John F. Uhden

Message 6 of 6

Sea-Haven
Mentor
Mentor

Thank you

0 Likes