Professional Documents
Culture Documents
Back to AutoLisp Intermediate Tutorial Back to AutoLisp Tutorial Homepage Back to AutoLisp Homepage Back to JefferyPSanders.com Homepage
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.
T H E
set.
And return the selection set with the entity added to the se
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: 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
Did everything get selected to be moved? Cool. Move individual everything get selected again? Cool. Why? Because AutoLisp finds the location.
I N T
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
Note: If you filter correctly using the ssget "X" function, you
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 40
T O R I A L
(sslength ss5)
;returns ER
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
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
;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
; 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