请查看此代码:
- ;;*****************************************************************************
- ; LASTN.LSP V1.0 by Zoltan Toth
- ; ZOTO Technologies,
- ; 23 Greenhills Dve,
- ; Melton, 3337.
- ; E-MAIL: zoltan.toth@ains.net.au
- ; WWW: http://www.ains.net.au/zoto/
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; This program will select the last n objects created in a drawing where n
- ; is an integer input by the user. This is most useful when you create a
- ; number of objects with the COPY, MIRROR or ARRAY commands and you wish to
- ; work with the ones just created. LASTN has been written so that it can be
- ; used in three different ways for maximum flexibility. First, it can be
- ; called by itself at the "Command:" prompt and the objects so selected can
- ; be accessed by a later command with the "Previous" option. Second, it can
- ; be called transparently (with a preceding apostrophe) at a "Select
- ; objects:" prompt and the objects selected will be passed back to the
- ; waiting command. Since it can be tedious to type in the preceding
- ; apostrophe, it is best to incorporate this command in the menu with the
- ; apostrophe included to make it a quick "single pick" invokation. Thirdly,
- ; as the (LASTN) function is not nested within (C:LASTN), it can be called
- ; (with an integer argument) by other programs. As an example, to set symbol
- ; SS1 to a selection set containing the last 5 objects created, use:
- ;
- ; (setq SS1(lastn 5))
- ;
- ; Any program that utilizes the (LASTN) function should, of course, check
- ; to see if it is already loaded and if not, load it. The following AutoLISP
- ; code would be satisfactory in most cases:
- ;
- ; (if(not LASTN)(load "LASTN"))
- ;
- ; Note that although AutoCAD's "Last" option selects the last drawn
- ; object visible, at least partially, on screen, LASTN always selects the
- ; last n drawn objects, whether visible on screen or not. This includes
- ; objects on layers that are OFF or FROZEN. Objects on LOCKed layers are
- ; also selected but cannot be edited whereas objects on FROZEN or OFF layers
- ; can be edited. Caution: don't specify a value higher than the number of
- ; objects you have created in the current space (Paper or Model) since you
- ; last entered that space ie. changed TILEMODE - the results won't be what
- ; you want.
- ;;*****************************************************************************
- (defun lastn (INT2 / SS2 SSL2) ;define function to take 1 argument
- (setq SS2 (ssadd)) ;set SS2 to an empty selection set
- (repeat INT2 ;repeat INT2 times
- (if (entlast)
- (progn
- (ssadd (entlast) SS2) ;add last undeleted object to selection set
- (entdel (entlast)) ;delete last undeleted object
- )
- )
- )
- (setq SSL2 (1- (sslength SS2)));set SSL2 to 1 less than size of selection set
- (while (>= SSL2 0) ;while SSL2 is greater than or equal to zero
- (entdel (ssname SS2 SSL2)) ;undelete SSL2'th object in selection set
- (setq SSL2 (1- SSL2)) ;decrement SL2
- )
- SS2 ;return selection set to calling function
- ) ;end (lastn) function
- (defun C:loo (/ COUNT2) ;define function
- ;set COUNT2 to number of objects
- (setq COUNT2 (getint "\nEnter number of objects: "))
- (if (= 0 (getvar "CMDACTIVE")) ;if no other command is active
- (progn ;else
- (command "._SELECT" (lastn COUNT2) "") ;run SELECT command and (lastn)
- (princ) ;exit quietly
- )
- (lastn COUNT2) ;call (lastn) function with argument
- )
- )
使用这个,我必须插入创建的对象的数量;我想用这样的东西,但要插入这样的东西。。。lc-上次创建,不是数字。。。。当我使用autocad中的select命令时,我说L-last,我将只选择最后创建的对象,使用类似LC-last created的东西,我想选择所有10个。。。或使用最后一个命令创建25个对象。怎样 |