AutoCAD 2002 Bible

Скачать в pdf «AutoCAD 2002 Bible»


(defun c:listsset (/ mysset counter)


(setq mysset (ssget))


(setq counter 0)


(while (< counter (sslength mysset))


(terpri)


(princ (cdr (assoc 0 (entget (ssname mysset counter))))) (setq counter (+ counter 1))


)


(princ)


)


2.    Load ab35-4.lsp.


3.    Activate AutoCAD and draw any number of objects onscreen — at least two different types of objects.


4.    Type listsset J. AutoCAD prompts you to select objects (because of the ssget function).


5.    Select all the objects in your drawing. The routine prints the type of each object you selected. (Press F2 to open the AutoCAD Text window to see the entire results.) Figure 35-7 shows the result. Of course, your result will be different because you probably drew different types of objects.


Figure 35-7: One possible result of the listsset routine


Command: 1i s t sse t


Se1ect ob j ect s; all 5 f ound


Se1ec t ob j ects:


LWPOLYLINE


CIRCLE


TEST


LINE


LINE


Here’s how this routine works:


♦    Line 1 creates a function and declares two variables, mysset and counter.


♦    Line 2 sets the mysset variable equal to the selection set that the user provides using SSGET.


♦    Line 3 sets the counter variable to zero.


♦    Line 4 starts a while loop. Working from the innermost set of parentheses, first you obtain the number of objects in the mysset selection set, using sslength. Then you specify that the WHILE loop will continue as long as the counter is less than the number of objects in the mysset selection set. In other words, when the routine has cycled through all the objects in the selection set, it stops.

Скачать в pdf «AutoCAD 2002 Bible»