PDA

View Full Version : Error message when Dialog Box opens - error to few arguments


Lions60
2006-12-06, 04:44 PM
Here is the lisp code and dcl. When i run this the dialogue box opens up but as soon as it opens up it goes away and the command line says error to few arguments. I am not real familiar with dialogue boxes in code so all help will be appreciated.

Lisp code

(defun C:filter ()
(setq ff (list "" "2in." "4in."))
(setq dcl_id (load_dialog "filter.DCL"))
(if
(not (new_dialog "filter" dcl_id))
(exit)
)
(set_tile "fr" "0")
(set_tile "fc" "0")
(set_tile "ff")

(mode_tile "fr" 2)
(mode_tile "fc" 2)
(mode_tile "ff" 2)

(action_tile "fr" "(setq data_fr (get_tile \"fr\"))")
(action_tile "fc" "(setq data_fc (get_tile \"fc\"))")
(action_tile "ff" "(setq data_ff (get_tile \"ff\"))")

(action_tile "accept" "(done_dialog 1)")
(action_tile "cancel" "(done_dialog 0)")
(setq ans (start_dialog))
(unload_dialog dcl_id)

(setq old_osnap1 (getvar "osmode"))
(setvar "osmode" 0)
(setq filr (atoi data_fr))
(setq filc (atoi data_fc))
(setq filf (atoi data_ff))
(fillayout)
(setvar "osmode" old_osnap1)
)

(defun fillayout ()
(setq filpnt (getpoint "\n Select Placement of filter"))
(setq filpnt1(polar filpnt (dtr 0) filf))
(setq filpnt2(polar filpnt1(dtr 90)(* filr 24)))
(setq filpnt3(polar filpnt2(dtr 180)filf))
(command "line" filpnt filpnt1 filpnt2 filpnt3"C")
(while (<(cadr filpnt) (-(cadr filpnt3)24))
(setq filpnt(list (car filpnt)(+(cadr filpnt)24)))
(setq filpnt1 (list (car filpnt1) (+(cadr filpnt1)24)))
(command "line" filpnt filpnt1"")
);; end of while
(fillclayout)
);; end of fillayout


(defun fillclayout ()
(setq filpnt4 (polar filpnt3 (dtr 90) 24))
(setq filpnt5(polar filpnt4 (dtr 0) filf))
(setq filpnt6(polar filpnt5(dtr 90)(* filc 24)))
(setq filpnt7(polar filpnt6(dtr 180)filf))
(command "line" filpnt4 filpnt5 filpnt6 filpnt7"C")
(while (<(cadr filpnt4) (-(cadr filpnt7)24))
(setq filpnt4(list (car filpnt4)(+(cadr filpnt4)24)))
(setq filpnt5 (list (car filpnt5) (+(cadr filpnt5)24)))
(command "line" filpnt4 filpnt5"")
);; end of while
);; end of fillayout

DCL

filter : dialog {label = "Flat Filters";
: column {label = "Information";
: edit_box {label = "Enter Number of Filter Rows:";
key = "fr";
edit_limit = 8;
edit_width = 8;}
: edit_box {label = "Enter Number of Filter Columns:";
key = "fc";
edit_limit = 8;
edit_width = 8;}
: popup_list {label = "Enter Width of Unit:";
key = "ff";
edit_limit = 8;
edit_width = 8;}}

spacer;
ok_cancel;
spacer;
spacer;
spacer;
:text_part{label = "Designed and Created";}
:text_part{label = "by Jeremy Preston";}}

pnorman
2006-12-06, 05:45 PM
Start by changing
(set_tile "ff")
to
(set_tile "ff" "0")
or whatever value its supposed to be...

Lions60
2006-12-06, 05:50 PM
Ok that solved the problem with the dialogue not staying on the screen. Now i am having a problem with my popup_list. There are no values in it.

pnorman
2006-12-06, 05:53 PM
You might also get some use out of this...

Regards
Phill

Also you are setting the var "ans" using (setq ans (start_dialog)) but then your not checking what the answer is..
(if (= ans 1)
(progn
(setq old_osnap1 (getvar "osmode"))
(setvar "osmode" 0)
(setq filr (atoi data_fr))
(setq filc (atoi data_fc))
(setq filf (atoi data_ff))
(fillayout)
(setvar "osmode" old_osnap1)
)
)

pnorman
2006-12-06, 06:02 PM
Ok that solved the problem with the dialogue not staying on the screen. Now i am having a problem with my popup_list. There are no values in it.
to fill a list tile you use the "start_list" and "end_list" functions

(start_list "ff")
(mapcar 'add_list ff)
(end_list)

and then to preselect an item in the list use set_tile
(set_tile "ff" "1")
remember that the first item in a list is "0" not "1"

Lions60
2006-12-06, 06:10 PM
Thank you for your help. This is one of my first attempts with lisp and dcl's.

pnorman
2006-12-06, 07:12 PM
Thank you for your help. This is one of my first attempts with lisp and dcl's.
You're welcome.

another question
What is your reason for defining your list for the popup list with "" as the first element?
(setq ff (list "" "2in." "4in."))

Lions60
2006-12-06, 07:25 PM
I have no idea. That has been taken out. I am still having one problem though. If in the popup list i select 2 then (setq filf(atoi data_ff)) should be set to 2, but its not set to 2. how do i get the value that was selected in the list.

pnorman
2006-12-06, 08:08 PM
I have no idea. That has been taken out. I am still having one problem though. If in the popup list i select 2 then (setq filf(atoi data_ff)) should be set to 2, but its not set to 2. how do i get the value that was selected in the list.
The value returned by a dcl list is a string, containing an integer or integers for the position of the selected item or items in the list starting with "0" for the first item. You then need to convert this position number into the actual value from your list. There are several method for doing this. I have chosen one and done it for you below.

I have also taken the liberty of making a fewother changes. I have added error handling, and default memory for the dcl including some global vars, declared your other variables local and a few other minor tweaks. Let me know if you cant make sense of the changes.

Also you should avoid redefining standard autocad commands like "filter". I have changed the command to c:FTR


(defun c:FTR ( / ff ff# dcl_id ans data_fr data_fc data_ff filr filc filf old_osnap1 cmdecho *error*)
(defun *error* (MSG) ; local error handler to reset entity redraw
(princ (strcat "\n" MSG)) ; return the error message
(if old_osnap1 (setvar "osmode" old_osnap1))
(if cmdecho (setvar "cmdecho" cmdecho))
)
(setq ff '("2\"" "4\"")
ff# '(2 4)
)
(setq dcl_id (load_dialog "filter.DCL"))
(if (not (new_dialog "filter" dcl_id))(exit))
(if (not *data_fr*)(setq *data_fr* 2))
(if (not *data_fc*)(setq *data_fc* 2))
(if (not *data_ff*)(setq *data_ff* "0"))
(setq data_fr *data_fr*
data_fc *data_fc*
data_ff *data_ff*
)
(set_tile "fr" (itoa data_fr))
(set_tile "fc" (itoa data_fc))
(start_list "ff")
(mapcar 'add_list ff)
(end_list)
(set_tile "ff" data_ff)
(mode_tile "ff" 2)
(action_tile "accept" "(get:dcl_filter)(done_dialog 1)")
(action_tile "cancel" "(done_dialog 0)")
(setq ans (start_dialog))
(unload_dialog dcl_id)
(if (= ans 1)
(progn
(setq old_osnap1 (getvar "osmode")
cmdecho (getvar "cmdecho")
)
(setvar "osmode" 0)
(setq filr *data_fr*
filc *data_fc*
filf (nth (atoi *data_ff*) ff#)
)
(fillayout)
(setvar "osmode" old_osnap1)
(setvar "cmdecho" cmdecho)
)
)
(princ)
)
(defun get:dcl_filter ()
(setq data_fr (atoi (get_tile "fr"))
data_fc (atoi (get_tile "fc"))
data_ff (get_tile "ff")
*data_fr* data_fr
*data_fc* data_fc
*data_ff* data_ff
)
)
(defun fillayout ( / filpnt filpnt1 filpnt2 filpnt3)
(setq filpnt (getpoint "\nSelect Placement of filter"))
(setvar "cmdecho" 0)
(setq filpnt1 (polar filpnt (dtr 0) filf)
filpnt2 (polar filpnt1 (dtr 90) (* filr 24))
filpnt3 (polar filpnt2 (dtr 180) filf)
)
(command "line" filpnt filpnt1 filpnt2 filpnt3 "C")
(while (< (cadr filpnt) (- (cadr filpnt3) 24))
(setq filpnt (list (car filpnt)(+ (cadr filpnt) 24)))
(setq filpnt1 (list (car filpnt1) (+ (cadr filpnt1) 24)))
(command "line" filpnt filpnt1 "")
);; end of while
(fillclayout)
);; end of fillayout

(defun fillclayout ( / filpnt4 filpnt5 filpnt6 filpnt7)
(setq filpnt4 (polar filpnt3 (dtr 90) 24)
filpnt5 (polar filpnt4 (dtr 0) filf)
filpnt6 (polar filpnt5 (dtr 90) (* filc 24))
filpnt7 (polar filpnt6 (dtr 180) filf)
)
(command "line" filpnt4 filpnt5 filpnt6 filpnt7 "C")
(while (< (cadr filpnt4) (- (cadr filpnt7) 24))
(setq filpnt4 (list (car filpnt4) (+ (cadr filpnt4) 24)))
(setq filpnt5 (list (car filpnt5) (+ (cadr filpnt5) 24)))
(command "line" filpnt4 filpnt5 "")
);; end of while
);; end of fillayout



filter : dialog {label = "Flat Filters";
: boxed_column {label = "Information";
: edit_box {label = "Enter Number of Filter Rows:";key = "fr";edit_limit = 8; edit_width = 9;}
: edit_box {label = "Enter Number of Filter Columns:";key = "fc";edit_limit = 8;edit_width = 9;}
: popup_list {label = "Enter Width of Unit:";key = "ff";edit_limit = 8;edit_width = 8;}
: spacer {height=0.5;}
}
spacer_1;
ok_cancel;
spacer_1;
:text_part {label = " Designed and Created";}
:text_part {label = " by Jeremy Preston";}
}


Regards
Phill

Lions60
2006-12-06, 08:56 PM
Thanks i now understand how to return the value from the popup. I appreciate your help.

pnorman
2006-12-06, 09:01 PM
ok I understad everything up until filf (nth (atoi *data_ff*) ff#). When i run the program and select 2 for the value it returns 0 and when i select 4 it returns 2. Is that function what controls the return value.
The value of variable *data_ff* (the golbal var) will be either "0" or "1". This corresponds to the first or second element in your list ff. I created the list ff# just so that I could easily get a value for filf that was an integer, 2 or 4 inches. So (nth (atoi *data_ff*) ff#) retrieves the first or second element form list ff# depending on the value of *data_ff*

list ff = ("2"" "4"")
list ff# = (2 4)

I wasn't sure if atoi would work on list ff as above but I have now tested it and it does so you can do without the list ff#
so change
(setq ff '("2\"" "4\"")
ff# '(2 4)
)
to
(setq ff '("2\"" "4\""))
and
filf (nth (atoi *data_ff*) ff#)
to
filf (atoi (nth (atoi *data_ff*) ff))

see attached

Lions60
2006-12-07, 02:51 PM
Thanks very much. I have taken the error checking and other things you added to my program and put them in some other i have been working on. They now run smoother and there is no more messaging popping up in the command line. I appreciate all you have done.

pnorman
2006-12-07, 03:22 PM
Thanks very much. I have taken the error checking and other things you added to my program and put them in some other i have been working on. They now run smoother and there is no more messaging popping up in the command line. I appreciate all you have done.
You're welcome.

Here is a bit more for you to chew on!

Regards
Phill