The AutoLi AutoLisp sp Tu Tutorial torial - DCL DCL Dialog Control Language Getting Started I'm not not going going to explain everything there is to know about about Dialog Dialog Control Control Language. There are plenty plenty of books on the subject. I will attempt to give you a goo unerstaning of how DCL interacts with !utoLisp. !utoLisp. "ou shoul be able to write your first DCL riven !utolisp !utolisp program in no time.
#ere is the basic orer for things to happen insie the !utoLisp file$ (defun C:MyProgram()
% Define the main program
(defun myFunction1() save&ars
% Define the functions you nee like
;do stuff here ) (defun myFunction2() ;do stuff here ) (setq list1(list "a" "b" "c" "d")) % uil the list if any are re(uire (setq list2(list "1" "2" "" "!")) (setq list(list "" "y" "#"))
load$dialog
%Loa the DCL file
ne%$dialog DCL file
%Loa the DCL efinition insie the
start$list add$list end$list
%)ut the list in the ialog box
start$list add$list end$list
%!s many list as you nee
set$tile
mode$tile necessary,
% *et the tiles +if necessary, % -nable or isable tiles +as
%*et up as many action tiles as you nee.
(action$tile "acce&t" "(myFunction1)(done$dialog 2)") (action$tile "cancel" "(myFunction2)(done$dialog 1)")
%Two action tiles nee to have the oneialog call. /ne of these nees to save the settings before % the oneialog call.
(setq d(start$dialog))
% *tart the ialog box
unload$dialog
% 0nloa the ialog box
% Do stuff if the user presses the cancel key
(if (' d 1)
load$dialog
%Loa the DCL file
ne%$dialog DCL file
%Loa the DCL efinition insie the
start$list add$list end$list
%)ut the list in the ialog box
start$list add$list end$list
%!s many list as you nee
set$tile
mode$tile necessary,
% *et the tiles +if necessary, % -nable or isable tiles +as
%*et up as many action tiles as you nee.
(action$tile "acce&t" "(myFunction1)(done$dialog 2)") (action$tile "cancel" "(myFunction2)(done$dialog 1)")
%Two action tiles nee to have the oneialog call. /ne of these nees to save the settings before % the oneialog call.
(setq d(start$dialog))
% *tart the ialog box
unload$dialog
% 0nloa the ialog box
% Do stuff if the user presses the cancel key
(if (' d 1)
;do stuff here if cancel %as &ressed ) % Do stuff if the user presses the accept key
(if (' d 2) ;do stuff here if oay %as &ressed ) )
% close the program
1e will iscuss this in etail later on.
I've foun the harest thing to get a grip on is laying laying out the ialog ialog box. )lease take take a look at the rows an columns section if you nee help with laying out a ialog box. 2or now let's look at the basics. 1e 1e will cover these items items first$ button3 row3 row3 column3 column3 boxerow3 an boxecolumn. Okay and Cancel Buttons 4 The DCL coe for a these buttons look like this$
: button { key = "accept"; assigne to this button, label = " Okay "; button. is_default = true; presses the enter key. key. }
: button { key = "cancel"; the button., label = " Cancel "; is_default = false;
55 Define the button 55 Define the action key +This is my name 55 This is the text isplaye on the 55 !llows the button to activate when the user 55 Close the button efinition
55 Define another button 55 Define the action key. +I chose this name for 55 Text isplaye on the button. 55 Does not allow this key to activate when the
enter key is presse. is_cancel = true; is selecte. }
55 !ctivate this key when the close button 6 7 8 55 Close the button efinition
Rows and Columns esignate areas to lay your controls on. 6Controls are list boxes3 eit boxes3 buttons3 etc. 8.
#ere is the DCL coe for a column$
: column { } #ere is the DCL coe for a row$
: row { } *imple right9
ere is the code !or a column with two "uttons# : column { : button { key = "accept"; label = " Okay "; is_default = true; } : button { key = "cancel"; label = " Cancel "; is_default = false; is_cancel = true; } }
:otice the buttons are stacke on top of each other.
ere is the code !or a row with two "uttons# : row { : button { key = "accept"; label = " Okay "; is_default = true; } : button { key = "cancel"; label = " Cancel "; is_default = false; is_cancel = true; }
:otice the buttons are sie by sie.
}
Let$s turn the a"o%e into Bo&ed Rows and Bo&ed Columns' ere is the code !or a "o&ed(column with two "uttons# : boxed_column { : button { key = "accept"; label = " Okay "; is_default = true; } : button { key = "cancel"; label = " Cancel "; is_default = false; is_cancel = true; } }
:otice the box aroun the buttons.
ere is the code !or a "o&ed(row with two "uttons# : boxed_row { : button { key = "accept"; label = " Okay "; is_default = true; } : button { key = "cancel"; label = " Cancel "; is_default = false; is_cancel = true; }
:otice the box aroun the buttons.
}
:ow we know the ifference between a row an a boxerow. 1e also know that controls insie a column get stacke on top of each other 6 vertical 8 an controls insie a row are next to each other 6 hori;ontal 8. Important$ "ou shoul never ever attempt to buil a ialog box without a cancel button.
O%er%iew Let's take a look at the entire coe for the ialog box above3 incluing the L*) file$ DCL 2IL- :!<-D$ DCLT-*T.DCL DCLT-*T.lsp DC_!#! : dialo$ { : boxed_row { : button { key = "accept";
!0T/LI*) )=/>=!< :!<-D$
(defun C:C*$+,-+() (if(not(setq dcl$id (load$dialog "C*$+,-+.dcl"))) (&rogn (alert "+he C* file could not be loaded.") (eit) ) (&rogn (if (not (ne%$dialog "C*$+,-+" dcl$id)) (&rogn (alert "+he definition could not be found inside the
label = " Okay "; is_default = true; } : button { key = "cancel"; label = " Cancel "; is_default = false; is_cancel = true; } }
C* file") (eit) ) (&rogn (action$tile "cancel" "(done$dialog 1)") (action$tile "acce&t" "(done$dialog 2)") (setq ddiag(start$dialog)) (unload$dialog dcl$id) (if (' ddiag 1) (&rinc "/n /n ...C*$+,-+ Cancelled. /n ") ) (if (' ddiag 2) (alert "0ou &ressed the 30 button4") ) ) ) ) ) (&rinc) )
}
AutoL)S* Let's take a look at the !utoLisp part of this simple program. 2irst we efine our program$ (defun C:C*$+,-+()
The secon thing was to loa the DCL file from isk. Insert a path if necessary3 but I always like to use the autoca search path to fin the file. :otice the cli variable use. 1e will nee this later on. This ientifies the file opene. ;;;555 *oad the dialog file from dis into memory (setq dcl$id (load$dialog "C*$+,-+.dcl")) 0ou can im&ro6e this %ith a little error checing: (if(not (setq dcl$id (load$dialog "C*$+,-+.dcl"))) (&rogn (alert "+he file could not be loaded.") (eit)
) )
*ince a DCL file can contain multiple ialog box efinitions3 6 I'll show you an example later on. 8 we nee to specify which ialog box we want to loa. This is taken care of in the next statement. :otice the name matches the efinition insie the DCL file. ;;;555 -ee if the C* definition is found inside the C* file (ne%$dialog "C*$+,-+" dcl$id) 0ou can in&ro6e this %ith a little error checing:
(if (not (ne%$dialog "C*$+,-+" dcl$id)) (&rogn (alert "+he C* definition could not be found inside the C* file.") (eit) ) )
The only problem with the above metho is if the DCL file fails to loa into memory you will get an alert stating the file i not loa. That's not a problem3 but you will also get an alert saying the Definition coul not be foun. 1e on't want both popping up. *o3 change the above to be neste3 like this$ ;;;555 +ry to load the C* file from dis into memory (if(not(setq dcl$id (load$dialog "C*$+,-+.dcl"))) (&rogn (alert "+he C* file could not be loaded.") (eit) )
;;;555 ,lse7 the C* file %as loaded into memory (&rogn ;;;555 +ry to load the definition inside the C* file (if (not (ne%$dialog "C*$+,-+" dcl$id)) (&rogn (alert "+he definition could not be found inside the C* file") (eit) ) ;;;555 ,lse7 the definition %as loaded7 %e are ready to roll (&rogn ;;;555 Put action eys here
) ) ) )
:ext3 we efine our action keys. These tell the program what to o whenever a user presses a button3 selects an item in a list3 etc. :otice the two action keys. ?cancel? an ?accept? . These match the keys in the DCL file. I mae these names up. "ou can name them whatever you want as long as it is not a name use by !utoC!D an it only appears once in each DCL efinition. "ou can't have two controls with the same key3 the program woul get confuse. *o woul I@@@ 1henever the user presses the cancel ke y3 the oneialog statement returns the value of A the startialog statement an closes the ialog box. 0pon pressing the /kay button3 6 key B accept 83 the oneialog program returns the value of to the startialog statement an closes the ialog box. That's it. :othing else to a3 except you coul have just about anything in here3 incluing instructions to execute a function 6 I'll emonstrate that later. 8
;;;555 8f an action e6ent occurs7 do this function (action$tile "cancel" "(done$dialog 1)") (action$tile "acce&t" "(done$dialog 2)")
2inally3 the big step. -verything is efine3 let's isplay the ialog box an set up the variable to hol the value returne from the oneialog statement.
;;;555 is&lay the dialog bo (setq ddiag(start$dialog))
The program halts here until the ialog box is issue a ?oneialog? call. In the mean time the user is interacting with the action keys. 1hen the user presses a button the program kills the ialog box with the unloaialog call. :otice the cli passe as a parameter. "ou coul have more than one ialog file open at one time. *o3 the unloaialog function nees to know which one to unloa.
;;;555 9nload the dialog bo from memory (unload$dialog dcl$id)
2inally the ialog box is gone. 1hat next9 2in out which button the user presse9 -xactly@ =emember the oneialog was setup to return either A or . The startailog statement set this value to the variable iag. 1e will use that now to etermine which button was presse.
;;;555 8f the cancel button %as &ressed 5 dis&lay message (if (' ddiag 1) (&rinc "/n /n ...C*$*-P Cancelled. /n ") ) ;;;555 8f the "ay" button %as &ressed (if (' ddiag 2) (alert "0ou &ressed the ay button4") )
!n the last step3 close the autolisp program.
(&rinc) )
The "asic DCL and AutoLisp model I will now give you the moel I use for EF of all ialog base programs I write. I start with this basic program an buil from there. It is basically the same thing we've gone over before. I put up a ialog box. I allow the user to press buttons an manipulate ata. The only ifference is3 when the user presses the /G!" button I save the settings in the ialog file before it closes. I o this insie the action key call with a function calle save&ars. 1ithout further ao3 here's the moel$
The DCL +odel# ,3MP*, : dialog label ' ",3MP*,.ls&"; ialog box initial$focus ' "tet6al"; focus : column : ro% : boed$column : edit$bo control 4 *omething new@ ey ' "tet6al";
55 )uts a label on the 55 *ets the initial
55 The eitbox
label ' "+et
> > : ro% : boed$ro% : button ey ' "acce&t"; label ' " ay "; is$default ' true; > : button ey ' "cancel"; label ' " Cancel "; is$default ' false; is$cancel ' true; > > > > >
The AutoLisp +odel# ;;;555 ,3MP*,.ls& 5 +et Find (defun sa6e
) (defun C:,3MP*,() ;;;555 +ry to load the C* file from dis into memory (if(not(setq dcl$id (load$dialog "C*$+,-+.dcl"))) (&rogn (alert "+he C* file could not be loaded.") (eit) )
;;;555 ,lse7 the C* file %as loaded into memory (&rogn ;;;555 +ry to load the definition inside the C* file
(if (not (ne%$dialog "C*$+,-+" dcl$id)) (&rogn (alert "+he definition could not be found inside the C* file") (eit) )
;;;555 ,lse7 the definition %as loaded7 %e are ready to roll (&rogn
;;;555 8f an action e6ent occurs7 do this function (action$tile "cancel" "(done$dialog 1)") (action$tile "acce&t" "(sa6e
Screen Shot#
If you coul not follow some of the autolisp functions3 you can ignore them for now or rea the !utolisp Tutorial. This is the moel. &ery little will change from this setup. "ou may a some controls to the DCL file which in turn will a !ction calls an influence the number of lines insie the save&ars routine. The only other thing that will change is insie the
/G!" button function. 6 1hen iag B 8. "ou will have to tell the program what to o when all of the information is gathere. 1e will cover these later. ack
The AutoLisp Tutorial - DCL Dialog Control Language - *art , *art , - Buttons
Let's buil a working DCL file showing us exactly how to hanle buttons. 1e will buil a DCL file containing three buttons plus a Close 6 Cancel 8 button. -ach of the three buttons will isplay a message when presse.
Layout thoughts# I will place the buttons in a column3 +stacke on top of each other,. Then I'll put the Close button at the bottom on a row of it's own. *o...I'll nee something like this$
: column : boed$column : button ?? Put code for button 1 here > : button @ ?? Put code for button 2 here > : button @ ?? Put code for button here > > : boed$ro% : button
?? Put code for the Close button here > > >
Let's copy in the coe for the heaer an all of the controls above. I'll show them in re. :otice the key names an labels ha to be change.
-3MP*,1 : dialog label ' "-am&le ialog Ao Boutine 5 Part 1"; : column : boed$column : button ey ' "but1"; label ' "Autton 1"; is$default ' false; > : button ey ' "but2"; label ' "Autton 2"; is$default ' false; > : button ey ' "but"; label ' "Autton "; is$default ' false; > > : boed$ro% : button ey ' "cancel"; label ' "Close"; is$default ' true; is$cancel ' true; > > > >
Right click and copy the a"o%e' Open ote*ad and paste it' Sa%e the !ile as SA+*L.,'DCL Be sure to change the "Save as Type" drop down box to "All Files" before saving it or it will put a ".txt" extension on the file name. Save this file somewhere in the AutoCA search path.
:ext we will get a copy of the !utoLisp moel an revise it. !ll new coe is shown in re. (defun C:-3MP*,1() ;;;555 *oad the dcl file from dis to memory (if(not(setq dcl$id (load$dialog " -3MP*,1.dcl"))) (&rogn (alert "+he C* file could not be loaded.") (eit) ) (&rogn ;;;555 *oad the C* definition inside the C* file (if (not (ne%$dialog " -3MP*,1" dcl$id)) (&rogn (alert "+he -3MP*,1 definition could not be found inside the C* file4") (eit) ) ;;;555 ,lse7 the definition %as loaded (&rogn
;;;555 8f an action e6ent occurs7 do this function (action$tile "cancel" "(done$dialog)") ;;;555 is&lay the dialog bo (start$dialog)
;;;555 9nload the dialog bo (unload$dialog dcl$id) ) ) ) ) ;;;555 -u&&ress the last echo for a clean eit (&rinc)
)
I remove several lines from the moel. I took out the part that checke to see if we hit the Cancel or /kay buttons. 1e on't nee either in this program. I also remove the action tile for the okay button3 remove ?set( iag? from the startialog statement3 an remove the value to return from the oneialog statement. Right click and copy the a"o%e' Open ote*ad and paste it' Sa%e the !ile as SA+*L.,'LS* Be sure to change the "Save as Type" drop down box to "All Files" before saving it or it will put a ".txt" extension on the file name. Save this file somewhere in the AutoCA search path.
Let's loa the program an see what the DCL file looks like. /n the comman line type this$ Comman$ +loa ?sampleA?, an press enter "ou shoul see this C$*ampleA Comman$ :ow type *ampleA an press enter. If everything went accoring to plan you shoul see this on your screen$
The buttons o not work yet. -xcept for the close button. It shoul work fine. 1e nee to a the function to print three ifferent messages when the user presses each button. Let's sen a parameter to the function to ecie which message to isplay. If the parameter e(uals A we will print the first message. If then print the secon message. If H print the thir message. *omething like this$ (defun doAutton(a) (cond ((' a 1)(alert "Autton 1 %as &ressed4")) ((' a 2)(alert "Autton 2 %as &ressed4")) ((' a )(alert "Autton %as &ressed4")) ) )
:ow we nee to a the action calls for each of the buttons$ (action$tile "but1" "(doAutton 1)") (action$tile "but2" "(doAutton 2)") (action$tile "but" "(doAutton )")
This will sen a parameter of A33 or H to the outton function epening on which button is presse.
Let's a the outton function an the action calls to the autolisp program. It shoul look like this$ (defun doAutton(a) (cond ((' a 1)(alert "Autton 1 %as &ressed4")) ((' a 2)(alert "Autton 2 %as &ressed4")) ((' a )(alert "Autton %as &ressed4")) ) ) (defun C:-3MP*,1() ;;;555 *oad the dcl file from dis into memory (if(not(setq dcl$id (load$dialog "-3MP*,1.dcl"))) (&rogn (alert "+he C* file could not be loaded.") (eit) ) ;;;555 ,lse7 the file %as loaded
(&rogn
;;;555 *oad the dialog definition inside the C* file (if (not (ne%$dialog "-3MP*,1" dcl$id)) (&rogn (alert "+he -3MP*,1 definition could not be found in the C* file4") (eit) ) ;;;555 ,lse7 the definition %as loaded (&rogn ;;;555 8f an (action$tile (action$tile (action$tile (action$tile
action e6ent occurs7 do this function "but1" "(doAutton 1)") "but2" "(doAutton 2)") "but" "(doAutton )") "cancel" "(done$dialog)")
;;;555 is&lay the dialog bo (start$dialog)
;;;555 9nload the dialog bo (unload$dialog dcl$id) ) ) ) ) ;;;555 -u&&ress the last echo for a clean eit (&rinc) )
*ave it an test it out. -verything working okay9
1hen you get your program teste an everything is working3 move the blue line above3 6 (defun C:-3MP*,1() 8 all the way to the top of the file. This will make all of your variables local an will reset them all to nil when the program ens. That's it. 1e're one. ack
The AutoLisp Tutorial - DCL Dialog Control Language - *art / *art / - .dit(Bo&
Let's buil a working DCL file showing us exactly how to hanle eit boxes. 1e will buil a DCL file containing two eit boxes plus a /kay an Cancel button. The information in the two eit boxes will be isplaye after selecting the /kay button.
Layout thoughts# I will place the eit boxes in a column3 +stacke on top of each other,. Then I'll put the /kay an Cancel buttons at the bottom in a row. *o...I'll nee something like this$
: column : boed$column : edit$bo ?? Put code for edit$bo 1 here > : edit$bo ?? Put code for edit$bo here >
> : boed$ro% : button ?? Put code for the ay button here > : button ?? Put code for the Cancel button here > > >
Let's copy in the coe for the heaer an all of the controls above. I'll show them in re. :otice the key names an labels ha to be change.
-3MP*,2 : dialog label ' "-am&le ialog Ao Boutine 5 Part 2"; : column : boed$column : edit$bo ey ' "username"; label ' ",nter your ame:"; edit$%idth ' 1D; 6alue ' ""; initial$focus ' true; > : edit$bo ey ' "userage"; label ' ",nter your 3ge:"; edit$%idth ' 1D; 6alue ' ""; > > : boed$ro% : button ey ' "acce&t"; label ' " ay "; is$default ' true; > : button ey ' "cancel";
label ' " Cancel "; is$default ' false; is$cancel ' true; > > > > Right click and copy the a"o%e' Open ote*ad and paste it' Sa%e the !ile as SA+*L./'DCL Be sure to change the "Save as Type" drop down box to "All Files" before saving it or it will put a ".txt" extension on the file name. Save this file somewhere in the AutoCA search path.
:ext we will get a copy of the !utoLisp moel an revise it. !ll new coe is shown in re. (defun C:-3MP*,2() ;;;555 *oad the dcl file from dis into memory (if(not(setq dcl$id (load$dialog " -3MP*,2.dcl"))) (&rogn (alert "+he C* file could not be loaded4") (eit) )
;;;555 ,lse7 the dcl file %as loaded into memory (&rogn ;;;555 *oad the definition inside the C* file (if (not(ne%$dialog " -3MP*,2" dcl$id)) (&rogn (alert "+he -3MP*,2 definition could not be loaded4") (eit) ) ;;;555 ,lse7 the definition %as loaded (&rogn ;;;555 8f an action e6ent occurs7 do this function (action$tile "acce&t" " (sa6e
;;;555 is&lay the dialog bo (setq ddiag(start$dialog)) ;;;555 9nload the dialog bo (unload$dialog dcl$id) ;;;555 8f the user &ressed the Cancel button (if(' ddiag 1) (&rinc "/n -am&le2 cancelled4") ) ;;;555 8f the user &ressed the ay button (if(' ddiag 2) (&rogn (&rinc "/n +he user &ressed ay4") ) )
) ) ) ) ;;;555 -u&&ress the last echo for a clean eit (&rinc) )
Right click and copy the a"o%e' Open ote*ad and paste it' Sa%e the !ile as SA+*L./'LS* Be sure to change the "Save as Type" drop down box to "All Files" before saving it or it will put a ".txt" extension on the file name. Save this file somewhere in the AutoCA search path.
Let's loa the program an see what the DCL file looks like. /n the comman line type this$ Comman$ +loa ?sample?, an press enter "ou shoul see this C$*ample Comman$ :ow type *ample an press enter. If everything went accoring to plan you shoul see this on your screen$
Looking goo so far. 1e nee to a the *ave&ars *ave&ars function function to save the strings in the eit boxes when the /kay button is presse. Look at the blue text in the Sample2.lsp program above. The eit box box for the name name nees to be a string. Dialog boxes return return strings3 so we o not nee to moify it. !ll we have to o is use the gettile gettile function. (setq userame(get$tile "username"))
The eit box for !ge !ge nees to be an integer. 1e will have to moify the gettile results by using the !T !T/I function. This function converts a string to an integer. (setq user3ge( atoi (get$tile "userage")))
If we needed to convert to an Real number we would would use DIST! function function instead of the "TI function. /ur *ave&ars routine woul look like this$ (defun sa6e
/ur program woul now look like this$ (defun sa6e
(setq user3ge(atoi(get$tile "userage"))) ) (defun C:-3MP*,2() ;;;555 *oad the dcl file from dis into memory (if(not(setq dcl$id (load$dialog "-3MP*,2.dcl"))) (&rogn (alert "+he C* file could not be loaded4") (eit) ) ;;;555 ,lse7 the dcl file %as loaded into memory (&rogn
;;;555 *oad the definition inside the C* file (if (not(ne%$dialog "-3MP*,2" dcl$id)) (&rogn (alert "+he -3MP*,2 definition could not be loaded4") (eit) )
;;;555 ,lse7 the definition %as loaded (&rogn
;;;555 8f an action e6ent occurs7 do this function (action$tile "acce&t" "(sa6e
;;;555 8f the user &ressed the Cancel button (if(' ddiag 1) (&rinc "/n -am&le2 cancelled4") ) ;;;555 8f the user &ressed the ay button (if(' ddiag 2) (&rogn (&rinc "/n +he user &ressed ay4") ) )
) ) ) ) ;;;555 -u&&ress the last echo for a clean eit
(&rinc) )
Last item. 1e nee to replace the line in the program$ (&rinc "/n +he user &ressed ay4") with something something to moify an isplay the the user:ame an user!ge ata. Let's o something something simple. 1e will will fin out how how many ays ol this person is. ;;;555 8f the user &ressed the ay button (if(' ddiag 2) (&rogn ;;;555 Multi&ly the users age ED to get the number of days. (setq user3ge( user3ge ED)) ;;;555 is&lay the results (alert (strcat userame " is " (itoa user3ge) " days old.")) ) )
! the above to the file3 save it an test it out. -verything working working okay9
1hen you get your program teste an everything is working3 move the blue line above3 6 (defun C:-3MP*,2() 8 all the way to the top top of the file. This will make make all of your variables local an will reset them all to nil when the program ens. That's it. 1e 1e're 're one. ack
The AutoLisp Tutorial - DCL Dialog Control Language - *art 0 *art 0 - List(Bo&
Let's buil a working DCL file showing us exactly how to hanle list boxes. 1e will buil a DCL file containing two list boxes plus an /kay an Cancel button. 1e will set the first list box to single selection an the secon to multiple selection. The selecte items will be isplaye on the screen after the user presses the /kay button.
Layout thoughts# I will place the list boxes in a row3 +sie by sie,. Then I'll put the /kay an Cancel buttons in a row at the bottom of the ialog box. *o...I'll nee something like this$
: column : boed$ro% : list$bo ?? Put code for list$bo 1 here > : list$bo ?? Put code for list$bo 2 here > > : boed$ro% : button ?? Put code for the ay button here > : button ?? Put code for the Cancel button here >
> >
Let's copy in the coe for the heaer an all of the controls above from the ?Controls? section of this tutorial. I'll show them in re. :otice the key names an labels ha to be change.
-3MP*, : dialog label ' "-am&le ialog Ao Boutine 5 Part "; : column : boed$ro% : list$bo label '"Choose 8tem"; ey ' "mylist1"; height ' 1D; %idth ' 2D; multi&le$select ' false; fied$%idth$font ' true; 6alue ' ""; > : list$bo label '"Choose 8tems"; ey ' "mylist2"; height ' 1D; %idth ' 2D; multi&le$select ' true; fied$%idth$font ' true; 6alue ' ""; > > : boed$ro% : button ey ' "acce&t"; label ' " ay "; is$default ' true; > : button ey ' "cancel"; label ' " Cancel "; is$default ' false;
is$cancel ' true; > > > > Right click and copy the a"o%e' Open ote*ad and paste it' Sa%e the !ile as SA+*L.0'DCL Be sure to change the "Save as Type" drop down box to "All Files" before saving it or it will put a ".txt" extension on the file name. Save this file somewhere in the AutoCA search path.
:ext we will get a copy of the !utoLisp moel an revise it. !ll new coe is shown in re. (defun C:-3MP*,() ;;;555 *oad the dcl file from dis into memory (if(not(setq dcl$id (load$dialog " -3MP*,.dcl"))) (&rogn (alert "+he C* file could not be loaded4") (eit) )
;;;555 ,lse7 the C* file %as loaded (&rogn ;;;555 *oad the dialog definition inside the C* file (if (not(ne%$dialog " -3MP*," dcl$id)) (&rogn (alert "+he -3MP*,.C* file could not be loaded4") (eit) ) ;;;555 ,lse7 the definition %as loaded (&rogn ;;;555 8f an action e6ent occurs7 do this function (action$tile "acce&t" " (sa6e
;;;555 9nload the dialog bo (unload$dialog dcl$id) ;;;555 8f the user &ressed the Cancel button (if(' ddiag 1) (&rinc "/n -am&le cancelled4") ) ;;;555 8f the user &ressed the ay button (if(' ddiag 2) (&rogn (&rinc "/n +he user &ressed ay4") ) )
) ) ) ) ;;;555 -u&&ress the last echo for a clean eit (&rinc) )
Right click and copy the a"o%e' Open ote*ad and paste it' Sa%e the !ile as SA+*L.0'LS* Be sure to change the "Save as Type" drop down box to "All Files" before saving it or it will put a ".txt" extension on the file name. Save this file somewhere in the AutoCA search path.
Let's loa the program an see what the DCL file looks like. /n the comman line type this$ Comman$ (load "sam&le") an press enter "ou shoul see this C$*ampleH Comman$ :ow type *ampleH an press enter. If everything went accoring to plan you shoul see this on your screen$
Looks goo but3 there is nothing to choose. Let's a some ata to the list boxes. 1e will nee two list. 1e will call the list for the first list box myListA an the secon myList.
(setq my*ist1(list "-lectrical" "*tructural" ")lumbing " "2ounation")) (setq my*ist2(list ")lastic" "*teel" "!luminum" "Concrete")) !lrighty then3 we have our list built. !ll we have to o is put them in the ialog box. 1e will use the startlist3 alist3 an enlist functions. *tartlist tells DCL which listbox we are going to eit. The ientification is mae by using the listbox G-". The first list has a key of ?mylistA? an the secon has a key of ?mylist?. *o the startlist function woul look like this$
(start$list "mylist1" ) ; The H means we want to elete the ol contents an start new. :ext we use the alist function to tell DCL which list to put in the listbox. 1e use the mapcar function to apply alist to each member in the list. /ur list for the first listbox is name myListA. *o...
(ma&car Gadd$list my*ist1) 2inally we use the enlist function to tell DCL to isplay the new contents because we are through eiting the list.
(end$list) To look at it all together$
(start$list "mylist1" ) (ma&car Gadd$list my*ist1) (end$list) (start$list "mylist2" ) (ma&car Gadd$list my*ist2) (end$list)
Let's a all of this to the !utoLisp program an see what it looks like. (defun C:-3MP*,() (setq my*ist1(list " -lectrical" "*tructural" ")lumbing" "2ounation")) (setq my*ist2(list " )lastic" "*teel" "!luminum" "Concrete")) ;;;555 *oad the dcl file from dis into memory (if(not(setq dcl$id (load$dialog "-3MP*,.dcl"))) (&rogn (alert "+he C* file could not be loaded4") (eit) )
;;;555 ,lse7 the C* file %as loaded (&rogn ;;;555 *oad the dialog definition if it is not already
loaded
(if (not(ne%$dialog "-3MP*," dcl$id)) (&rogn (alert "+he -3MP*, definition could not be loaded4") (eit) ) ;;;555 ,lse7 the definition %as loaded
(&rogn
(start$list "mylist1" ) (ma&car Gadd$list my*ist1) (end$list)
(start$list "mylist2" ) (ma&car Gadd$list my*ist2) (end$list) ;;;555 8f an action e6ent occurs7 do this function (action$tile "acce&t" " (sa6e
) ) ) ) ;;;555 -u&&ress the last echo for a clean eit (&rinc) )
:otice the location of the re lines. 1e create the list before loaing the ialog box. 1e a the list to the ialog box after it is loae with newialog an before the actiontile statements. This is the orer you shoul use.
Looking goo so far. 1e nee to a the *ave&ars function to save the selecte items from the list boxes when the /kay button is presse. Look at the blue text in the Sample#.lsp program above. Let's steal the save&ars routine from the listbox control on the ?List an how to hanle them? page of this tutorial an moify it. I'll show the moifications in re.
(defun sa6e
1ow@ That was easy. 1ait a minute3 we have two list boxes. 1e will have to create a function out of this or simply copy this an o it twice. 2or now3 let's just o it twice.
/ur program woul now look like this$ (defun sa6e
;;;555 -a6e the list setting mylist%")) (setq readlist(get$tile " ;;;555 -etu& a 6ariable to run through the list (setq count 1) ;;;555 cycle through the list getting all of the selected items (%hile (setq item (read readlist)) (setq retlist(a&&end ret*ist (list (nth item my*ist1)))) (%hile (and (?' " " (substr readlist count 1)) (?' "" (substr readlist count 1)) ) (setq count (1H count)) ) (setq readlist (substr readlist count)) ) ;;;555 -etu& a list to hold the selected items (setq ret*ist2(list)) ;;;555 -a6e the list setting (setq readlist(get$tile "mylist2 ")) ;;;555 -etu& a 6ariable to run through the list (setq count 1) ;;;555 cycle through the list getting all of the selected items (%hile (setq item (read readlist)) (setq retlist2(a&&end ret*ist2 (list (nth item my*ist2)))) (%hile (and (?' " " (substr readlist count 1)) (?' "" (substr readlist count 1)) ) (setq count (1H count)) ) (setq readlist (substr readlist count)) ) )
(defun C:-3MP*,()
(setq my*ist1(list " -lectrical" "*tructural" ")lumbing" "2ounation")) (setq my*ist2(list " )lastic" "*teel" "!luminum" "Concrete")) ;;;555 *oad the dcl file from dis into memory (if(not(setq dcl$id (load$dialog "-3MP*,.dcl"))) (&rogn (alert "+he C* file could not be loaded4") (eit) )
;;;555 ,lse7 the C* file %as loaded (&rogn ;;;555 *oad the definition inside the C* file (if (not(ne%$dialog "-3MP*," dcl$id)) (&rogn (alert "+he -3MP*, definition could not be loaded4") (eit) ) ;;;555 ,lse7 the definition file %as loaded (&rogn
(start$list "mylist1" ) (ma&car Gadd$list my*ist1) (end$list)
(start$list "mylist2" ) (ma&car Gadd$list my*ist2) (end$list) ;;;555 8f an action e6ent occurs7 do this function (action$tile "acce&t" "(sa6e
(if(' ddiag 2) (&rogn (&rinc "/n +he user &ressed ay4") ) )
) ) ) ) ;;;555 -u&&ress the last echo for a clean eit (&rinc) )
Last item. 1e nee to replace the line in the program$ (&rinc "/n +he user &ressed ay4") with something to moify an isplay the selecte items. Let's o something simple. 1e will tell the user what was selecte out of each list.. ;;;555 8f the user &ressed the ay button (if(' ddiag 2) (&rogn ;;;555 8nform the user of his selection from the first list (&rinc (strcat "/n 0ou chose " (car ret*ist) " from the first list bo.")) ;;;555 8nform the user of his selections from the second list (&rinc "/n 0our choice(s) from the second list bo :") (foreach a ret*ist2 (&rinc "/n ") (&rinc a) ) ) )
! the above to the file3 save it an test it out. -verything working okay9
1hen you get your program teste an everything is working3 move the blue line above3 6 (defun C:-3MP*,() 8 all the way to the top of the file. This will make all of your variables local an will reset them all to nil when the program ens. That's it. 1e're one. ack
The AutoLisp Tutorial - DCL
Dialog Control Language - *art 1 *art 1 - *op2p(List
Let's buil a working DCL file showing us exactly how to hanle popup list. 1e will buil a DCL file containing two popup list plus an /kay an Cancel button. The selecte items will be isplaye on the screen after the user presses the /kay button.
Layout thoughts# I will place the popuplist in a row3 +sie by sie,. Then I'll put the /kay an Cancel buttons in a row at the bottom of the ialog box. *o...I'll nee something like this$
: column : boed$ro% : &o&u&$list ?? Put code for &o&u&$list 1 here > : &o&u&$list ?? Put code for &o&u&$list 2 here > > : boed$ro% : button ?? Put code for the ay button here > : button ?? Put code for the Cancel button here > > >
Let's copy in the coe for the heaer an all of the controls above from the ?Controls? section of this tutorial. I'll show them in re. :otice the key names an labels ha to be change.
-3MP*,! : dialog label ' "-am&le ialog Ao Boutine 5 Part !"; : column : boed$ro% : &o&u&$list ey ' "mylist1"; label ' "-elect 8tem"; fied$%idth$font ' true; %idth ' =; 6alue ' ""; > : &o&u&$list ey ' "mylist2"; label ' "-elect 8tem"; fied$%idth$font ' true; %idth ' =; 6alue ' ""; > > : boed$ro% : button ey ' "acce&t"; label ' " ay "; is$default ' true; > : button ey ' "cancel"; label ' " Cancel "; is$default ' false; is$cancel ' true; > > > > Right click and copy the a"o%e' Open ote*ad and paste it' Sa%e the !ile as SA+*L.1'DCL Be sure to change the "Save as Type" drop down box to "All
Files" before saving it or it will put a ".txt" extension on the file name. Save this file somewhere in the AutoCA search path.
:ext we will get a copy of the !utoLisp moel an revise it. !ll new coe is shown in re. (defun C:-3MP*,!() ;;;555 *oad the dcl file from dis into memory (if(not(setq dcl$id (load$dialog " -3MP*,!.dcl"))) (&rogn (alert "+he C* file could not be loaded4") (eit) )
;;;555 ,lse7 the C* file %as loaded (&rogn ;;;555 *oad the definition inside the C* file (if (not(ne%$dialog " -3MP*,!" dcl$id)) (&rogn (alert "+he -3MP*,!.C* file could not be loaded4") (eit) ) ;;;555 ,lse7 the definition %as loaded (&rogn ;;;555 8f an action e6ent occurs7 do this function (action$tile "acce&t" " (sa6e
(if(' ddiag 2) (&rogn (&rinc "/n +he user &ressed ay4") ) )
) ) ) ) ;;;555 -u&&ress the last echo for a clean eit (&rinc) )
Right click and copy the a"o%e' Open ote*ad and paste it' Sa%e the !ile as SA+*L.1'LS* Be sure to change the "Save as Type" drop down box to "All Files" before saving it or it will put a ".txt" extension on the file name. Save this file somewhere in the AutoCA search path.
Let's loa the program an see what the DCL file looks like. /n the comman line type this$ Comman$ (load "sam&le!") an press enter "ou shoul see this C$*ample Comman$ :ow type *ample an press enter. If everything went accoring to plan you shoul see this on your screen$
Looks goo but3 there is nothing to choose. Let's a some ata to the popup list boxes. 1e will nee two list. 1e will call the list for the first popup list box myListA an the secon myList.
(setq my*ist1(list "-lectrical" "*tructural" ")lumbing " "2ounation")) (setq my*ist2(list ")lastic" "*teel" "!luminum" "Concrete")) !lrighty then3 we have our list built. !ll we have to o is put them in the ialog box. 1e will use the startlist3 alist3 an enlist functions. *tartlist tells DCL which popup list box we are going to eit. The ientification is mae by using the popup list box G-". The first popup list box has a key of ?mylistA? an the secon has a key of ?mylist?. *o the startlist function woul look like this$
(start$list "mylist1" ) ; The H means we want to elete the ol contents an start new. :ext we use the alist function to tell DCL which list to put in the popup list box. 1e use the mapcar function to apply alist to each member in the list. /ur list for the first popup list box is name myListA. *o...
(ma&car Gadd$list my*ist1) 2inally we use the enlist function to tell DCL to isplay the new contents because we are through eiting the popup list box.
(end$list) To look at it all together$
(start$list "mylist1" ) (ma&car Gadd$list my*ist1) (end$list) (start$list "mylist2" ) (ma&car Gadd$list my*ist2) (end$list)
Let's a all of this to the !utoLisp program an see what it looks like. (defun C:-3MP*,!() (setq my*ist1(list " -lectrical" "*tructural" ")lumbing" "2ounation")) (setq my*ist2(list " )lastic" "*teel" "!luminum" "Concrete")) ;;;555 *oad the dcl file from dis into memory (if(not(setq dcl$id (load$dialog " -3MP*,!.dcl"))) (&rogn (alert "+he C* file could not be loaded4") (eit) )
;;;555 ,lse7 the C* file %as loaded (&rogn ;;;555 *oad the definition inside the C* file (if (not(ne%$dialog "-3MP*,!" dcl$id)) (&rogn (alert "+he -3MP*,!.C* file could not be loaded4") (eit) ) ;;;555 ,lse7 the definition %as loaded (&rogn
(start$list "mylist1" ) (ma&car Gadd$list my*ist1) (end$list)
(start$list "mylist2" ) (ma&car Gadd$list my*ist2) (end$list) ;;;555 8f an action e6ent occurs7 do this function (action$tile "acce&t" " (sa6e
;;;555 8f the user &ressed the ay button (if(' ddiag 2) (&rogn (&rinc "/n +he user &ressed ay4") ) )
) ) ) ) ;;;555 -u&&ress the last echo for a clean eit (&rinc) )
:otice the location of the re lines. 1e create the list before loaing the ialog box. 1e a the list to the ialog box after it is loae with newialog an before the actiontile statements. This is the orer you shoul use.
Looking goo so far. 1e nee to a the *ave&ars function to save the selecte items from the popup list boxes when the /kay button is presse. Look at the blue text in the Sample$.lsp program above. Let's steal the save&ars routine from the popup list box control on the ?*aving ata from the ialog box? page of this tutorial an moify it. I'll show the moifications in re.
(defun sa6e
1ait a minute3 we have two popup list boxes. 1e will have to create a function out of this or simply copy this an o it twice. 2or now3 let's just o it twice.
/ur program woul now look like this$
(defun sa6e
;;;555 ,lse7 the C* file %as loaded (&rogn ;;;555 *oad the definition inside the C* file
(if (not(ne%$dialog "-3MP*,!" dcl$id)) (&rogn (alert "+he -3MP*,!.C* file could not be loaded4") (eit) )
;;;555 ,lse7 the definition %as loaded (&rogn
(start$list "mylist1" ) (ma&car Gadd$list my*ist1) (end$list)
(start$list "mylist2" ) (ma&car Gadd$list my*ist2) (end$list) ;;;555 8f an action e6ent occurs7 do this function (action$tile "acce&t" "(sa6e
(&rinc "/n +he user &ressed ay4")
) ) ) ) ) ) ;;;555 -u&&ress the last echo for a clean eit (&rinc) )
Last item. 1e nee to replace the line in the program$ (&rinc "/n +he user &ressed ay4") with something to moify an isplay the selecte items. Let's o something simple. 1e will tell the user what was selecte out of each popup list.. ;;;555 8f the user &ressed the ay button (if(' ddiag 2) (&rogn ;;;555 8nform the user of his selection from the first list (&rinc (strcat "/n 0ou chose " my8tem1 " from the first &o&u& list bo.")) ;;;555 8nform the user of his selections from the second list (&rinc (strcat "/n 0ou chose " my8tem2 " from the second &o&u& list bo.")) ) )
! the above to the file3 save it an test it out. -verything working okay9
1hen you get your program teste an everything is working3 move the blue line above3 6 (defun C:-3MP*,!() 8 all the way to the top of the file. This will make all of your variables local an will reset them all to nil when the program ens. That's it. 1e're one. ack
The AutoLisp Tutorial - DCL Dialog Control Language - *art 3 *art 3 - Radio Buttons
Let's buil a working DCL file showing us exactly how to hanle raio buttons. The first thing you nee to know about a raio button is how stupi they are. They have no brains. They o not know what the other raio buttons are oing. "ou can layout six raio buttons an select everyone of them like they were toggles. That's not the way we use raio buttons. They are suppose to be smart. They shoul know what to o if a raio button aroun them is selecte. They shoul turn themselves off because only one raio button in a group is suppose to be checke. That's where raiocolumn an raiorow come in to play. They are the brains for the raio buttons. They watch all the buttons in their row or column to make sure only one is turne on. 1e will buil a DCL file containing raiobuttons plus an /kay an Cancel button. The selecte item will be isplaye on the screen after the user presses the /kay button.
Layout thoughts# I will place the raiobuttons in a column3 +stacke on top of each other,. Then I'll put the /kay an Cancel buttons in a row at the bottom of the ialog box. *o...I'll nee something like this$
: column : radio$column ?? Put code for radio$column here : radio$column ?? Put code for radio$button 1 here > : radio$button ?? Put code for radio$button 2 here > : radio$button ?? Put code for radio$button here > : radio$button ?? Put code for radio$button ! here > > : boed$ro% : button ?? Put code for the ay button here > : button ?? Put code for the Cancel button here > > >
Let's copy in the coe for the heaer an all of the controls above from the ?Controls? section of this tutorial. I'll show them in re. :otice the key names an labels ha to be change.
-3MP*,D : dialog label ' "-am&le ialog Ao Boutine 5 Part D"; : column : radio$column ey ' "mychoice"; : radio$button ey ' "but1"; label ' "3&&les"; > : radio$button
ey ' "but2"; label ' "ranges"; > : radio$button ey ' "but"; label ' "Aananas"; > : radio$button ey ' "but!"; label ' "*emons"; > > : boed$ro% : button ey ' "acce&t"; label ' " ay "; is$default ' true; > : button ey ' "cancel"; label ' " Cancel "; is$default ' false; is$cancel ' true; > > > > Right click and copy the a"o%e' Open ote*ad and paste it' Sa%e the !ile as SA+*L.3'DCL Be sure to change the "Save as Type" drop down box to "All Files" before saving it or it will put a ".txt" extension on the file name. Save this file somewhere in the AutoCA search path.
:ext we will get a copy of the !utoLisp moel an revise it. !ll new coe is shown in re. (defun C:-3MP*,D() ;;;555 *oad the dcl file from dis into memory (if(not(setq dcl$id (load$dialog " -3MP*,D.dcl")))
(&rogn (alert "+he C* file could not be loaded4") (eit) )
;;;555 ,lse7 the C* file %as loaded (&rogn
;;;555 *oad the definition inside the C* file (if (not(ne%$dialog " -3MP*,D" dcl$id)) (&rogn (alert "+he -3MP*,D definition could not be loaded4") (eit) )
;;;555 ,lse7 the definition %as loaded (&rogn ;;;555 8f an action e6ent occurs7 do this function (action$tile "acce&t" " (sa6e
) ) ) ) ;;;555 -u&&ress the last echo for a clean eit (&rinc) )
Right click and copy the a"o%e' Open ote*ad and paste it' Sa%e the !ile as SA+*L.3'LS* Be sure to change the "Save as Type" drop down box to "All Files" before saving it or it will put a ".txt" extension on the file name. Save this file somewhere in the AutoCA search path.
Let's loa the program an see what the DCL file looks like. /n the comman line type this$ Comman$ (load "sam&leD") an press enter "ou shoul see this C$*ampleK Comman$ :ow type *ampleK an press enter. If everything went accoring to plan you shoul see this on your screen$
That oesn't look very goo oes it9 Let's change the boxerow into a boxecolumn in our DCL file. %See the blue text in the D&L file above'
It still oesn't look right. It's our label ?*ample Dialog ox =outine 4 )art K? that is causing the problem. Let's shorten it to ?*D= 4 )art K? an try it again$
Looks better@
Looking goo so far. 1e nee to a the *ave&ars function to save the selecte items from the raiocolumn when the /kay button is presse. Look at the blue text in the Sample(.lsp program above. Let's steal the save&ars routine from the raiocolumn control on the ?*aving ata from the ialog box? page of this tutorial an moify it. I'll show the moifications in re. 1e can o this two ifferent ways. 1e can check each raiobutton to fin out which one is on or we can check the entire column of raiobuttons by getting the value of the raiocolumn. 2irst metho$ Checking the =aioColumn$
(defun sa6e
% M B not chosen % M B not chosen % M B not chosen % M B not chosen
A B chosen A B chosen A B chosen A B chosen
,
*o...1hich one o we use9 2or this tutorial3 let's use both. 1hy not9
(defun sa6e
% M B not chosen % M B not chosen % M B not chosen % M B not chosen
A B chosen A B chosen A B chosen A B chosen
! this to the original *ampleK.lsp program an we shoul have something that looks like this$ (defun sa6e
% M B not chosen % M B not chosen % M B not chosen % M B not chosen
A B chosen A B chosen A B chosen A B chosen
,
(defun C:-3MP*,D() ;;;555 *oad the dcl file from dis into memory (if(not(setq dcl$id (load$dialog "-3MP*,D.dcl"))) (&rogn (alert "+he C* file could not be loaded4") (eit) )
;;;555 ,lse7 the C* file %as loaded (&rogn ;;;555 *oad the definition inside the C* file (if (not (ne%$dialog "-3MP*,D" dcl$id)) (&rogn (alert "+he C* definition could not be loaded4") (eit) ) ;;;555 ,lse7 the definition %as loaded (&rogn ;;;555 8f an action e6ent occurs7 do this function (action$tile "acce&t" "(sa6e
(setq ddiag(start$dialog)) ;;;555 9nload the dialog bo (unload$dialog dcl$id) ;;;555 8f the user &ressed the Cancel button (if(' ddiag 1) (&rinc "/n -am&leD cancelled4") ) ;;;555 8f the user &ressed the ay button (if(' ddiag 2) (&rogn (&rinc "/n +he user &ressed ay4") ) )
) ) ) ) ;;;555 -u&&ress the last echo for a clean eit (&rinc) )
Last item. 1e nee to replace the line in the program$ (&rinc "/n +he user &ressed ay4") with something to isplay the selecte item. ;;;555 8f the user &ressed the ay button (if(' ddiag 2) (&rogn ;;;555 8nform the user of his selection using the radio$column data (&rinc "/n 9sing Badio$column data...0ou chose ") (cond ((' myChoice "but1")(&rinc "3&&les4")) ((' myChoice "but2")(&rinc "ranges4")) ((' myChoice "but")(&rinc "Aananas4")) ((' myChoice "but!")(&rinc "*emons4")) )
;;;555 8nform the user of his selection using the radio$buttons data (&rinc "/n 9sing Badio$buttons data...0ou chose ") (cond ((' Choice1 1)(&rinc "3&&les4")) ((' Choice2 1)(&rinc "ranges4")) ((' Choice 1)(&rinc "Aananas4")) ((' Choice! 1)(&rinc "*emons4")) ) ) )
! the above to the autolisp file3 save it an test it out. -verything working okay9
1hen you get your program teste an everything is working3 move the blue line above3 6 (defun C:-3MP*,D() 8 all the way to the top of the file. This will make all of your variables local an will reset them all to nil when the program ens.
That's it. 1e're one. ack
The AutoLisp Tutorial - DCL Dialog Control Language - *art 4 *art 4 - Te&t and Toggles
Let's buil a working DCL file showing us exactly how to hanle text an toggles. 1e will buil a DCL file containing toggles3 one text3 plus a Cancel button. The selecte item will be isplaye on the screen in the text control.
Layout thoughts# I will place the text control on the top of the box. Then I'll put the toggles in a column3 +stacke on top of each other,. Last3 I'll put the Cancel button at the bottom of the ialog box. *o...I'll nee something like this$
: column : column : tet ?? Put code for > > : boed$column : toggle ?? Put code for > : toggle ?? Put code for > : toggle ?? Put code for
tet here
toggle 1 here
toggle 2 here
toggle here
> : toggle ?? Put code for toggle ! here > > : boed$ro% : button ?? Put code for the Cancel button here > > >
Let's copy in the coe for the heaer an all of the controls above from the ?Controls? section of this tutorial. I'll show the changes that neee to be mae in re. :otice the key names an labels ha to be change.
-3MP*,E : dialog label ' "-am&le ialog Ao Boutine 5 Part E"; : column : column : tet ey ' "tet1"; 6alue ' "othing selected."; > > : boed$column label ' "Choose your lucy charms:"; : toggle ey ' "tog1"; label ' "Kearts"; 6alue ' "="; > : toggle ey ' "tog2"; label ' "Moons"; 6alue ' "="; > : toggle ey ' "tog"; label ' "-tars";
6alue ' "="; > : toggle ey ' "tog!"; label ' "Clo6ers"; 6alue ' "="; > > : boed$ro% : button ey ' "cancel"; label ' "Cancel"; is$default ' true; is$cancel ' true; > > > Right click and copy the a"o%e' Open ote*ad and paste it' Sa%e the !ile as SA+*L.4'DCL Be sure to change the "Save as Type" drop down box to "All Files" before saving it or it will put a ".txt" extension on the file name. Save this file somewhere in the AutoCA search path.
:ext we will get a copy of the !utoLisp moel an revise it. !ll new coe is shown in re. (defun C:-3MP*,E() ;;;555 *oad the dcl file from dis into memory (if(not(setq dcl$id (load$dialog " -3MP*,E.dcl"))) (&rogn (alert "+he C* file could not be loaded4") (eit) )
;;;555 ,lse7 the C* file %as loaded (&rogn ;;;555 *oad the dialog definition inside the C* file (if (not (ne%$dialog " -3MP*,E" dcl$id)) (&rogn (alert "+he -3MP*,E definition could not be loaded4")
(eit) ) ;;;555 ,lse7 the definition %as loaded (&rogn
;;;555 8f an action e6ent occurs7 do this function (action$tile "acce&t" "( sa&e'ars)(done$dialog 2)") (action$tile "cancel" "(done$dialog 1)") ;;;555 is&lay the dialog bo (setq ddiag(start$dialog)) ;;;555 9nload the dialog bo (unload$dialog dcl$id) ;;;555 8f the user &ressed the Cancel button (if(' ddiag 1) (&rinc "/n -am&leE cancelled4") ) ;;;555 8f the user &ressed the ay button (if(' ddiag 2) (&rogn (&rinc "/n +he user &ressed ay4") ) )
) ) ) ) ;;;555 -u&&ress the last echo for a clean eit (&rinc) )
=emove everything liste in orange above. 1e o not nee an /kay button. Thus we o not nee to check to see if the user presse /kay or Cancel. 1e also o not nee the #a&e'ars routine in this program. =emove the orange items so your program looks like the one below. (defun C:-3MP*,E() ;;;555 *oad the dcl file from dis into memory
(if(not(setq dcl$id (load$dialog " -3MP*,E.dcl"))) (&rogn (alert "+he C* file could not be loaded4") (eit) ) ;;;555 ,lse7 the C* file %as loaded (&rogn
;;;555 *oad the dialog definition inside the C* file (if (not (ne%$dialog " -3MP*,E" dcl$id)) (&rogn (alert "+he -3MP*,E definition could not be loaded4") (eit) )
;;;555 ,lse7 the definition %as loaded (&rogn
;;;555 8f an action e6ent occurs7 do this function (action$tile "cancel" "(done$dialog 1)") ;;;555 is&lay the dialog bo (setq ddiag(start$dialog)) ;;;555 9nload the dialog bo (unload$dialog dcl$id) ) ) ) ) ;;;555 -u&&ress the last echo for a clean eit (&rinc) )
Right click and copy the a"o%e' Open ote*ad and paste it' Sa%e the !ile as SA+*L.4'LS* Be sure to change the "Save as Type" drop down box to "All Files" before saving it or it will put a ".txt" extension on the file name. Save this file somewhere in the AutoCA search path.
Let's loa the program an see what the DCL file looks like. /n the comman line type this$ Comman$ (load "sam&leE") an press enter "ou shoul see this C$*ampleN Comman$ :ow type *ampleN an press enter. If everything went accoring to plan you shoul see this on your screen$
Doesn't look right. The ialog box is too wie. It's our label ?*ample Dialog ox =outine 4 )art N? that is causing the problem. I woul shorten it but3 my text control will nee the room if everything is selecte. I'll have to isplay ?#earts
2irst let's write a routine to check each toggle an buil a string representing all of the selecte items.
(defun ch+oggle() (setq (setq (setq (setq (setq (if(' (if(' (if(' (if('
tog1(atoi(get$tile "tog1"))) tog2(atoi(get$tile "tog2"))) tog(atoi(get$tile "tog"))) tog!(atoi(get$tile "tog!"))) my-tr "") tog1 1)(setq tog2 1)(setq tog 1)(setq tog! 1)(setq
my-tr(strcat my-tr(strcat my-tr(strcat my-tr(strcat
% M B not chosen % M B not chosen % M B not chosen % M B not chosen
my-tr " my-tr " my-tr " my-tr "
A B chosen A B chosen A B chosen A B chosen
Kearts"))) Moons"))) -tars"))) Clo6ers")))
;;;555 8f nothing %as selected... (if(' my-tr "")(setq my-tr "othing -elected4")) ;;;555 o% set the tet control to dis&lay the string (set_tile "tet1" my-tr) )
I use the gettile function to get the value of each toggle. I use the atoi function to convert that ata from a string to an integer. %I could have left it a string and checked to see if tog) e*ualled +)+ instead of the number ).' I set the variable my*tr to an empty string an then appene all the checke toggle labels to it. I then change the value of the text control by using the set(tile function. ! this to the top of your autolisp program an save it.
The last step is to a the action calls to the !utoLisp program. 1e nee one action call per toggle switch. -ach action call shoul run the chkToggle function we just create. (action$tile (action$tile (action$tile (action$tile
"tog1" "tog2" "tog" "tog!"
"(c(k!o$$le)") "(c(k!o$$le)") "(c(k!o$$le)") "(c(k!o$$le)")
Let's a this to the !utoLisp program. I'll show the new chkToggle function an the action calls in re. It shoul look like this$
(defun ch+oggle()
(setq (setq (setq (setq
tog1(atoi(get$tile tog2(atoi(get$tile tog(atoi(get$tile tog!(atoi(get$tile
(setq (if(' (if(' (if(' (if('
my-tr "") tog1 1)(setq tog2 1)(setq tog 1)(setq tog! 1)(setq
"tog1"))) "tog2"))) "tog"))) "tog!")))
my-tr(strcat my-tr(strcat my-tr(strcat my-tr(strcat
% M B not chosen % M B not chosen % M B not chosen % M B not chosen
my-tr my-tr my-tr my-tr
" " " "
A B chosen A B chosen A B chosen A B chosen
Kearts"))) Moons"))) -tars"))) Clo6ers")))
;;;555 8f nothing %as selected... (if(' my-tr "")(setq my-tr "othing -elected4")) ;;;555 o% set the tet control to dis&lay the string (set$tile "tet1" my-tr) ) (defun C:-3MP*,E() ;;;555 *oad the dcl file from dis into memory (if(not(setq dcl$id (load$dialog " -3MP*,E.dcl"))) (&rogn (alert "+he C* file could not be loaded4") (eit) )
;;;555 ,lse7 the C* file %as loaded (&rogn ;;;555 *oad the dialog definition inside the C* file (if (not (ne%$dialog " -3MP*,E" dcl$id)) (&rogn (alert "+he -3MP*,E definition could not be loaded4") (eit) ) ;;;555 ,lse7 the definition %as loaded (&rogn (action$tile (action$tile (action$tile (action$tile (action$tile
"tog1" "(ch+oggle)") "tog2" "(ch+oggle)") "tog" "(ch+oggle)") "tog!" "(ch+oggle)") "cancel" "(done$dialog 1)")
;;;555 is&lay the dialog bo (setq ddiag(start$dialog)) ;;;555 9nload the dialog bo (unload$dialog dcl$id) ) ) ) ) ;;;555 -u&&ress the last echo for a clean eit (&rinc) )
*ave it an test it out. -verything working okay9
1hen you get your program teste an everything is working3 move the blue line above3 6 (defun C:-3MP*,E() 8 all the way to the top of the file. This will make all of your variables local an will reset them all to nil when the program ens. That's it. 1e're one. ack
The AutoLisp Tutorial - DCL Dialog Control Language - *art 5 :ow it is time to take all of the parts an pieces an put them together. Let's buil a working DCL file that will let us see most of the things we've learne an yet not get to eep into autolisp. Lets raw a polygon or circle3 on a selecte layer with the option to save the settings last use for efaults next time we run the program. If polygon is chosen3 ask for the number of sies. *o....we will nee a listbox to hol all of the available layer names. 1e will nee a raiocolumn to select a circle or polylgon. 1e will nee an popuplist to hol the number of sies for the polygon. 1e will nee a toggle to check the ?*ave *ettings? option. !n last3 we will nee an /kay an Cancel button.
Layout thoughts# The list will nee to have several layers showing so the user won't have to scroll forever. *o3 it will probably be the tallest item on the ialog box. I'll put it in a column by itself. I'll try to fit the rest of the items in a column besie it. Then I'll put the /kay an Cancel buttons at the bottom in a row. *o...I'll nee something like this$
: column : ro% : boed$column : radio$column : radio$button ?? Put code for radio button 1 here J Circle @ > : radio$button ?? Put code for radio button 2 here J Polygon @ > > : &o&u&$list
?? Put code for &o&u&$list here J umber of -ides @ > : toggle ?? Put code for toggle here
J -a6e -ettings @
> > : ro% : list$bo ?? Put code for list here J *ayer ames @ > > > : ro% : button ?? Put code for button 1 here J ay @ > : button ?? Put code for button 2 here J Cancel @ > > >
Let's copy in the coe for the heaer an all of the controls above. I'll show them in re. :otice the key names an labels ha to be change.
-3MP*,L : dialog label ' "-am&le ialog Ao Boutine 5 Part L"; : column : ro% : boed$column : radio$column ey ' "radios"; : radio$button label ' "ra% Circle"; ey ' "dra%cir";
6alue ' "1"; > : radio$button label ' "ra% Polygon"; ey ' "dra%&ol"; 6alue ' "="; > > : &o&u&$list ey ' "numsides"; label ' "umber of -ides"; %idth ' 2D; fied$%idth$font ' true; > : toggle ey ' "sa6eset"; label ' "-a6e settings"; > > : ro% : list$bo label '"-elect *ayer"; ey ' "layer*ist"; height ' D; %idth ' 1D; multi&le$select ' false; fied$%idth$font ' true; 6alue ' ""; > > > : ro% : button ey ' "acce&t"; label ' " ay "; is$default ' true; > : button ey ' "cancel"; label ' " Cancel "; is$default ' false; is$cancel ' true;
> > > > Right click and copy the a"o%e' Open ote*ad and paste it' Sa%e the !ile as SA+*L.'DCL Be sure to change the "Save as Type" drop down box to "All Files" before saving it or it will put a ".txt" extension on the file name. Save this file somewhere in the AutoCA search path.
:ext we will get a copy of the !utoLisp moel an revise it. !ll new coe is shown in re. (defun C:-3MP*,L() ;;;555 *oad the dcl file from dis into memory (if(not(setq dcl$id (load$dialog " -3MP*,L.dcl"))) (&rogn (alert "+he C* file could not be loaded4") (eit) )
;;;555 ,lse7 the C* file %as loaded (&rogn ;;;555 *oad the definition inside the C* file (if (not (ne%$dialog " -3MP*,L" dcl$id)) (&rogn (alert "+he -3MP*,L definition could not be loaded4") (eit) ) ;;;555 ,lse7 the definition %as loaded (&rogn ;;;555 8f an action e6ent occurs7 do this function (action$tile "cancel" "(done$dialog 1)") (action$tile "acce&t" "(sa6e
(unload$dialog dcl$id) ;;;555 8f the cancel button %as &ressed 5 dis&lay message (if (' ddiag 1) (&rinc "/n /n ... -3MP*,L Cancelled. /n ") ) ;;;555 8f the "ay" button %as &ressed (if (' ddiag 2) (&rinc "/n /n ... -3MP*,L Com&lete4") ) ) ) ) ) ;;;555 -u&&ress the last echo for a clean eit (&rinc) )
Right click and copy the a"o%e' Open ote*ad and paste it' Sa%e the !ile as SA+*L.5'LS* Be sure to change the "Save as Type" drop down box to "All Files" before saving it or it will put a ".txt" extension on the file name. Save this file somewhere in the AutoCA search path.
Let's loa the program an see what the DCL file looks like. /n the comman line type this$ Comman$ +loa ?sampleO?, an press enter "ou shoul see this C$*ampleO Comman$ :ow type *ample an press enter. If everything went accoring to plan you shoul see this on your screen$
:otice there are no items in either list. 1e haven't ae that part yet. !lso notice the Draw Circle is selecte. 1e i that in the DCL file. 1e set the value of that raiobutton to ?A?. 1e i not set the value of the toggle3 so the efault is unchecke. If you push the Cancel button the program will exit normally. If you press the /kay button an error will occur because we have not efine the save&ars routine. 1e have two things left to o. 2irst we nee to buil the list for the popuplist control an the listbox control. Then we nee to a the list to the ialog box.
Instea of builing a function to get all of the layer names into a list3 let's just buil the list manually to keep things simple. /kay...you talke me into it. I'll o it both ways an you can use the one you want. I'm going to use the short version for this tutorial. Long way$ ;;;555 -et u& a list to hold the layer names (setq layer*ist(list)) ;;;555 Iet the first layer name in the dra%ing (setq layr(tblnet "*30,B" +)) ;;;555 3dd the layer name to the list (setq layer*ist(a&&end layer*ist (list(cdr(assoc 2 layr))))) ;;;555 -te& though the layer table to get all layers (%hile (setq layr(tblnet "*30,B")) ;;;555 -a6e each layer name in the list
(setq layer*ist(a&&end layer*ist (list(cdr(assoc 2 layr))))) )
*hort 1ay$ (setq layer*ist(list "=" "8M" "K8," "-+B" "+" ",*"))
1e also nee a list for the polgon's number of sies$ (setq num-ides(list "!" "E" "N" "12" "1E"))
1e nee to a these lines to our autolisp program. ! it just below the newialog call an above the actiontile statements. 1e now nee to uploa the list into the ialog box. *o put these lines just below the lines you just ae. ;;;555 3dd the layer names to the dialog bo (start$list "layerlist" ) (ma&car Gadd$list layer*ist) (end$list) ;;;555 3dd the number of sides to the dialog bo (start$list "numsides" ) (ma&car Gadd$list num-ides) (end$list) 1hen you are one it shoul look like this$ (defun C:-3MP*,L() ;;;555 *oad the dcl file from dis into memory (if(not(setq dcl$id (load$dialog "-3MP*,L.dcl"))) (&rogn (alert "+he C* file could not be loaded4") (eit) )
;;;555 ,lse7 the C* file %as loaded (&rogn ;;;555 *oad the definition inside the C* file (if (not (ne%$dialog "-3MP*,L" dcl$id)) (&rogn (alert "+he -3MP*,L definition could not be loaded4") (eit) ) ;;;555 ,lse7 the definition %as loaded
(&rogn
(setq layer*ist(list "=" "8M" "K8," "-+B" "+" ",*")) (setq num-ides(list "!" "E" "N" "12" "1E"))
;;;555 3dd the layer names to the dialog bo (start$list "layerlist" ) (ma&car Gadd$list layer*ist) (end$list)
;;;555 3dd the number of sides to the dialog bo (start$list "numsides" ) (ma&car Gadd$list num-ides) (end$list) ;;;555 8f an action e6ent occurs7 do this function (action$tile "cancel" "(done$dialog 1)") (action$tile "acce&t" "(sa6e
;;;555 9nload the dialog bo (unload$dialog dcl$id) ;;;555 8f the cancel button %as &ressed 5 dis&lay message (if (' ddiag 1) (&rinc "/n /n ...-3MP*,L Cancelled. /n ") ) ;;;555 8f the "ay" button %as &ressed (if (' ddiag 2) (&rinc "/n /n ...-3MP*,L Com&lete4") ) ) ) ) ) ;;;555 -u&&ress the last echo for a clean eit (&rinc) )
-a6e7 *oad7 and Bun.
0ou should see this:
:ext3 let's buil the *ave&ars routine. 1e will o this by starting with the save&ars routine in the !utoLisp
;;;555 Iet the number of sides selected from the list (setq num-tr(get$tile "numsides")) (if(' num-tr "") (setq num-ides nil) (setq num-ides(nth (atoi num-tr) num-ides)) )
;;;555 -ee if the user %ants to sa6e the settings (setq sa6e-et(atoi(get$tile "sa6eset"))) ;;;555 Iet the selected item from the layer list (setq s-tr(get$tile " layerlist")) ;;;555 8f the inde of the selected item is not "" then something %as selected (if(?' s-tr "") (&rogn ;;;555 -omething is selected7 so con6ert from string to integer (setq s8nde(atoi s-tr))
;;;555 3nd get the selected item from the list (setq layerame(nth s8nde layer*ist))
)
;;;555 ,lse7 nothing is selected (&rogn
;;;555 -et the inde number to 51 (setq s8nde 51) ;;;555 3nd set the name of the selected item to nil (setq layerame nil)
) ) )
ote# *ince we i not specify a efault value for the listbox3 layer:ame will be set to nil if the user oes not select a layer from the list before hitting the /kay button.
*ave3 Loa3 an =un. Check the values after pressing the /kay button by typing an exclamation point an then the variable name on the comman line. -xamples$ To get the layer name type 4layerame an press enter. To get the value of the toggle type 4sa6e-et an press enter.
The only work left on the ialog box is to isable the ?:umber of *ies? popuplist when a circle is selecte. Let's a two actiontiles on both of the raiobuttons. ;;;555 8f an action e6ent occurs7 do this function (action$tile "dra%cir" "(toggleBadio 1)") (action$tile "dra%&ol" "(toggleBadio 2)")
This will sen a parameter of A to the toggle=aio function if the Circle is selecte. It will sen a parameter of to the toggle=aio function if the )olygon is selecte. 1hat the hell is a toggle=aio function9 1e have to create it an put it in our !utoLisp program. Like this$ (defun toggleBadio(a)
;if circle is selected (if(' a 1) (mode$tile "numsides" 1)
;else (mode$tile "numsides" =)
;disable
;enable
) )
*ince our efault for the raio buttons is to raw a circle3 the num*ies popuplist shoul be isable before the ialog box starts. *o just before the actiontile statements we nee to a this line$ (mode$tile "numsides" 1) Co&y7 -a6e7 and Bun.
0ou should see this:
The num*ies popuplist is isable when the circle is selecte. -nable when polygon is selecte. #ere is the !utoLisp program after the lines above were ae$ (defun sa6e
;;;555 Iet the number of sides selected from the list (setq s-tr(get$tile "numsides")) (if(' s-tr "") (setq num-ides nil) (setq num-ides(nth (atoi s-tr) num-ides)) ) ;;;555 -ee if the user %ants to sa6e the settings (setq sa6e-et(atoi(get$tile "sa6eset"))) ;;;555 Iet the selected item from the layer list (setq s-tr(get$tile "layerlist")) ;;;555 8f the inde of the selected item is not "" then something %as selected (if(?' s-tr "") (&rogn ;;;555 -omething is selected7 so con6ert from string to integer (setq s8nde(atoi s-tr)) ;;;555 3nd get the selected item from the list (setq layerame(nth s8nde layer*ist)) ) ;;;555 ,lse7 nothing is selected (&rogn
;;;555 -et the inde number to 51 (setq s8nde 51) ;;;555 3nd set the name of the selected item to nil (setq layerame nil) ) ) ) (defun toggleBadio(a) ;if circle is selected (if(' a 1) (mode$tile "numsides" 1) ;disable ;else (mode$tile "numsides" =) ;enable ) )
(defun C:-3MP*,L() ;;;555 *oad the dcl file from dis into memory (if(not(setq dcl$id (load$dialog "-3MP*,L.dcl"))) (&rogn (alert "+he C* file could not be loaded4") (eit) )
;;;555 ,lse7 the C* file %as loaded (&rogn ;;;555 *oad the definition inside the C* file (if (not (ne%$dialog "-3MP*,L" dcl$id)) (&rogn (alert "+he -3MP*,L definition could not be loaded4") (eit) ) ;;;555 ,lse7 the definition %as loaded (&rogn (setq layer*ist(list "=" "8M" "K8," "-+B" "+" ",*")) (setq num-ides(list "!" "E" "N" "12" "1E"))
;;;555 3dd the layer names to the dialog bo (start$list "layerlist" ) (ma&car Gadd$list layer*ist) (end$list)
;;;555 3dd the number of sides to the dialog bo (start$list "numsides" ) (ma&car Gadd$list num-ides) (end$list)
(mode$tile "numsides" 1) ;;;555 8f an (action$tile (action$tile (action$tile (action$tile
action e6ent occurs7 do this function "dra%cir" "(toggleBadio 1)") "dra%&ol" "(toggleBadio 2)") "cancel" "(done$dialog 1)") "acce&t" "(sa6e
;;;555 is&lay the dialog bo (setq ddiag(start$dialog)) ;;;555 9nload the dialog bo (unload$dialog dcl$id) ;;;555 8f the cancel button %as &ressed 5 dis&lay message (if (' ddiag 1)
(&rinc "/n /n ...-3MP*,L Cancelled. /n ") )
;;;555 )f t(e "Okay" button was pressed (if (' ddiag 2) (&rinc "/n /n ...-3MP*,L Com&lete4") ) ) ) ) )
;;;555 -u&&ress the last echo for a clean eit (&rinc) )
:ow the only thing remaining is to o something something when the user presses presses the okay button. 1e have all of the ialog box box ata store in variable names.... names.... 6aria"le ame
DCL Control )tem
Action 7ey
Type o! Data Stored
raios
=aioColumn
?raios?
*tring 6 !ction Gey :ame8
num*ies
)opupList
?numsies?
Integer 6 :umber of sies8
save*et
Toggle
?saveset?
Integer 6 M or A 8
layer:ame
List
?layerlist?
*tring 6 :ame of Layer8
*o now all we have to o is write the the !utoLisp !utoLisp coe insie insie the ?/kay ?/kay button was presse? I2 statement. +1here the blue line is above., above.,
:ow we will replace the blue line above$ (&rinc "/n /n ...-3MP*, Com&lete4") with new coe. 2irst3 let's go go ahea an change change the layer. layer. (setq old*ay(get6ar "clayer")) (set6ar "clayer" layerame)
That was easy. :ow3 Let's raw the selecte selecte entity
(if(' radios "dra%cir") (&rogn (setq &t(get&oint "/n Center &oint: ")) (command "circle" &t &ause) ) ;;;555 ,lse dra% a &olygon (&rogn (setq &t(get&oint "/n Center Point: ")) (command "&olygon" num-ides &t "C" &ause) ) )
! the above to your program an save it. Test it out. -verything working okay9
!n finally all we have left is the coe for the efault settings. *ince everything in the ialog box is a string3 why on't we save all of the ata as strings. Lucky for us3 !utoDesk inclue AK setvars for us to store ata in. 0*-==A thru 0*-==K is use to store real numbers. 0*-=IA thru 0*-=IK is use to store integers. 0*-=*A thru 0*-=*K are use to store strings. 1e will use the system variables 0*-=*A thru 0*-=* to save our ata since we are saving the ata as strings. !ll of these setvars are store insie the rawing file. They will be there everytime you open your rawing. #ow convenient@ *o let's get to it. The first variable to store is =!DI/* an it is alreay a string. *o....
(set6ar "9-,B-1" radios) The secon variable to store is :0<*ID-* an it is an integer representing the number of sies the polygon shoul have. I want to store the inex of the selecte item in the list not the actual number of sies. 1e save the inex as a variable name :0<*T= when we ran the save&ars routine. *o...
(set6ar "9-,B-2" num-tr) The thir variable to save is *!&-*-T. It is store as an integer. 1e will have to convert it to a string to save it.
(set6ar "9-,B-" (itoa sa6e-et)) The fourth an final variable to save is L!"-=:!<-. It is store as a string. I want to save the inex of the selecte item. 1e save that earlier with the save&ars routine in a variable name s*T=.
(set6ar "9-,B-!" s-+B)
The last thing we have to o is check for the efault settings an loa them if they exist. (defun sa6e
;;;555 ,lse7 nothing is selected (&rogn ;;;555 -et the inde number to 51 (setq s8nde 51) ;;;555 3nd set the name of the selected item to nil (setq layerame nil) )
) ) (defun toggleBadio(a) ;if circle is selected (if(' a 1) (mode$tile "numsides" 1) ;disable ;else (mode$tile "numsides" =) ;enable ) ) (defun C:-3MP*,L() ;;;555 *oad the dcl file from dis into memory (if(not(setq dcl$id (load$dialog "-3MP*,L.dcl"))) (&rogn (alert "+he C* file could not be loaded4") (eit) )
;;;555 ,lse7 the C* file %as loaded (&rogn ;;;555 *oad the definition inside the C* file (if (not (ne%$dialog "-3MP*,L" dcl$id)) (&rogn (alert "+he -3MP*,L definition could not be loaded4") (eit) ) ;;;555 ,lse7 the definition %as loaded (&rogn (setq layer*ist(list "=" "8M" "K8," "-+B" "+" ",*")) (setq num-ides(list "!" "E" "N" "12" "1E"))
;;;555 3dd the layer names to the dialog bo (start$list "layerlist" ) (ma&car Gadd$list layer*ist) (end$list)
;;;555 3dd the number of sides to the dialog bo (start$list "numsides" ) (ma&car Gadd$list num-ides) (end$list)
;;;555 3dd the code here (if(?' (get6ar "9-,B-1") (&rogn (setq radios (get6ar (setq num-tr (get6ar
to chec for defaults "") "users1")) "users2"))
(setq sa6e-et(get6ar "users")) (setq layer8nde(get6ar "users!")) (set$tile "radios" radios) (set$tile "numsides" num-tr) (set$tile "sa6eset" sa6e-et) (set$tile "layerlist" layer8nde) ) ) ;;;555 nly disable the num-ides &o&u&$list if a circle is being dra%n (if(' radios "dra%cir") (mode$tile "numsides" 1) ) ;;;555 8f an (action$tile (action$tile (action$tile (action$tile
action e6ent occurs7 do this function "dra%cir" "(toggleBadio 1)") "dra%&ol" "(toggleBadio 2)") "cancel" "(done$dialog 1)") "acce&t" "(sa6e
;;;555 is&lay the dialog bo (setq ddiag(start$dialog)) ;;;555 9nload the dialog bo (unload$dialog dcl$id) ;;;555 8f the cancel button %as &ressed 5 dis&lay message (if (' ddiag 1) (&rinc "/n /n ...-3MP*,L Cancelled. /n ") ) ;;;555 8f the "ay" button %as &ressed (if (' ddiag 2) (&rogn ;;;555 -a6e the old layer and reset to ne% layer (setq old*ay(get6ar "clayer")) (set6ar "clayer" layerame)
;;;555 -ee %hat needs to be dra%n (if(' radios "dra%cir") (&rogn (setq &t(get&oint "/n Center &oint: ")) (command "circle" &t &ause) )
;;;555 ,lse dra% a &olygon (&rogn (setq &t(get&oint "/n Center Point: ")) (command "&olygon" num-ides &t "C" &ause) )
) ;;;555 -ee if %e need to sa6e the settings (if(' sa6e-et 1) (&rogn
;;;555 3dd code here to sa6e the settings as defaults (set6ar (set6ar (set6ar (set6ar
"9-,B-1" "9-,B-2" "9-,B-" "9-,B-!"
radios) num-tr) (itoa sa6e-et)) s-+B)
) ) ) ) ) ) ) ) ;;;555 -u&&ress the last echo for a clean eit (&rinc) )
1hen you get your program teste an everything is working3 move the blue line above3 6 (defun C:-3MP*,L() 8 all the way to the top of the file. This will make all of your variables local an will reset them all to nil when the program ens. That's it. 1e're one. ack
The AutoLisp Tutorial - DCL Dialog Control Language - List
List and how to handle them' Listbox an popuplist hanle a list of items in basically the same manner. "ou have to loa your list into the list box an at some point you have to ecie which item or items were selecte. In the ?*aving ata from a ialog box? I cover how to fin the selecte items from a listbox an a popuplist. #ow o we get the list insie the listbox9 That is what we nee to cover in this section. *o let's get starte. If you looke at the previous sections you know the !utoLisp an DCL basic moel. Let's get a copy of that in this section so we can look at it. I will replace the eitbox with a listbox control an a the coe to hanle the list. The list hanling coe is shown in the ?*aving ata from a ialog box? section of this tutorial. I will show the revise an new coe in re below. !ll of the "lack code is unchanged from the asic
The Basic Re%ised +odel The DCL 8ile# ,3MP*, : dialog label ' ",3MP*,.ls&"; ialog box : column : ro% : boed$column : list$bo
55 )uts a label on the
99 ) replaced the
edit("o& with a list("o&'
label '"Choose 8tems"; ey ' "mylist"; height ' 1D; %idth ' 2D; multi&le$select ' true;
99 +ultiple selection
is on
fied$%idth$font ' true; 99 8i&ed :idth 8ont
is on
6alue ' "="; > > > : ro% : boed$ro% : button ey ' "acce&t"; label ' " ay "; is$default ' true; > : button ey ' "cancel"; label ' " Cancel "; is$default ' false; is$cancel ' true; > > > > >
The AutoLisp 8ile# ;;;555 ,3MP*,.ls& ;;;555 I replace the save&ars routine with the one from the ?*ave ata from a list? section of this tutorial. ;;; I also change the things marke in re. (defun sa6e
;;;555 -etu& a 6ariable to run through the list (setq count 1) ;;;555 cycle through the list getting all of the selected items (%hile (setq item (read readlist)) (setq retlist(a&&end ret*ist (list (nth item myist)))) (%hile (and (?' " " (substr readlist count 1)) (?' "" (substr readlist count 1)) ) (setq count (1H count)) ) (setq readlist (substr readlist count)) ) )
(defun C:,3MP*,() ;;;555 8 need to build a list of data (setq myist(list "1" "2" "" "!" "D" "E" "L" "N")) ;;;555 *oad the dcl file from dis into memory (if(not(setq dcl$id (load$dialog ",3MP*,.dcl"))) (&rogn (alert "+he C* file could not be loaded4") (eit) )
;;;555 ,lse7 the C* file %as loaded into memory (&rogn
;;;555 *oad the dialog definition inside the C* file (if (not (ne%$dialog ",3MP*," dcl$id)) (&rogn (alert "+he C* definition could not be found inside the C* file4") (eit) )
;;;555 ,lse7 the dialog definition loaded (&rogn
;;;555 Kere7 8 add the data to the list$bo control ;;; 8 do this after the ne%$dialog call and before the action$tiles.
mylist" ) (start$list " (ma&car Gadd$list myist) (end$list)
;;;555 otice the "mylist" is the action ey associated %ith the C* file and ;;; the myist is the 6ariable for the list built abo6e. ;;;555 8f an action e6ent occurs7 do this function (action$tile "cancel" "(done$dialog 1)") (action$tile "acce&t" "(sa6e
*o3 in orer to isplay a list in a ialog box3 you must first buil the list. Then use the startlist3 alist3 an enlist functions just after the newialog call an before the actiontiles. This is the same for both a listbox an a popuplist.
ack
The AutoLisp Tutorial - DCL Dialog Control Language - Set and +ode Tile Set(Tile and +ode(Tile Set(Tile - is use to set the value of a control. *set_tile
"key"
"&alue"+
*etTile has two parameters. ?Gey? an ?&alue?.
;7ey; 4 The name of the key you efine with the control insie the DCL file. ;6alue;4 The new value for the control. •
-itbox
o (set$tile "mybo" "Oeff") Displays eff in the eit box. o (set$tile "mybo" "!G5 1?2") Displays '4H A5 in the eit box. •
Listbox
o (set$tile "mylist" "=") *elects the first item in the list. o (set$tile "mylist" "D") *elects the sixth item in the list.
o (set$tile "mylist" "") •
:o Items are selecte.
)op0pList
o (set$tile "mylist" "=") *elects the first item in the list. o (set$tile "mylist" "D") *elects the sixth item in the list. o (set$tile "mylist" "") •
:o Items are selecte.
Toggle
o (set$tile "mytog" "=") =emoves the check from the box. o (set$tile "mytog" "1") Checks the box. •
=aioutton
o (set$tile "myradio1" "1")
+ode(Tile - is use to enable or isable a control. *mode_tile
"key"
&alue+
;7ey; 4 The name of the key you efine with the control insie the DCL file. 6alue4 The new value for the control.
M B -nable A B Disable
(mode$tile "mylist" =) -nables the list box (mode$tile "mylist" 1) Disables the list box 0se
That is all there is to settile an moetile. 1e will use them later on in the tutorial so you can see them in action. ack
The AutoLisp Tutorial - DCL Dialog Control Language - Action Action In orer for the ialog box to respon to user interaction3 you must set up an action event. ! trigger3 to fire when the user selects an item from a list or presses a button. This works off of the G-" efine for each control insie the DCL file. If the key for a button is name ?mybutton? then you must have an action name ?mybutton?. /therwise the user will press the button an nothing will happen. Let's take a look at the actiontile.
*action_tile
"key"
"action"+
The actiontile has two parameters. ?Gey? an ?action?.
;7ey; 4 The name of the key you efine with the control insie the DCL file. ;Action;4 The action you want taken when the action event is fire. a variable or run a function.
"ou can set
.&les# Let's take for example3 you have a button name ?test? an you want to set the variable name myT-*T to A if the user presses the button$
*action_tile
"test"
"*set, my!est %+"+
:otice the key is in (uotes an the set( function is in (uotes. This is stanar proceure for the actiontile statement. :ext let's say you have the same thing except you want to run a function name ?save&ars? when the user presses the test button.
*action_tile
"test"
"*sa&e'ars+"+
:otice is is the same as the above. The +save&ars, is insie (uotes. 1hat if you wante to o both3 run the function an set a variable9
*action_tile
"test"
"*set, my!est %+*sa&e'ars+"+
*imply put both insie the (uotes. /ne more thing....1hat if the button is set to be the cancel or accept button for the ialog box9 :o problem...
*action_tile "test" *done_dialo$ %+"+
"*set, my!est %+*sa&e'ars+
! the oneialog statement to the en. 6 Insie the (uotes 8
That is about all there is to an actiontile. =emember3 anything with a key can have an action call. ack
The AutoLisp Tutorial - DCL
Dialog Control Language - )mage )mage )mage !n Image is use to isplay a vector graphic picture insie a rectangle. To create the image you can use three ifferent methos. •
&ectorimage 4 Draws a single straight line in the current image.
•
2illimage
4 Draws a fille rectangle in the current image.
•
*lieimage
4 Draws an !utoC!D slie in the image.
2or this tutorial we will concentrate on the *lieImage function. -veryone knows how to create a slie right9 The <*LID- comman. /kay. 1e will assume our image is reay. Let's look at the DCL Image efinition an the !utoLisp functions re(uire to isplay the image.
DCL 4 "ou must supply either the with an height or one of these plus an aspectratio.
: image ey ' "sld"; height ' =; %idth ' =; color ' =; is$enabled ' false; is$tab$sto& ' false; P
AutoLisp ;;;555 First %e need a slide name (setq my-lideame "c:?acad?myslide.sld") ;;;555 -econd %e need the ey to the image control (setq myey "sld") ;;;555 et %e send the slide name and the ey to the u&date function (u&ate8mage my-lideame myey) ; -O!: otice my-lideame becomes sldame and myey becomes ey %hen &assed ; as &arameters to the u&ate8mage function. ;;;555 Function to u&date the slide (defun u&ate8mage( sldame ey) ;;;555 Iet the %idth of the slide (setq %idth (dim$tile ey)) ;;;555 Iet the height of the slide (setq height (dimy$tile ey)) ;;;555 -tart the slide definition (start$image ey) ;;;555 i&e out the bacground (fill$image = = %idth height =) ;;;555 Put the slide in the image area (slide$image = = %idth height sldame) ;;;555 Finish the slide definition (end$image) )
This function can be use over an over to isplay any slie image in an image control. 0se the upDateImage function after the newialog call an before the actiontile statements. "ou can also use this function while the ialog box is isplaye in one of your action calls.
ack
The AutoLisp Tutorial - DCL Dialog Control Language - Sa%e6ars In this section we are going to take a look at the *ave&ars routine an isect it for each type of control. The types of controls that we sometimes nee to save are $ -itbox 4 Listbox 4 )opupList 4 =aiouttons 4 =aioColumn 4 =aio=ow 4 Toggle The *ave&ars routine is execute just before the ialog box is issue a oneialog call. "ou cannot get the ata from the ialog box once it has been shut own. If you remember our action calls in the !utoLisp )rogram3 they looke something like this$ ;;;555 8f an action e6ent occurs7 do this function (action$tile "acce&t" "(sa6e
e need to %or on the "stuffing".
*etGs
#tuffin$ There are three parts to a control with an action call back statement. A. The DCL efinition . The action call in the !utoLisp file. H. The coe insie the *ave&ars routine. In each of the following controls I will show you all three parts so we know how to put it all together later. !lthough3 all of the parts are important3 try to focus on the *ave&ars routine.
-itbox
4
Listox*ingle*election 4 Listox
=aioColumn
4
=aio=ow
4
Toggle 4
/kCancel
dit_.ox : edit_box { key = "edbox"; label = ".olt Circle Diameter:"; A edit_widt( = /; &alue = "%0"; }
o Action call re
*action_tile "edbox" "*do!(is1unction+"+
To get the ata as a real num"er#
To get the ata as a string#
+efun save&ars+,
+efun save&ars+,
H
(setq edAo(distof(get$tile "edbo")))
(setq edAo(get$tile "edbo"))
)
)
OT.# otice ) used the key name as the %aria"le to store the data in' =ou will !ind this method makes it easier to keep things straight' DCL is case sensiti%e so> ) ne%er capitali?e key names> only autolisp %aria"le names i! they are made up o! more than one word' Like# this)s+y6aria"le'
ist_.ox
A
#in$le C(oice Only
: list_box { key = "mylist"; label = "2&ailable C(oices"; multiple_select = "12#"; widt( = 30; (ei$(t = 40; fixed_widt(_font = true; &alue = ""; }
55 *ets single selection
55 -(ually space characters 55 *tart with no item selecte
o Action call re
*action_tile "edbox" "*do!(is1unction+"+ (defun sa6e
H
;;;555 Iet the selected item from the list (setq s-tr(get$tile "mylist")) ;;;555 8f the inde of the selected item is not "" then something %as selected (if(?' s-tr "") (&rogn ;;;555 -omething is selected7 so con6ert from string to integer (setq s8nde(atoi s-tr)) ;;;555 3nd get the selected item from the list (setq same(nth s8nde my*ist)) )
;;;555 ,lse7 nothing is selected (&rogn
;;;555 -et the inde number to 51 (setq s8nde 51) ;;;555 3nd set the name of the selected item to nil (setq same nil) ) ) )
otes#
A. This shoul only be use when single selection is re(uire. This will not work on multiple selection. . This is assuming there is a list of items calle myList.
ist_.ox
A
5ultiple C(oice
: list_box { key = "mylist"; label = "2&ailable C(oices"; multiple_select = "!67"; widt( = 30; (ei$(t = 40; fixed_widt(_font = false; alignment 8 &alue = "3"; }
55 *ets multiple selection
55 0se efault font 6 no 99 *tart with item K selecte.
o Action call re
*action_tile "mylist" "*do!(is1unction+"+ (defun sa6e
H
;;;555 -etu& a list to hold the selected items (setq ret*ist(list)) ;;;555 -a6e the list setting
(setq readlist(get$tile "files")) ;;;555 -etu& a 6ariable to run through the list (setq count 1) ;;;555 cycle through the list getting all of the selected items (%hile (setq item (read readlist)) (setq retlist(a&&end ret*ist (list (nth item fileames)))) (%hile (and (?' " " (substr readlist count 1)) (?' "" (substr readlist count 1)) ) (setq count (1H count)) ) (setq readlist (substr readlist count)) ) )
ote# This metho can be use for a single or multiple selection listbox.
8op7p_ist
A
: popup_list { key = "mylist"; fixed_widt(_font = false; widt( = 40; (ei$(t = 40; }
55 action key 55 fixe with font off 55 with of popup list 55 height of popup list
o Action call re
*action_tile "mylist" "*do!(is1unction+"+ (defun sa6e
H (if(' s-tr "")(alert "o 8tem %as -elected4")) )
6adio_Column and 6adio_.uttons
: radio$column label ' "Choices"; ey ' "choices";
A
55 0se boxeraiocolumn if a box is re(uire. 55 Label for the column or boxecolumn 55 !ction key for the raio column
: radio$button label ' "Choice 1"; ey ' "choice1"; >
55 2irst raio button
: radio$button label ' "Choice 2"; ey ' "choice2"; >
55 *econ raio button
: radio$button label ' "Choice "; ey ' "choice"; >
55 Thir raio button
: radio$button label ' "Choice !"; ey ' "choice!"; >
55 2ourth raio button
55 Close the raiocolumn
>
o Action call re
*action_tile "c(oices" "*do!(is1unction+"+
55 If any choice is mae
*action_tile "c(oice%" "*do!(at1unction+"+
55 If choiceA is mae
*action_tile "c(oice4" "*doDis1unction+"+
55 If choice is mae
etc9
H (defun sa6e
(setq choices
% M B not chosen % M B not chosen % M B not chosen % M B not chosen
A B chosen A B chosen A B chosen A B chosen
,
6adio_6ow 2nd 6adio_.uttons
A
: radio$ro% label ' "Choices"; ey ' "choices";
55 0se boxeraiorow if a box is re(uire. 55 Label for the row or boxerow 55 !ction key for the raio row
: radio$button label ' "Choice 1"; ey ' "choice1"; >
55 2irst raio button
: radio$button label ' "Choice 2"; ey ' "choice2"; >
55 *econ raio button
: radio$button label ' "Choice "; ey ' "choice"; >
55 Thir raio button
: radio$button label ' "Choice !"; ey ' "choice!"; >
55 2ourth raio button
55 Close the raiorow
>
o Action call re
*action_tile "c(oices" "*do!(is1unction+"+ mae
55 If any choice is
*action_tile "c(oice%" "*do!(at1unction+"+
55 If choiceA is mae
*action_tile "c(oice4" "*doDis1unction+"+
55 If choice is mae
etc9 (defun sa6e
H (defun sa6e
!o$$le
A
: to$$le { key = "to$%"; label = "-ame"; }
55 !ction key 55 Label
% M B not chosen % M B not chosen % M B not chosen % M B not chosen
A B chosen A B chosen A B chosen A B chosen
o Action call re
*action_tile "to$%" "*do!(is1unction+"+ (defun sa6e
H
1 ' checed
)
Ok(Cancel ok_cancel;
55 /nly one line re(uire
A :ote$ I usually efine my own okay an cancel buttons using two stanar buttons3 but this works fine. "ou will nee two action calls for this button...both close the ialog box but the accept or ?/kay? key will save the ialog box settings before shutting the ialog box own.
*action_tile "cancel" "*done_dialo$ %+"+
*action_tile "accept" "*sa&e'ars+*done_dialo$ 4+"+ !hh....finally the *ave&ars routine shows up.
H
:othing to o in the save&ars routine for these buttons.
ack
The AutoLisp Tutorial
Dialog Control Language - Controls Let's take a look at the ifferent controls you can put on the ialog box. "ou've seen a few of them in the overview portion but let's go over the majority of them now. I will only show the most use properties for each control.
LA=O2T COTROLS# : column label ' "My Column"; >
: boed$column label ' "My Column"; >
: ro% label ' "My Bo%"; >
: boed$ro% label ' "My Bo%"; >
: s&acer %idth ' 1=; height ' 1D; >
Column "ou can omit the label.
oxe Column "ou can omit the label.
=ow "ou can omit the label.
oxe =ow "ou can omit the label.
! normal spacer to help align other controls. "ou can omit the with an height properties.
: s&acer$=;
: s&acer$1;
! spacer that usually has no with. It simply means3 if you have to stretch something in this row to make things fit3 stretch this spacer instea of the other items..
The smallest spacer that's visually noticable.
B2TTO key B The name you assign to the button. label B The text isplaye on the button.
: button ey ' "button1; label ' "ay"; is$tab$sto& ' true; is$cancel ' false; is$default ' true; %idth ' 1D; height ' 1=; mnemonic ' "A"; >
iscancel B Determines if this is the cancel button. /ne control must be assigne to be the cancel action. isefault B Determines if this button activates when the user presses the enter key. mnemonic B Determines if you can press !LTQ to move to this action key. "ou assign the letter an DCL will unerscore the letter on the ialog box to let the user know it is !LT4able. If that is a word-
[email protected] RAD)O COL2+> RAD)O COL2+> RAD)O B2TTO
: radio$column label ' "Choices"; ey ' "choices"; : radio$button label ' "Choice 1"; ey ' "choice1"; > : radio$button label ' "Choice 2";
55 0se boxeraiocolumn if a box is re(uire. 55 Label for the column or boxecolumn 55 !ction key for the raio column 55 2irst raio button
55 *econ raio button
ey ' "choice2"; > : radio$button label ' "Choice "; ey ' "choice"; > : radio$button label ' "Choice !"; ey ' "choice!"; > >
55 Thir raio button
55 2ourth raio button
55 Close the raiocolumn
[email protected] RAD)O RO:> RAD)O RO:> RAD)O B2TTO : radio$ro% label ' "Choices"; ey ' "choices"; : radio$button label ' "1"; ey ' "choice1"; > : radio$button label ' "2"; ey ' "choice2"; > : radio$button label ' ""; ey ' "choice"; > : radio$button label ' "!"; ey '
55 0se boxeraiorow for box. 55 Label for the row or boxerow 55 !ction key for the raio row 55 2irst raio button
55 *econ raio button
55 Thir raio button
55 2ourth raio button
"choice!"; > >
55 Close the raiorow
.D)T BO@ : edit$bo ey ' "my6al"; label ' "
55 !ction key 55 Label for the eit box 55 Character with 55 Initial value
L)ST BO@
: list$bo label '"Choose 8tems"; ey ' "mylist"; height ' 1D; %idth ' 2D; multi&le$select ' true; fied$%idth$font ' true; 6alue ' "="; >
55 Label for the list box 55 !ction key 55 #eight of list box 55 1ith of list box 55
2ixe 1ith 2ont B T=0
&iew of list box with...
&iew of list box with...
2ixe 1ith 2ont B 2!L*-.
2ixe 1ith 2ont B 2!L*-.
*O*2* L)ST
: &o&u&$list ey ' "mylist"; label ' "-elect 8tem"; fied$%idth$font ' false; %idth ' 1D; 6alue ' =; >
55 !ction key 55 Label 55 0se fixe with font B false 55 1ith of list box 55 Initial selection B Ast item
T.@T : tet ey ' "mytet"; 6alue ' "+his is tet4"; >
55 !ction key 55 &alue
/kay. That's it for controls. There are others but3 these are the most use controls. Let's move on. ack
The AutoLisp Tutorial - DCL Dialog Control Language - Rows and Columns Rows and Columns Let's get a feel for laying out a ialog box using neste rows an columns. I'll o this by showing you the DCL coe next to a picture of the ialog box. I can't think of any easier way to o it. Ignore all of the Labels and T/T controls. I will use these to visuall0 show the location of things.
-xample A$
,3MP*, : dialog label ' ",3MP*,.ls&"; : column : boxed_column { label ' "column 1"; : boed$column label ' "column2"; > : boed$column label ' "column "; > > o$cancel; > >
Column Column Column
,3MP*, : dialog label ' ",3MP*,.ls&"; : column : boxed_row { label ' "ro% 1"; : boed$column label ' "column2"; > : boed$column label ' "column "; > > o$cancel; > > ,3MP*, : dialog label ' ",3MP*,.ls&"; : column : boxed_column { label ' "column 1"; : boed$column label ' "column2"; : tet ey ' "t1"; 6alue ' "+et1"; > : tet ey ' "t2"; 6alue ' "+et2"; > > : boed$column label ' "column "; : tet ey ' "t"; 6alue ' "+et"; > : tet ey ' "t!"; 6alue ' "+et!"; > > > o$cancel; > >
:otice I change the first boxe column into a boxe row. =ow Column Column
Column Column Column
,3MP*, : dialog label ' ",3MP*,.ls&"; : column : boxed_row { label ' "ro% 1"; : boed$column label ' "column2"; : tet ey ' "t1"; 6alue ' "+et1"; > : tet ey ' "t2"; 6alue ' "+et2"; > > : boed$column label ' "column "; : tet ey ' "t"; 6alue ' "+et"; > : tet ey ' "t!"; 6alue ' "+et!"; > > > o$cancel; > >
=ow Column Column
,3MP*, : dialog label ' ",3MP*,.ls&"; : column : boxed_row { label ' "ro% 1"; : boxed_row { label ' "ro% 2"; : tet ey ' "t1"; 6alue ' "+et1"; > : tet ey ' "t2"; 6alue ' "+et2"; > > : boxed_row { label ' "ro% "; : tet ey ' "t"; 6alue ' "+et"; > : tet ey ' "t!"; 6alue ' "+et!"; > > > o$cancel; > >
=ow =ow =ow