manipulating (splitting) a selection set

manipulating (splitting) a selection set

robert06
Collaborator Collaborator
1,628 Views
8 Replies
Message 1 of 9

manipulating (splitting) a selection set

robert06
Collaborator
Collaborator

Firstly creating a selection set of objects
(setq ss1 (ssget))

 

After that would like to create separate selection sets:
1) hatches from ss1 to delete them
2) change all other objects of ss1 to a layer

 

What would be the best way?

0 Likes
Accepted solutions (2)
1,629 Views
8 Replies
Replies (8)
Message 2 of 9

Kent1Cooper
Consultant
Consultant
Accepted solution

Something like this [untested] :

 

(repeat (setq n (sslength ss1))

  (setq ent (ssname ss1 (setq n (1- n)))); step through selection

  (if (member '(0 . "HATCH") (entget ent)); is it a Hatch pattern?

    (entdel ent); then -- remove it

    (command "_.chprop" ent "" "_layer" "YourLayerName" ""); else -- put it on Layer

  ); if

); repeat

 

EDIT:  That doesn't actually make separate selection sets  of the two categories of things, as you describe, but just deals with each entity individually.  If you really need them put into selection sets, it can also be done pretty easily.

Kent Cooper, AIA
Message 3 of 9

john.uhden
Mentor
Mentor
Accepted solution

ss1 is a collection of all the entities selected via ssget.

It is not a list, but each of its members can be inspected for varying properties.  For example:

(setq ss2 (ssadd)) ;; empty selection set waiting to be populated
(repeat (setq i (sslength ss1))
  (setq e (ssname ss1 (setq i (1- i))) ;; ename
        ent (entget e)  ;; entity data in dxf format
        etype (cdr (assoc 0 ent)) ;; entity type, e.g. CIRCLE, LINE, etc.
  )
  ;| Then you can decide how to handle each entity.  For instance if it's a hatch, then add it to ss2 and remove it from ss1...
  |;
  (if (= etype "HATCH")
    (progn
      (ssadd e ss2)
      (ssdel e ss1)
    )
  )
)
:| Of course I prefer to simplify code using (and ...) instead of (if ... (progn ...)), e.g.
  (and
    (= etype "HATCH")
    (ssadd e ss2)
    (ssdel e ss1)
  )
Just be aware that the (and ...) function will stop being evaluated at the first statement within it that returns nil.
Thanks go to Stephan Koster for that technique donated decades ago.
|;

John F. Uhden

Message 4 of 9

robert06
Collaborator
Collaborator

Thanks, that will do just fine.

0 Likes
Message 5 of 9

robert06
Collaborator
Collaborator

Thank you for the tutorial, got it.

0 Likes
Message 6 of 9

robert06
Collaborator
Collaborator

Separate selection sets enable manipulating ss1  subsequently, which helped me to add another step manipulating the objects.

0 Likes
Message 7 of 9

Kent1Cooper
Consultant
Consultant

@robert06 wrote:

Separate selection sets enable manipulating ss1  subsequently, which helped me to add another step manipulating the objects.


It sounds like you really just need one selection set to "survive" the operation, and you can still just dump the Hatch patterns.  In that case, the original selection set variable can remain, and what remains of it  at the end put on the desired Layer together.  How 'bout something like this [minimally tested  this time]?

 

(repeat (setq n (sslength ss1))

  (setq ent (ssname ss1 (setq n (1- n)))); step through selection

  (if (member '(0 . "HATCH") (entget ent)); is it a Hatch pattern?

    (entdel ent); then -- delete it [from the drawing -- don't really need to from the set ]

  ); if

); repeat

(command "_.chprop" ss1 "" "_layer" "YourLayerName" ""); put what's left of it on Layer

 

Kent Cooper, AIA
0 Likes
Message 8 of 9

john.uhden
Mentor
Mentor
I so much enjoy seeing responses like yours because you are helping
yourself, as opposed to those "needy" people who treat this place like a
freeware drive-thru.

John F. Uhden

0 Likes
Message 9 of 9

robert06
Collaborator
Collaborator

That was what I dared to ask for at first, you were right, but understood then, that another operation can be added!

0 Likes