You are on page 1of 6

The AutoLisp Intermediat

Back to AutoLisp Intermediate Tutorial Back to AutoLisp Tutorial Homepage Back to AutoLisp Homepage Back to JefferyPSanders.com Homepage

Selection Set Functions


Functions - ssadd ssdel sslength ssname

Example P

ssadd - This function does one of three things depending on how many

If you use the ssadd function with no arguments it will return a Example : (setq myNewSet(ssadd))

If you use ssadd with a name of an entity it will return a new se member.

Example : (setq myNewSet(ssadd entityName

If you use ssadd with a name of an entity and name of an selec

T H E

set.

Example : (setq myOldSet(ssadd entityName

And return the selection set with the entity added to the se

Syntax : (ssadd) (ssadd entityName) (ssadd entityName Se

Where entityName is a valid entity name returned by ssna

Where selectionSetName is a valid name of a selection se Returns the selection set with the new entity added to it.

A U T O
)

Example: (<Selection set: 1>

Example: Let's build a function that allows me to add items to a s (defun C:BldSet() (setq mySet(ssadd)) (while(/= (setq enS(entsel)) nil) (setq en(car enS)) (setq mySet(ssadd en mySet))

;defin a p

;build an

;loop unti

;get the e

;add the

L I S P

) Now at the Command prompt type: Command: move<enter> Command: !mySet<enter>

;don't forget the exclamation po

Did everything get selected to be moved? Cool. Move individual everything get selected again? Cool. Why? Because AutoLisp finds the location.

ssdel - This function does the opposite of ssadd. SSDEL removes an en


Syntax : (ssdel entityName selectionSetName)

I N T

Where entityName is a valid entity name returned by ssna

Where selectionSetName is a valid name of a selection se Returns a new selection set without the entity. Assuming en1 is a valid entity and en2 is not. Assuming ss1 is a valid selection set and ss2 is not.

E R M E D I A T E T U

Assuming en3 is a valid entity name but is not part of any selec (ssdel en1 ss1) (ssdel en1 ss2) (ssdel en2 ss1) (ssdel en2 ss2) (ssdel en3 ss1)

;returns sele

;returns ERR

;returns ERR

;returns ERR ;returns nil

Note: If you filter correctly using the ssget "X" function, you

sslength - This function returns the number of entities inside a selection


Syntax : (sslength selectionSetName)

Where selectionSetName is a valid name of a selection se

Returns a real number if the number is greater than 32,767, oth The number, real or integer, represents the quantity of Assuming ss1 is a valid selection set containing 15 entities. Assuming ss2 is a valid selection set containing 1 entity. Assuming ss3 is a valid selection set containing no entities.

Assuming ss4 is a valid selection set containing 40,000 entities. Assuming ss5 is not a valid selection set. (sslength ss1) (sslength ss2) (sslength ss3) (sslength ss4)

;returns 15 ;returns 1 ;returns 0

;returns 40

T O R I A L

(sslength ss5)

;returns ER

ssname - This function returns an entity name contained inside a selecti


Syntax : (ssname selectionSetName nthItem)

Where selectionSetName is a valid name of a selection se

Where nthItem is an integer representing an index into th

Note: nthItem needs to be a real if the set contains mor Returns an entity's name on success and nil on error. Assuming ss1 is a valid selection set containing 15 entities.

Assuming ss2 is a valid selection set containing 40,000 entities. Assuming ss3 is not a valid selection set. (ssname ss1 0) (ssname ss1 3) (ssname ss1 24) (ssname ss1 -3) (ssname ss2 34555) real) (ssname ss2 34555.0)

;returns th

;returns th

;returns ni

;returns ni

;returns ER

;returns th

End of Selection Set Functions

Example Program 1:

I will write a program that prints the layer name of every entity in a selec

(defun C:pLay() (if (setq eset(ssget) (progn statement (setq cntr 0) (while (< cntr (sslength eset))

;define

;use the

;use pro

;set the ;while

;note: the length is one more than the index of items since the fir to the ;first item in a selection set consisting of one item you wo eset 1). (setq en(ssname eset cntr)) with cntr (setq enlist(entget en)) (setq layName(cdr(assoc 8 enlist))) (princ "\n ") printed (princ layName) line (setq cntr(+ cntr 1)) ) ) ;get ;get

;get

;pr

;p

;i

;c

;c

(princ "\n Error - No entities selected.") ;p

; note: the if statement can be a " if then " statement or a " if then e ) )

Note: I personally do not find any of these functions useful except for

If you use your ssget "X" filters well enough there is no reason for th There are other selection set functions that are even less useful such

When you loop through your selection set you can check an entities D whether the entity is one to either skip or work on. So, you can avoid Don't get me wrong. I'm not saying they are completely useless and why bother.

AutoLisp Intermediate Tutorial AutoLisp Tutorial Home AutoLisp Home Home All questions/complaints/suggestions should be sent to Last Updated January 4th, 2012

Copyright 2002-2012 JefferyPSanders.com. All r

You might also like