Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

SSet all objects after specified object.

1 REPLY 1
SOLVED
Reply
Message 1 of 2
mdhutchinson
256 Views, 1 Reply

SSet all objects after specified object.

I wonder if I could get some input with this... I've had this function for quite a while, however, I am certain it is not as eloquent as it could be, also, if the enext is in fact the last object (or perhaps if enext is nil) this seems to still return a selection set - however, (not (zerop (sslength existsel))) throws an error. I do not know just why...rather, I'd like it to return nil.

 

 

(defun newsel  (enext                                                           ; next entity                            
               existsel
               /                                                                ; exist sel set                          
               elst
              )                                                                 ; Entity list                            
  (if  enext                                                                    ; if enext get                           
    (setq enext (entnext enext))                                                ; next entity                            
    (setq enext (entnext))                                                      ; first entity                           
  )

  (if  (and enext (null existsel))
    (setq existsel (ssadd))
  ) 
  (while enext                                                                  ; if a next entity                       
    (setq elst (entget enext))                                                  ; get entity list                        
    (if  (and (not (equal "ATTRIB" (cdr (assoc 0 elst))))                       ; get parent ent                          
             (not (equal "VERTEX" (cdr (assoc 0 elst))))                        ; not the                                
             (not (equal "SEQEND" (cdr (assoc 0 elst))))                        ; children                               
        )
      (ssadd enext existsel)                                                    ; add the ENEXT to the Sel Set           
    )
    (setq enext (entnext enext))                                                ; get the ENEXT                          
  )
  existsel
)

1 REPLY 1
Message 2 of 2
Kent1Cooper
in reply to: mdhutchinson

It looks like the usage of this would be:

 

(newsel anEntityName aSelectionSet)

 

and that either anEntityName or aSelectionSet could be supplied as nil, but that would need to be specified for the particular argument.

 

If the User [or the calling larger routine, or something] specifies nil for enext, it will start at [and set enext to] the first object in the database.  But if some entity name is supplied, it will start with the one following that, as the first of the objects to step through.

 

If nil is supplied for existsel, and there's some next object, it will start an empty selection set with the existsel name.  If an existing selection set is supplied for existsel, it will just keep it to start.  Then it will step through everything from the initial enext and newer, and for those that aren't "child" objects, add them to existsel.

 

Your error would happen if existsel itself is nil [not just empty], because (sslength) won't be able to handle that.  It looks to me as though the only way existsel can be nil is if it is supplied as nil in the argument and if enext is nil so that an empty existsel if not created.  Since, if enext is supplied as nil in the argument, it saves the first object in the database as enext, that can't result in a nil result unless there's nothing in the drawing.  If an entity name is supplied as enext in the argument, enext can end up nil before the question comes up whether to make an empty existsel set only if that supplied entity is the last in the database, so that the re-setting of it to the following entity results in nil.

 

About the only way I can picture it's returning a selection set when the enext supplied in the argument is the last drawn object and if nil is supplied for the existsel argument [in which case you would expect existsel to be nil in the end], is if that enext is a "parent" object.  That would result in enext being reset to the first child object under it [since it hasn't looked at what that is yet, to know whether it wants to deal with it], and not to nil.  That would cause an empty but non-nil existsel set to be established.  If no "child" object under the parent qualifies to be added to the set, existsel would still be there, but would be empty.  But that shouldn't give the error you mention.  So I'm confused, too.

 

I'm also unsure about some of the elements.  If existsel is supplied as an argument, it looks to me like the result would include everything in that, even things that are not newer than the enext argument.  Is that the idea?

 

I don't know whether any of that helps, but I'm just thinking out loud....

 

By the way, here's an elegance increase, to let it dig out the entity type only once:

 

    (if  (not (wcmatch (cdr (assoc 0 elst)) "ATTRIB,VERTEX,SEQEND")) ; parent, not children
      (ssadd enext existsel) ; add the ENEXT to the Sel Set
    )

 

or, using a list instead of (wcmatch):

 

    (if  (not (member (cdr (assoc 0 elst)) '("ATTRIB" "VERTEX" "SEQEND"))) ; parent, not children
      (ssadd enext existsel) ; add the ENEXT to the Sel Set
    )

Kent Cooper, AIA

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost