View Full Version : Dialog box question
cadconcepts
2006-03-24, 04:01 AM
Hi All
I am trying to add editable drop down box similar to the angle box in the Hatch dialog box or the scale box in the plot command. I want to be able to either enter a value or select it from list of available choices. Thanks in advance.
Manuel A. Ayala
Adesu
2006-03-24, 07:26 AM
Hi All
I am trying to add editable drop down box similar to the angle box in the Hatch dialog box or the scale box in the plot command. I want to be able to either enter a value or select it from list of available choices. Thanks in advance.
Manuel A. Ayala
Hi cadconcepts,
Here what you are looking for,I hope this code can help you
This is LSP file
(defun c:test1 (/ lst dcl_id ans)
(setq lst'("1 : 1" "1 : 2" "1 : 3" "1 : 4" "1 : 5"))
(setq dcl_id (load_dialog "Test-1.DCL"))
(if
(not (new_dialog "test1" dcl_id))
(exit)
)
(start_list "pl") ; start the list box
(mapcar 'add_list lst) ; fill the list box
(end_list)
(mode_tile "pl" 4)
(action_tile "pl" "(setq data_pl (get_tile \"pl\"))")
(action_tile "accept" "(done_dialog 1)")
(action_tile "cancel" "(done_dialog 0)")
(setq ans (start_dialog))
(if
(= ans 0)
(progn
(alert (strcat "\nAre you want try again"
"\nplease type sample...and hit enter"))
(unload_dialog dcl_id)
(exit)
) ; progn
(Progn
(setq xdata (nth (atoi data_pl) lst))
(alert (strcat "\nYou choose scale is " xdata))
;(*****PUT HERE YOUR NEXT PROGRAM *****)
) ; progn
) ; if
(princ)
) ; end of program
;-----------------------------------------------------
This is dcl file
test1 : dialog {label = "TEST DIALOG MANAGER";
: column {label = "Select a new value";
: popup_list {key = "pl";}}
spacer;
ok_cancel;}
CAB2k
2006-03-24, 11:58 PM
Here is my shot at it. Needs work. :)
;; Use a edit box over a pick list so the user may pick from the list
;; or enter a value
(defun c:test1 (/ lst dcl_id choice dclexit)
(setq lst '("first item" "second item" "third item" "forth item" "fith item"))
(setq dcl_id (load_dialog "Test-1.DCL"))
(if (new_dialog "test1" dcl_id)
(progn
(start_list "pk_value")
(mapcar 'add_list lst)
(end_list)
(action_tile "pk_value" "(set_tile \"usr_value\" (nth (atoi $value) lst)))")
(action_tile "accept" "(setq choice (get_tile \"usr_value\"))(done_dialog 1)")
(action_tile "cancel" "(setq choice \"\")(done_dialog 0)")
(setq dclexit (start_dialog))
(unload_dialog dcl_id)
(if (= choice "")(setq choice "none"))
(prompt (strcat "\n*** selected " choice " ***"))
)
(prompt (strcat "\n*** User Quit ***"))
)
(princ)
)
This is dcl file, save as Test-1.DCL
test1 : dialog {label = "TEST DIALOG MANAGER";
: column {label = "Select a new value";
: edit_box { key = "usr_value";}
: popup_list {key = "pk_value";}}
spacer;
ok_cancel;}
rkmcswain
2006-03-25, 03:33 PM
Here is alternative version of the version provided by CAB2k. This method creates the DCL file during run-time. This provides two advantages.
You don't have to provide a separate DCL file.
You can alter the properties of the DCL file based on decisions made earlier in the lisp file.
(defun test1:mkdialog ( / fp)
(setq fn (strcat (getenv "temp") "\\test1.dcl"))
(setq fp (open fn "w"))
(write-line "test1 : dialog {label = \"TEST DIALOG MANAGER\";" fp)
(write-line " : column {label = \"Select a new value\";" fp)
(write-line " : edit_box { key = \"usr_value\";}" fp)
(write-line " : popup_list {key = \"pk_value\";}}" fp)
(write-line " spacer;ok_cancel;}" fp)
(close fp)
)
(defun c:test1 (/ lst dcl_id choice dclexit)
(test1:mkdialog)
(setq lst '("first item" "second item" "third item" "fourth item" "fifth item"))
(setq dcl_id (load_dialog fn))
(if (new_dialog "test1" dcl_id)
(progn
(start_list "pk_value")
(mapcar 'add_list lst)
(end_list)
(action_tile "pk_value" "(set_tile \"usr_value\" (nth (atoi $value) lst)))")
(action_tile "accept" "(setq choice (get_tile \"usr_value\"))(done_dialog 1)")
(action_tile "cancel" "(setq choice \"\")(done_dialog 0)")
(setq dclexit (start_dialog))
(unload_dialog dcl_id)
(if (= choice "")(setq choice "none"))
(prompt (strcat "\n*** selected " choice " ***"))
)
(prompt (strcat "\n*** User Quit ***"))
)
(princ)
)
Have a good one.
CAB2k
2006-03-25, 07:27 PM
That's a good idea to incorporate the dcl, especially when the end user is not familiar with lisp & dcl files.
The attached lisp is what I use to create the lisp routine from a dcl file.
See the notes in the header for more information.
cadconcepts
2006-03-26, 06:30 AM
To All-
Thank you all for the great suggestions. I will try them out and let you know if I have any problems. Again, thanks.
Manuel
Terry Cadd
2006-06-15, 12:56 AM
Manuel,
I’m new to AUGI and I came across your topic from a few months back, and would like to add a function that I had written a few years ago for my company. I was asked to find a way of adding additional items to a dialog list, if the engineer wanted to choose something other than the default dialog list choices. They wanted it to work similar to what you can do with a VBA list, by selecting an item from the list or just typing in something else. This version is very generic, but additional checks can be added to insure that the user is adding the correct type of items, such as integers or real numbers within a specified range.
Here’s my “Other” version.
Terry Cadd
; c:Test3
(defun c:Test3 (/ ans data_pl dcl_id OtherList)
(defun OtherList (SentList SentVar / AddOther Other SubList SubVar)
(setq SubList (eval (read SentList))
SubVar (eval (read SentVar))
)
(if (= (nth (atoi $value) SubList) "")
(setq $value (itoa (- (length SubList)(length (member SubVar SubList)))))
)
(if (= (nth (atoi $value) SubList) "Other")
(progn
(setq Other (EditValue "Enter Other Value" SubVar))
(if (not Other) (setq Other ""))
(if (= (strcase Other) "OTHER") (setq Other ""))
(if (/= Other "")
(progn
(setq AddOther t)
(foreach Item SubList
(if (= (strcase Other) (strcase Item))
(setq $value (itoa (- (length SubList)(length (member Item SubList))))
AddOther nil)
)
)
(if AddOther
(setq SubList (append (append (reverse (cdr (cdr (reverse SubList))))(list Other))(list "" "Other"))
$value (itoa (- (length SubList)(length (member Other SubList)))))
)
)
(setq $value (itoa (- (length SubList)(length (member SubVar SubList)))))
)
)
)
(setq SubVar (nth (atoi $value) SubList))
(start_list $key) (mapcar 'add_list SubList)(end_list)
(set_tile $key $value)
(set (read SentList) SubList)
(set (read SentVar) SubVar)
);defun OtherList
; With a List with Other include the blank ""))
(setq lst '("1 : 1" "1 : 2" "1 : 3" "1 : 4" "1 : 5" "" "Other"))
(setq data_pl (nth 0 lst))
(setq dcl_id (load_dialog "Test3.dcl"))
(if (not (new_dialog "Test3" dcl_id)) (exit))
(start_list "pl")(mapcar 'add_list lst)(end_list)
(action_tile "pl" "(OtherList \"lst\" \"data_pl\")");Change variables & keep \"s
(setq ans (start_dialog))
(unload_dialog dcl_id)
(if (= ans 0) (exit))
(princ (strcat "\n" data_pl))
(princ)
);defun c:Test3
; EditValue
(defun EditValue (Title Value / Dcl_Id Return)
(setq NewValue Value)
(setq Dcl_Id (load_dialog "Test3.dcl"))
(if (not (new_dialog "EditValue" Dcl_Id)) (exit))
(set_tile "Title" Title)
(set_tile "Prompt" "Value:")
(set_tile "Text" Value)
(action_tile "accept" "(setq NewValue (get_tile \"Text\")) (done_dialog 1)")
(action_tile "Cancel" "(done_dialog)")
(setq Return (start_dialog))
(unload_dialog Dcl_Id)
(if (= Return 0) (setq NewValue nil))
NewValue
);defun EditValue
(princ)
- - - - - - - -
// Test3.dcl
dcl_settings : default_dcl_settings { audit_level = 3; }
Test3 : dialog {
label = "Test Dialog";
spacer;
: text {
label = "Select a new value";
}
: popup_list {
key = "pl";
}
spacer;
: row {
: column {
: ok_button {
alignment = right;
width = 11;
}
}
: column {
: cancel_button {
alignment = left;
width = 11;
}
}
}
}// Test3
EditValue : dialog {
key = "Title";
label = "";
initial_focus = "Text";
spacer;
: row {
: column {
width = 7;
fixed_width = true;
spacer;
: column {
: text {
key = "Prompt";
label = "";
alignment = left;
}
}
}
: edit_box {
key = "Text";
edit_width = 14;
fixed_width = true;
}
}
spacer;
: row {
: column {
: ok_button {
alignment = right;
width = 11;
}
}
: column {
: cancel_button {
alignment = left;
width = 11;
}
}
}
}// EditValue
[ Moderator Action = ON ] How do I use [ CODE ] tags? (http://forums.augi.com/misc.php?do=bbcode#code) [ Moderator Action = OFF ]
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.