AN ARRAY OF OPTIONS (array.lsp)Array is one of AutoCAD's more useful commands but it does lack some flexibility. It also lacks documentation. There are in fact three options for the Array command but only two are documented: Rectangular and Polar. The third, "C" (for Circular?) has been around since at least Release 10 but there is no documentation for it that I have found. I discovered it by accident one day when I hit "C" instead of "P".This month we will be looking at a replacement for the Array command that will have a total of four options: Rectangular, Divided, Polar and Circular. Divided is a variation on Rectangular which asks for the number of columns and rows, and then the distance/s in each direction to fill. The spacing of each element of the array is then calculated to just fill the distance/s. This is similar to the Polar option in which the angle between each element is calculated to just fill the angle supplied by the user. Incidentally, the "C" option asks for the angle between each element. The ListingAfter the program description there are two lines of code before the DEFUN statement. Since it is not inside a DEFUN, it will run when the program is loaded. The code undefines the standard Array command and informs the user that the Array command is being redefined.The next line contains the DEFUN statement, defining the program name and localizing variables. Variable CMD is set to the current value of the CMDECHO Setvar for restoration later and CMDECHO is then set to zero to turn off command echoing. The next line uses SSGET to prompt the user to select some objects and these are stored in selection set SS2. The INITGET function is then used to initialize the four keywords for the GETKWORD function following and the number 1 immediately following the INITGET prevents the user from not supplying a keyword. The user response is then stored in variable OPT2. An IF function then checks the value in OPT2 and if it is "Divided", its then-expression, grouped by a PROGN, is run. This expression in fact takes up most of the rest of the program. It starts with an INITGET function with 6 as an argument. This forces the user to supply either a positive number or [RETURN] to the following GETINT function which is then stored in variable NROW2. The IF which follows checks if NROW2 has a value and if not (meaning the user hit [RETURN]), it will set NROW2 to 1, the default shown in the prompt. The next five lines of code will do the same but with variable NCOL2. NROW2 & NCOL2 now hold the number of rows and columns for the array. The following IF then checks if the values in NROW2 and NCOL2 are both 1. If so, its then-expression will run, informing the user that a one-element array has been requested and that there is nothing to do. If either or both variables had a number other than 1 then its else-expression, grouped by a PROGN, will run. This starts with an IF checking if the value in variable NROW2 is greater than 1. If so, it will use INITGET to prevent the following GETDIST function from accepting a zero or no value. This value will be stored in variable VDIST2. This value is then divided by one less than the number of rows to obtain the distance between each row and is stored in variable VDIST3. This procedure is repeated if NCOL2 has a value higher than one with the obtained distance stored in variable HDIST2 and the divided distance stored in variable HDIST3. A COND function is then employed to decide which Array command sequence to run. If the array is to have only one row, the Array command does not request a distance between columns and the same thing applies with columns. This means that three different response sequences are required to handle all possible situations. There is no need to run a test for the third command sequence - it is the only option left. Note the period and underscore preceding the ARRAY argument in the command sequence. The period ensures that the Array command will still work if undefined. Since loading the program undefines the Array command, it is imperative that the period be there. The underscore is less critical - it simply ensures that the program will run on non-English versions of AutoCAD. The underscore but not the period are also applied to command option keywords. If you are running Release 11 or earlier, leave out the underscore - it's only supported from R12 on. Some closing parentheses close off the various PROGNs and IFs until we close off the then-expression for the IF which checked for the "Divided" option keyword. We then start its else-expression which simply starts the Array command and passes it the selected objects and the option keyword given by the user. The command is left "open" to directly request the user for more input. Once finished, the CMDECHO setvar is restored to its original value and the PRINC function prevents its value from being printed to screen as it exits |
©1996-2001 ZOTO Technologies