the autolisp tutorial with dcl
TRANSCRIPT
-
8/18/2019 The AutoLisp Tutorial With Dcl
1/114
The AutoLisp Tutorial - DCL
Dialog Control Language
Getting Started
I'm not going to explain everything there is to know about Dialog Control
Language. There are plenty of books on the subject. I will attempt to give you a goounerstaning of how DCL interacts with !utoLisp. "ou shoul be able to write your
first DCL riven !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() % Define the functions you nee like
save&ars
;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" "#"))
-
8/18/2019 The AutoLisp Tutorial With Dcl
2/114
load$dialog %Loa the DCL file
ne%$dialog %Loa the DCL efinition insie the
DCL file
start$list %)ut the list in the ialog box add$listend$list
start$list %!s many list as you nee add$list
end$list
set$tile % *et the tiles +if necessary,
mode$tile % -nable or isable tiles +as
necessary,
%*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)
-
8/18/2019 The AutoLisp Tutorial With Dcl
3/114
;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 out the ialog box. )lease 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 will cover these items first$ button3 row3 column3
boxerow3 an boxecolumn.
Okay and Cancel Buttons 4 The DCL coe for a these buttons look like this$
: button { 55 Define the button
key = "accept"; 55 Define the action key +This is my name
assigne to this button,
label = " Okay "; 55 This is the text isplaye on the
button.
is_default = true; 55 !llows the button to activate when the user
presses the enter key.
} 55 Close the button efinition
: button { 55 Define another button
key = "cancel"; 55 Define the action key. +I chose this name for
the button.,
label = " Cancel "; 55 Text isplaye on the button.
is_default = false; 55 Does not allow this key to activate when the
-
8/18/2019 The AutoLisp Tutorial With Dcl
4/114
enter key is presse.
is_cancel = true; 55 !ctivate this key when the close button 6 7 8
is selecte.
} 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.
-
8/18/2019 The AutoLisp Tutorial With Dcl
5/114
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.
-
8/18/2019 The AutoLisp Tutorial With Dcl
6/114
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- :!=!< :!
-
8/18/2019 The AutoLisp Tutorial With Dcl
7/114
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)
-
8/18/2019 The AutoLisp Tutorial With Dcl
8/114
) )
*ince a DCL file can contain multiple ialog box efinitions3 6 I'll show you anexample 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 theC* 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
-
8/18/2019 The AutoLisp Tutorial With Dcl
9/114
) ) ) )
: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? . Thesematch the keys in the DCL file. I mae these names up. "ou can name them whatever you wantas 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 key3 the oneialog statement returns the value of A thestartialog 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 havemore 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 buttonwas presse.
-
8/18/2019 The AutoLisp Tutorial With Dcl
10/114
;;;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 callwith a function calle save&ars. 1ithout further ao3 here's the moel$
The DCL +odel#
,3MP*, : dialog
label ' ",3MP*,.ls&"; 55 )uts a label on the
ialog box
initial$focus ' "tet6al"; 55 *ets the initial
focus : column : ro% : boed$column
: edit$bo 55 The eitbox
control 4 *omething new@ ey ' "tet6al";
-
8/18/2019 The AutoLisp Tutorial With Dcl
11/114
label ' "+et
-
8/18/2019 The AutoLisp Tutorial With Dcl
12/114
(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
-
8/18/2019 The AutoLisp Tutorial With Dcl
13/114
/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 neesomething 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
http://www.jefferypsanders.com/autolisp_DCL.htmlhttp://www.jefferypsanders.com/autolisp_DCL.html
-
8/18/2019 The AutoLisp Tutorial With Dcl
14/114
-
8/18/2019 The AutoLisp Tutorial With Dcl
15/114
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 insidethe 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)
-
8/18/2019 The AutoLisp Tutorial With Dcl
16/114
)
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 startialogstatement3 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 linetype 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$
-
8/18/2019 The AutoLisp Tutorial With Dcl
17/114
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
-
8/18/2019 The AutoLisp Tutorial With Dcl
18/114
(&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 theC* file4") (eit) )
;;;555 ,lse7 the definition %as loaded(&rogn
;;;555 8f an action e6ent occurs7 do this function (action$tile "but1" "(doAutton 1)") (action$tile "but2" "(doAutton 2)") (action$tile "but" "(doAutton )") (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)
)
*ave it an test it out. -verything working okay9
-
8/18/2019 The AutoLisp Tutorial With Dcl
19/114
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
>
http://www.jefferypsanders.com/autolisp_DCL.htmlhttp://www.jefferypsanders.com/autolisp_DCL.html
-
8/18/2019 The AutoLisp Tutorial With Dcl
20/114
>: 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";
-
8/18/2019 The AutoLisp Tutorial With Dcl
21/114
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
-
8/18/2019 The AutoLisp Tutorial With Dcl
22/114
;;;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 "AllFiles" 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$
-
8/18/2019 The AutoLisp Tutorial With Dcl
23/114
-
8/18/2019 The AutoLisp Tutorial With Dcl
24/114
(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
-
8/18/2019 The AutoLisp Tutorial With Dcl
25/114
(&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 user:ame an
user!ge ata. Let's o something simple. 1e will fin out 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 ofdays.
(setq user3ge( user3ge ED))
;;;555 is&lay the results (alert (strcat userame " is " (itoa user3ge) " daysold.")) ) )
! 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*,2() 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
http://www.jefferypsanders.com/autolisp_DCL.htmlhttp://www.jefferypsanders.com/autolisp_DCL.html
-
8/18/2019 The AutoLisp Tutorial With Dcl
26/114
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 >
-
8/18/2019 The AutoLisp Tutorial With Dcl
27/114
>>
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;
http://www.jefferypsanders.com/autolisp_DCL_Controls.htmlhttp://www.jefferypsanders.com/autolisp_DCL_Controls.html
-
8/18/2019 The AutoLisp Tutorial With Dcl
28/114
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
-
8/18/2019 The AutoLisp Tutorial With Dcl
29/114
;;;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$
-
8/18/2019 The AutoLisp Tutorial With Dcl
30/114
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 olcontents 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...
-
8/18/2019 The AutoLisp Tutorial With Dcl
31/114
(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
-
8/18/2019 The AutoLisp Tutorial With Dcl
32/114
(&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
-
8/18/2019 The AutoLisp Tutorial With Dcl
33/114
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
-
8/18/2019 The AutoLisp Tutorial With Dcl
34/114
;;;555 -a6e the list setting (setq readlist(get$tile " mylist%"))
;;;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*,()
-
8/18/2019 The AutoLisp Tutorial With Dcl
35/114
(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
-
8/18/2019 The AutoLisp Tutorial With Dcl
36/114
(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 thefirst list bo."))
;;;555 8nform the user of his selections from the secondlist (&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
-
8/18/2019 The AutoLisp Tutorial With Dcl
37/114
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
http://www.jefferypsanders.com/autolisp_DCL.htmlhttp://www.jefferypsanders.com/autolisp_DCL.html
-
8/18/2019 The AutoLisp Tutorial With Dcl
38/114
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 >>
>
-
8/18/2019 The AutoLisp Tutorial With Dcl
39/114
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
http://www.jefferypsanders.com/autolisp_DCL_Controls.htmlhttp://www.jefferypsanders.com/autolisp_DCL_Controls.html
-
8/18/2019 The AutoLisp Tutorial With Dcl
40/114
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 shownin 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
-
8/18/2019 The AutoLisp Tutorial With Dcl
41/114
(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$
-
8/18/2019 The AutoLisp Tutorial With Dcl
42/114
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)
-
8/18/2019 The AutoLisp Tutorial With Dcl
43/114
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
-
8/18/2019 The AutoLisp Tutorial With Dcl
44/114
;;;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
-
8/18/2019 The AutoLisp Tutorial With Dcl
45/114
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
-
8/18/2019 The AutoLisp Tutorial With Dcl
46/114
(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
-
8/18/2019 The AutoLisp Tutorial With Dcl
47/114
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
-
8/18/2019 The AutoLisp Tutorial With Dcl
48/114
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 knowwhat 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$
http://www.jefferypsanders.com/autolisp_DCL.htmlhttp://www.jefferypsanders.com/autolisp_DCL.html
-
8/18/2019 The AutoLisp Tutorial With Dcl
49/114
: 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
http://www.jefferypsanders.com/autolisp_DCL_Controls.htmlhttp://www.jefferypsanders.com/autolisp_DCL_Controls.html
-
8/18/2019 The AutoLisp Tutorial With Dcl
50/114
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")))
-
8/18/2019 The AutoLisp Tutorial With Dcl
51/114
(&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
-
8/18/2019 The AutoLisp Tutorial With Dcl
52/114
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'
-
8/18/2019 The AutoLisp Tutorial With Dcl
53/114
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 inre.
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$
http://www.jefferypsanders.com/autolisp_DCL_SaveVar.htmlhttp://www.jefferypsanders.com/autolisp_DCL_SaveVar.htmlhttp://www.jefferypsanders.com/autolisp_DCL_SaveVar.htmlhttp://www.jefferypsanders.com/autolisp_DCL_SaveVar.html
-
8/18/2019 The AutoLisp Tutorial With Dcl
54/114
(defun sa6e
-
8/18/2019 The AutoLisp Tutorial With Dcl
55/114
! this to the original *ampleK.lsp program an we shoul have something that
looks like this$
(defun sa6e
-
8/18/2019 The AutoLisp Tutorial With Dcl
56/114
(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 theradio$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")) )
-
8/18/2019 The AutoLisp Tutorial With Dcl
57/114
;;;555 8nform the user of his selection using theradio$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.
-
8/18/2019 The AutoLisp Tutorial With Dcl
58/114
That's it. 1e're one.
ack
The AutoLisp Tutorial - DCLDialog 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 tet here >>: boed$column
: toggle
?? Put code for toggle 1 here >
: toggle ?? Put code for toggle 2 here
>: toggle ?? Put code for toggle here
http://www.jefferypsanders.com/autolisp_DCL.htmlhttp://www.jefferypsanders.com/autolisp_DCL.html
-
8/18/2019 The AutoLisp Tutorial With Dcl
59/114
>: 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. :oticethe 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";
http://www.jefferypsanders.com/autolisp_DCL_Controls.htmlhttp://www.jefferypsanders.com/autolisp_DCL_Controls.html
-
8/18/2019 The AutoLisp Tutorial With Dcl
60/114
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 shownin 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")
-
8/18/2019 The AutoLisp Tutorial With Dcl
61/114
(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 notnee 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
-
8/18/2019 The AutoLisp Tutorial With Dcl
62/114
(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.
-
8/18/2019 The AutoLisp Tutorial With Dcl
63/114
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
-
8/18/2019 The AutoLisp Tutorial With Dcl
64/114
(defun ch+oggle()
(setq tog1(atoi(get$tile "tog1"))) % M B not chosen A B chosen
(setq tog2(atoi(get$tile "tog2"))) % M B not chosen A B chosen
(setq tog(atoi(get$tile "tog"))) % M B not chosen A B chosen
(setq tog!(atoi(get$tile "tog!"))) % M B not chosen A B chosen
(setq my-tr "") (if(' tog1 1)(setq my-tr(strcat my-tr " Kearts"))) (if(' tog2 1)(setq my-tr(strcat my-tr " Moons"))) (if(' tog 1)(setq my-tr(strcat my-tr " -tars"))) (if(' tog! 1)(setq my-tr(strcat my-tr " 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 "tog1" "(c(k!o$$le)")
(action$tile "tog2" "(c(k!o$$le)")
(action$tile "tog" "(c(k!o$$le)")
(action$tile "tog!" "(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()
-
8/18/2019 The AutoLisp Tutorial With Dcl
65/114
(setq tog1(atoi(get$tile "tog1"))) % M B not chosen A B chosen
(setq tog2(atoi(get$tile "tog2"))) % M B not chosen A B chosen
(setq tog(atoi(get$tile "tog"))) % M B not chosen A B chosen
(setq tog!(atoi(get$tile "tog!"))) % M B not chosen A B chosen
(setq my-tr "") (if(' tog1 1)(setq my-tr(strcat my-tr " Kearts"))) (if(' tog2 1)(setq my-tr(strcat my-tr " Moons"))) (if(' tog 1)(setq my-tr(strcat my-tr " -tars"))) (if(' tog! 1)(setq my-tr(strcat my-tr " 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 "tog1" "(ch+oggle)")
(action$tile "tog2" "(ch+oggle)")
(action$tile "tog" "(ch+oggle)")
(action$tile "tog!" "(ch+oggle)") (action$tile "cancel" "(done$dialog 1)")
-
8/18/2019 The AutoLisp Tutorial With Dcl
66/114
;;;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
http://www.jefferypsanders.com/autolisp_DCL.htmlhttp://www.jefferypsanders.com/autolisp_DCL.html
-
8/18/2019 The AutoLisp Tutorial With Dcl
67/114
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
-
8/18/2019 The AutoLisp Tutorial With Dcl
68/114
?? 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";
-
8/18/2019 The AutoLisp Tutorial With Dcl
69/114
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;
-
8/18/2019 The AutoLisp Tutorial With Dcl
70/114
>>
>
>
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
-
8/18/2019 The AutoLisp Tutorial With Dcl
71/114
(unload$dialog dcl$id)
;;;555 8f the cancel button %as &ressed 5 dis&laymessage (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$*ampleOComman$
:ow type *ample an press enter. If everything went accoring to plan you shoul
see this on your screen$
-
8/18/2019 The AutoLisp Tutorial With Dcl
72/114
: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 thistutorial.
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
-
8/18/2019 The AutoLisp Tutorial With Dcl
73/114
(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
-
8/18/2019 The AutoLisp Tutorial With Dcl
74/114
(&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
-
8/18/2019 The AutoLisp Tutorial With Dcl
75/114
-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
-
8/18/2019 The AutoLisp Tutorial With Dcl
76/114
;;;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)
-
8/18/2019 The AutoLisp Tutorial With Dcl
77/114
;if circle is selected (if(' a 1)
(mode$tile "numsides" 1) ;disable
;else
(mode$tile "numsides" =) ;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
-
8/18/2019 The AutoLisp Tutorial With Dcl
78/114
;;;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 "" thensomething %as selected(if(?' s-tr "")
(&rogn
;;;555 -omething is selected7 so con6ert from string tointeger (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 ))
-
8/18/2019 The AutoLisp Tutorial With Dcl
79/114
(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 e6ent occurs7 do this function (action$tile "dra%cir" "(toggleBadio 1)") (action$tile "dra%&ol" "(toggleBadio 2)") (action$tile "cancel" "(done$dialog 1)") (action$tile "acce&t" "(sa6e
-
8/18/2019 The AutoLisp Tutorial With Dcl
80/114
(&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 when the user presses the okay
button. 1e have all of the ialog box ata store in variable 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 !utoLisp coe insie the ?/kay button was
presse? I2 statement. +1here the blue line is above.,
:ow we will replace the blue line above$ (&rinc "/n /n ...-3MP*,
Com&lete4") with new coe.
2irst3 let's go ahea an change the layer.
(setq old*ay(get6ar "clayer"))(set6ar "clayer" layerame)
That was easy. :ow3 Let's raw the selecte entity
-
8/18/2019 The AutoLisp Tutorial With Dcl
81/114
(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 inthe 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
-
8/18/2019 The AutoLisp Tutorial With Dcl
82/114
(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
-
8/18/2019 The AutoLisp Tutorial With Dcl
83/114
))
(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 to chec for defaults (if(?' (get6ar "9-,B-1") "") (&rogn (setq radios (get6ar "users1")) (setq num-tr (get6ar "users2"))
-
8/18/2019 The AutoLisp Tutorial With Dcl
84/114
(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 circleis being dra%n (if(' radios "dra%cir") (mode$tile "numsides" 1) )
;;;555 8f an action e6ent occurs7 do this function (action$tile "dra%cir" "(toggleBadio 1)") (action$tile "dra%&ol" "(toggleBadio 2)") (action$tile "cancel" "(done$dialog 1)") (action$tile "acce&t" "(sa6e
-
8/18/2019 The AutoLisp Tutorial With Dcl
85/114
;;;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 asdefaults (set6ar "9-,B-1" radios) (set6ar "9-,B-2" num-tr) (set6ar "9-,B-" (itoa sa6e-et)) (set6ar "9-,B-!" 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
http://www.jefferypsanders.com/autolisp_DCL.htmlhttp://www.jefferypsanders.com/autolisp_DCL.html
-
8/18/2019 The AutoLisp Tutorial With Dcl
86/114
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
-
8/18/2019 The AutoLisp Tutorial With Dcl
87/114
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
-
8/18/2019 The AutoLisp Tutorial With Dcl
88/114
;;;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 insidethe 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 beforethe action$tiles.
-
8/18/2019 The AutoLisp Tutorial With Dcl
89/114
(start$list " mylist" ) (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 builtabo6e.
;;;555 8f an action e6ent occurs7 do this function (action$tile "cancel" "(done$dialog 1)") (action$tile "acce&t" "(sa6e
-
8/18/2019 The AutoLisp Tutorial With Dcl
90/114
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.
http://www.jefferypsanders.com/autolisp_DCL.htmlhttp://www.jefferypsanders.com/autolisp_DCL.html
-
8/18/2019 The AutoLisp Tutorial With Dcl
91/114
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")
-
8/18/2019 The AutoLisp Tutorial With Dcl
92/114
(mode$tile "mylist" =) -nables the list box
(mode$tile "mylist" 1) Disables the list box
0se
-
8/18/2019 The AutoLisp Tutorial With Dcl
93/114
.&les#
Let's take for example3 you have a button name ?test? an you want to set thevariable 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 can