As written, the current function will return the value returned by the setvar function, which will be the name of the original layer. We can add a (princ) expression to the end of the function definition to suppress the value returned by the last evaluated expression. However, there are few other enhancements that we can make here. (while (= 1 (logand 1 (getvar 'cmdactive))) Putting everything together, we have: (defun c:testfunction ( / old ) The above will continue to pause for user input whilst a command is active. Hence the test expression for our loop can be: (= 1 (logand 1 (getvar 'cmdactive)))Īnd now it just remains to construct the loop itself - for this, we can use the AutoLISP while function: (while (= 1 (logand 1 (getvar 'cmdactive))) Which will return 1 if a command is active, else 0 otherwise. To test whether bit code 1 is set, we can use the AutoLISP logand function, which returns the bitwise AND of two supplied integers, e.g.: (logand 1 3) => 1Ĭombining this with the CMDACTIVE system variable we have: (logand 1 (getvar 'cmdactive)) However, this only pauses for a single input, and the AutoCAD LINE command will accept an arbitrary number of inputs, and so we need a way to construct a loop and determine when the user has finished with the command.įor this, we can make use of the CMDACTIVE system variable, which is a bit-coded system variable indicating the current command state - a bit code of 1 indicates that a command is active. \\.Īside: the pause symbol also evaluates to a backslash, but since this symbol is not protected and may be redefined, I would always recommend using a literal backslash.Īnd so we might use: (command "line" "\\") However, since the backslash is an escape character in AutoLISP, you'll need to prefix it with another backslash in order to output a literal backslash to the command, e.g. To pause for user input in an AutoCAD command invoked from an AutoLISP program or toolbar macro, you use the backslash \. Your current code will evaluate the expression (setvar 'clayer OLD) before the user has supplied the first line point, as there is no pause for user input. Since the AutoCAD LINE command can issue an arbitrary number of prompts to the user (depending on the number of lines they wish to draw), you'll need to include a loop within the code to allow for an arbitrary number of user inputs, before resetting the current layer.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |