AutoCAD: Dialog Fun Facts > Get Ready, Set, Action!
Excitement Filled the Air
In August we all had a chance to experience the excitement that surrounded the Track & Field events of the 2024 Summer Olympics. As early as June I watched the tryouts that determined the athletes who would qualify to compete with other Olympians from all over the world. Starting with the individual sprinters, to the hurdle obstacles and to the team relay races witnessing who crossed the finish line first was absolutely thrilling. But the most anxious part of the race was actually at the beginning. This is when the stadium went silent with each Olympian positioned at the starting line waiting for the call to, “Get ready, Set, and Go!!!”
At the beginning of this year, I introduced an article titled Dialog Fun Facts. For me, the ability to program and layout custom dialog boxes in AutoCAD gives me a similar kind of excitement as watching the Summer Olympics. I’m writing follow-up articles on this topic so I can pass this excitement on to fellow AutoCAD users.
Get Ready…
For this go-around, the first dialog fun fact I would like to discuss is the get_tile function. To demonstrate how get_tile works first open the Windows built-in Notepad app and create a file called MyDcl.dcl.
Note: This file may already exist from following the instructions in my AutoCAD: Dialog Fun Facts article.
Next, enter the following lines of code in the file to define the contents of a custom dialog named MyDcl4 (see Figure 1):
Firgure 1
Then, save this file in one of the folders listed under AutoCAD’s Options command, Files tab, and Support File Search Path (see Figure 2).
Firgure 2
To bring up the MyDcl4 custom dialog onto the drawing area at AutoCAD’s command prompt enter the following lines of code one after the other following each line with the Enter key (see Figure 3):
Firgure 3
The following dialog box opens in the AutoCAD graphics drawing area (see Figure 4):
Firgure 4
Though both the OK and Cancel buttons when clicked dismisses the dialog box, when the Help button is clicked the following AutoCAD Message window appears (see Figure 5):
Firgure 5
One reason for the information displayed in this window to appear is because of the get_tile function as shown in this portion of the code:
(get_tile \"error\")
The "error" in this case references the key defined for the errtile which is stored in AutoCAD’s base.dcl file. As I mentioned in my January article, there are a number of predefined dialog components stored in AutoCAD’s base.dcl file. One quick way to locate and open this text file is by entering the following at AutoCAD’s command prompt:
(findfile "base.dcl")
Open base.dcl with Notepad and search for errtile. You’ll land on the following content that shows what makes up this tile (see Figure 6):
Firgure 6
Besides the dcl code defining this as a text tile that has no label and a width of up to 35 characters, there’s a very important attribute called key. The key attribute is defined as "error". So, the get_tile function references the content set in the errtile by using this key. After getting the content from errtile then the alert function is used to display this in the AutoCAD Message window as shown in the following portion of the code:
(alert (get_tile \"error\"))
In the next section I’ll discuss the function used to set the content of errtile.
Set…
The second dialog fun fact is the set_tile function. The set_tile function is similar to the get_tile function by again referencing the errtile with the key defined as "error". This is then followed by the content to be set which in this example is as follows:
(set_tile "error" "Hello")
Click the OK button to dismiss the previous dialog on the screen. This time, enter the following line of code again in its entirety before hitting the Enter key on the keyboard (see Figure 7):
Firgure 7
The following dialog opens now displaying in the AutoCAD graphics drawing area something different than previously (see Figure 8):
Firgure 8
Notice the content has changed in the lower left-hand corner from "Hello" to "Summer Olympics". This is because the set_tile function has now set that content with the following portion of code:
(set_tile "error" "Summer Olympics")
Also, when the Help button is clicked this time the AutoCAD Message window shows the new content by again using the combination of the alert and get_tile functions (see Figure 9):
Firgure 9
Action!!!
To bring it all together, the third dialog fun fact is the action_tile function. Again, like both get_tile and set_tile, action_tile references a tile with its defined key. In both the previous examples the Help button’s defined key is called "help" (see Figure 10):
Firgure 10
Then, this is followed by a statement surrounded by quotes that invokes the action to run when this button is clicked as shown in the following portion of code:
(action_tile "help" "(alert (get_tile \"error\"))")
Click the OK button to dismiss the previous dialog on the screen. This time, enter the following line of code again in its entirety before hitting the Enter key on the keyboard (see Figure 11):
Firgure 11
Notice the change in the dialog box this time. There’s no content shown in the lower left-hand corner because there’s no set_tile function implemented until after the Help button is clicked. Then, the action_tile function takes over and runs the set_tile function on the key defined as "error" with the content of "Hello!!!" (see Figure 12):
Firgure 12
A La Mode
I’m going to top this article off with one more bonus dialog fun fact called the mode_tile function. Again, like the previous three functions the mode_tile function references the tile’s key to make a change to the mode of the tile. For the purpose of this next example, I’ll focus on two mode settings:
0 which enables the tile for viewing
1 which disables or grays out the tile
To demonstrate these couple of mode_tile settings once again with Notepad, open the MyDcl.dcl text file for editing. This time, enter the following content in the file and save it (see Figure 13):
Firgure 13
This time, the custom dialog box is named MyDcl5 and also notice the addition of a fourth tile called info. Again, searching for info in the base.dcl file shows the following content for the Info button (see Figure 14):
Firgure 14
Before continuing, enter the following at the AutoCAD command prompt to remove the previous MyDcl4 dialog box definition from memory:
(unload_dialog dcl-id)
Then, at AutoCAD’s command prompt, enter the following lines of code again one after the other following each line with the Enter key (see Figure 15):
Firgure 15
Note that this time there are two action_tile lines of code. The first line refers to the Help button key, and the second the Info button key. These are each followed by the statement to run when the corresponding buttons are clicked.
So, when the Help button is clicked the action_tile causes the content in the errtile to change its look with the use of the mode_tile function. In this case, a setting of 1 disables or grays it out. Likewise, the opposite occurs when the Info button is clicked. The action_tile this time causes the content in the errtile to change its look to enabled. A mode_tile setting of 0 enables the tile (see Figure 16):
Firgure 16
The Excitement Continues…
I hope this follow up article, like the first, has introduced some easy learning methods using fun facts to implement custom dialog boxes in AutoCAD. Though we'll have to wait four years before experiencing more fun and excitement at the next Summer Olympics, we don't have to wait that long to experience the same when it comes to dialog box programming. In fact, we don't even have to wait another year for the next release of AutoCAD. But we can start customizing dialog boxes today and immediately see the fruits of our labor. It's so easy to just put into use the many tiles and clusters already defined for us in AutoCAD. So, let's start using the functions learned to implement your own custom dialog boxes now. There's no need to, “Get Ready…” or even, “Set…” but instead just, “Go into Action!!!”