Layer Control (lc.lsp)Often you need to freeze a layer that an object is on and you don't know the name of the layer. You can run the List command on it to find out but wouldn't it be quicker to just pick the object? This month's Lisp file does just that. It even goes 'into' Blocks and Xrefs and extracts the layer name of the selected object and prompts the user to freeze, lock (or unlock) or turn off the layer the object is on.The ListingAfter the customary description header, the program's name defined and the variables it uses are localized. This is followed by a SETQ function which saves the value of Cmdecho and Expert Setvars for restoration later since LC will be changing them. This is evident on the next line with Cmdecho being changed to zero so as to suppress the commands issued by LC from being echoed on the command line.The IF function on the following line checks to see if the value of the Expert Setvar is zero and if so, the value of Expert is set to 1 on the next line. Setting Expert to 1 will suppress the warning that the user is turning off the current layer as this would upset the program's command sequence when turning off the current layer. After the IF function is closed, a COMMAND function runs the Undo command to group the program into a single Undo. The next line sets variable ENT2 to the list returned by the NENTSEL function when an object is picked. The line following uses the IF function to see if ENT2 has a value ie. an object had been picked. If so, its then-expression, which involves most of the rest of the program, grouped by a PROGN, will run. This starts with a check to see if there are four elements in the list stored in ENT2, meaning that a complex object such as a block was picked. If so, another IF checks the first character of the block name to see if it is an asterisk (*), meaning that it was an anonymous block such as a hatch or a dimension. The code to extract the first character is heavily nested to avoid the overhead of defining a variable that is needed for a very short time as well as an additional PROGN to group in the extra step. If the first character is an asterisk, the IF's then-expression will run, extracting the layer of the block rather than that of the object within the block which would be on layer 0. If not, the IF's else-expression will run, extracting the layer name of the sub-entity. Either way, the layer name will be stored in variable LAY2. If the selected object was not a complex entity, the else-expression for that IF function will run. This simply extracts the layer name of that object and stores it in LAY2. The Layer table of the drawing is searched for the status of the layer in variable LAY2 and stores the status value in variable LS2. An If then checks to see if the layer is currently locked by the value in LS2. If it is either 68 or 116, the layer is locked. (68 means that it is a `local' layer and 116 is an Xref layer.) This is used to determine the next prompt to the user. If the layer is locked, the IF’s then-expression, grouped by a PROGN, will run. An INITGET function uses the '1' argument to prevent the user from not providing a response, and initializes the allowable keywords. The user is then prompted for the action to be taken with the layer (Freeze, Unlock or turn Off) with the response stored in variable KWD2. If the layer was not locked, the IF's else-expression will run. This is identical to the then-expression except that the "Lock" keyword replaces "Unlock". The program then checks if the layer to be modified is the current layer and also if it is to be turned off. If both of these are true then an alert box is displayed warning the user that they are turning off the current layer. Another IF function following then checks to see if the layer to be modified is the current layer and if the requested action is to freeze it. If so, an alert box is displayed, informing the user that it cannot be frozen as it is the current layer. If either one or both of the test statements are false (it is not the current layer and/or it is not to be frozen), then the IF's else-expression will run. This starts with the COMMAND function carrying out the action. A prompt is then started, printing the word "Layer" and then the layer name stored in variable LAY2 to the command line. A COND function is then used to determine which word should then be appended so as to correctly inform the user of what action has been taken. A series of closing parentheses closes of various PROGNs and IFs until we are back at the else-expression for that IF early in the program which checked to see if an object had been selected. This expression displays an alert box informing the user that no object had been selected. The IF is then closed. The Undo group is then closed off and the Cmdecho and Expert Setvars
are then restored to their original values. The PRINC function is then
called to prevent the value of Expert being echoed to the command line.
|
©1996-2001 ZOTO Technologies