CURRENT OFFSETS (ofc.lsp)The OFFSET command is one of the most useful in AutoCAD but has room for improvement. The new object it creates has the same layer, colour and linetype as the original object but often you would like the new object's properties to have the current settings. OFC (OFfset to Current) is an AutoLISP program that does that by repeatedly running the OFFSET command and changing the properties of the last created object to the current settings.The ListingAfter the program description the program name is defined and variables localized. The value for the CMDECHO Setvar is saved to variables for restoration later as the program will be changing it. The OFFSETDIST Setvar is also copied to variable OD2 but not for restoration - it will be needed by the program for processing. This Setvar contains a real number but the OFFSET command has a unique way of using it. The offset distance can either be an actual distance or it can be Through and the OFFSETDIST Setvar is either set to the offset distance value or -1.0 to denote the Through setting. In order to determine the offset distance or its Through setting, an IF tests to see if the value in variable OD2 is negative and if so, changes the value in OD2 to "Through" else OD2 is set to the numerical value of OFFSETDIST converted to a string.The CMDECHO Setvar is then set to zero to prevent command sequences being prompted to screen. This is followed by an INITGET function which initializes two keywords, "Through" and "CAL", for the following GETDIST function. It also prevents them from supplying a zero or negative value but allows a [RETURN]. This GETDIST function prompts the user for an offset distance, displaying the current value as the default and then sets variable OD3 to the user response. Note that the GETDIST function allows distance input by picking 2 points on the screen. An IF function checks to see if the user response was "CAL" and if so will run its then-expression, a PROGN group. This checks if the geometric calculator is loaded by checking for the existence of the CAL variable. If it doesn't exist, the geometric calculator will be loaded with the XLOAD function. XLOAD is used to load ADS files the same way that LOAD loads AutoLISP files. The calculator is then run, the value it returns being stored in variable OD3. Another IF checks if variable OD3 has no value which means that the user hit [RETURN] to accept the default value. If so, the OFFSETDIST Setvar is checked to see if it is negative. If negative, OD3 is set to "Through" else OD3 is set to the current value of OFFSETDIST. In order to accurately simulate the operation of the OFFSET command, the OFFSETDIST Setvar needs to be set to whatever value the user has input. This is done by using an IF to check variable OD3 for the value "Through". If true, OFFSETDIST is set to -1.0 else it is set to the current value of OD3. The user is then prompted to select an object. The ENTSEL function employed returns a list containing the object name and the point through which it was picked. The point is stored in variable P2. If a point was picked such that no object was selected, ENTSEL will return nil and variable P2 will also be set to nil. A WHILE loop is then started which will repeat as long as P2 has a value. This loop starts with the COMMAND function running the UNDO command to start a group for each iteration of the loop undoable by a single U command. The following COMMAND function runs the OFFSET command using variable OD3 to supply the offset distance and P2 as the point to select the object. Note that the OFFSET command cannot take an object to offset - it takes a point and uses that point to find an object. The COMMAND function is then suspended with the OFFSET command only half complete while OD3 is checked to see if its value is a real number. This is used to determine which prompt will be used to prompt the user for the second point. If OD3 is a real, the user is prompted to select the side to offset else they are prompted for the through point. The COMMAND function is then restarted with a pause that allows the user to pick the point for the offset. The two double quotes then terminate the OFFSET command. A new COMMAND function runs the CHANGE command which changes the most recent created object to the current layer, colour and linetype. One more COMMAND function is started to end the UNDO group started at the beginning of this WHILE loop. The user is then prompted to pick a new object to offset using the ENTSEL function as previously described to pass a point to variable P2. Picking a blank part of the screen or hitting return will set P2 to nil and terminate the WHILE loop. Once the loop has been terminated, CMDECHO has its original value restored
and the PRINC function prevents the value of CMDECHO from being printed
to screen when the program ends.
|
©1996-2001 ZOTO Technologies