Changing Styles (ts.lsp)

AutoCAD's Style command can be used to create or modify a text style, list existing styles or simply to make another pre-defined style current. In the last two cases however, the Style command's prompt sequence finds it a little tiresome. Listing the styles lists far more data than most people usually want and changing the current style requires a large number of [RETURNS] accepting defaults. TS is a quick little AutoLISP routine that simply prompts you for the new text style and does it. The only other option is "?" which will list the style names already defined without any superfluous information.

The Listing

After the program description header, the program name is defined and the four variables it uses are localized. The next line of code sets variable TS2 to a list containing the name of the first text style in the style table. The TBLNEXT function has a "T" argument to `rewind' the table listing and be certain of getting the first style.

A WHILE loop then starts up and runs as long as a call to get the next style doesn't return Nil, meaning it returned a style, setting TS3 to the style data list. The one line of code within the loop extracts the name of the style and stores it in variable TS2, each iteration of the loop adding another style name to the list.

After the WHILE loop is closed, a screen prompt is started. It is completed in the following line of code which appends the current style name and the ">: " to it. This line of code prints the style name in uppercase and stores any user response in variable UR2.

This is followed by a WHILE loop which runs while the user response was "?". It starts with the TEXTPAGE function switching to a cleared text screen and then prints a heading. Counter CTR2 is then initialized to zero and a REPEAT loop is then started which will loop through the number of style names stored in TS3. This will print a new line, and then the CTR2'th style name in the list in TS3 (remember that zero gets the first element in the list). CTR2 is then incremented by one so as to get the next style name in the next iteration of the loop. The REPEAT loop is then closed.

The prompt sequence requesting a new style name is then repeated and the While loop is closed. The GRAPHSCR function is then called to return the display to the graphics screen.

An IF then checks the user response and if it was not an empty string (the user did not hit [RETURN]), its then-expression will run. This is another If which searches the drawing's style table for the style name supplied by the user. If not found, its then-expression will run. This displays an alert box informing the user that the nominated style has not been defined and to use the Style command.

If the style was found in the style table then the IF’s else-expression will run. This, consists of two actions, grouped by a PROGN, which sets the Textstyle Setvar to the nominated style and then displays a prompt informing the user of the new current text style.

We then close of the PROGN and the two IFs and a PRINC function prevents the word nil from being printed to screen as the program exits.
 

©1996-2001 ZOTO Technologies