if selection set then ......

if selection set then ......

neam
Collaborator Collaborator
1,637 Views
9 Replies
Message 1 of 10

if selection set then ......

neam
Collaborator
Collaborator

hi every body

I have a selection set (by (ssget "X".........) that sometimes includes:

1-many objects (text and mtext and maybe lwpolyline) 

and sometimes:

2-includes two objects (one text and one lwpolyline)

How can I just delete text if it is the first(1) mode?

How can I clear selection set if it is the second(2) mode?

Thank you for your help

 

 

0 Likes
Accepted solutions (1)
1,638 Views
9 Replies
Replies (9)
Message 2 of 10

Kent1Cooper
Consultant
Consultant

If, when it contains only two objects, it is always and only those particular two kinds, and if  ss  is the variable name, how about....?

 

(if (> (sslength ss) 2)

  ();;;; then -- delete Text [do you know how to do that?] .... [also Mtext?] ....

  (setq ss nil); else -- clear selection set

); if

Kent Cooper, AIA
0 Likes
Message 3 of 10

neam
Collaborator
Collaborator

Hi kent1cooper

thank you for reply

yes I want delete just only text object when is (>(sslength ss) 2)

0 Likes
Message 4 of 10

Kent1Cooper
Consultant
Consultant

Conveniently, you can have it find the Text objects from within the  Previous selection:

 

(if (> (sslength ss) 2)

  (command "_.erase" (ssget "_P" '((0 . "TEXT"))) ""); then

  (setq ss nil); else -- clear selection set

); if

 

[That doesn't account for possible locked Layers, but it could be made to, if necessary.]

Kent Cooper, AIA
0 Likes
Message 5 of 10

neam
Collaborator
Collaborator

Dear kent1cooper

your answer is absolutely correct when my selection set more than 2 objects.

but:

if selected objects is equal to 2 entities (text and polyline) then clear selection set.

If selected objects Is equal to 2 entities (text and mtext) then erase only text object.

 

0 Likes
Message 6 of 10

Kent1Cooper
Consultant
Consultant

@neam wrote:

….

If selected objects Is equal to 2 entities (text and mtext) then erase only text object.

….


That combination was not among the possibilities in your original description, nor did you answer the first sentence in Message 2 with any qualifications.  That can be done, but are there any other possibilities you haven't listed yet?

Kent Cooper, AIA
0 Likes
Message 7 of 10

neam
Collaborator
Collaborator

You are completely right.

The main reason for this error is that my English is weak.

I no haven't other possibilities in listed.

thank you very much Because of the time you left for me.

0 Likes
Message 8 of 10

pbejse
Mentor
Mentor

@neam wrote:

if selected objects is equal to 2 entities (text and polyline) then clear selection set.

If selected objects Is equal to 2 entities (text and mtext) then erase only text object.


Since you are using (ssget "X"),  then included a filter for ONLY Mtext.

 

(ssget "X" '((0 . "MTEXT")))

 

or better yet, use other filters to limit the selection that meets your requiements, like layer , position, string value...

 


@neam wrote:

If selected objects Is equal to 2 entities (text and mtext) then erase only text object.


Erase on the drawing or remove from the selection?

 

0 Likes
Message 9 of 10

Kent1Cooper
Consultant
Consultant
Accepted solution

@neam wrote:

....

if selected objects is equal to 2 entities (text and polyline) then clear selection set.

If selected objects Is equal to 2 entities (text and mtext) then erase only text object.

 


How about this?  If you have only three possible situations, and you want to erase all the Text objects in two of them [more than 2 objects, or Text + Mtext], then all you need to do is test for the 3rd situation [2 objects including a Polyline].  Minimally tested:

 

(if (and (= (sslength ss) 2) (ssget "_P" '((0 . "*POLYLINE"))))
  (setq ss nil); then -- clear selection
  (command "_.erase" (ssget "_X" '((0 . "TEXT"))) ""); else -- erase Text
); if

 

If your (ssget "X" ...) establishing the selection set included filtering, such as by Layer or in only the current space, include the same filtering in the (ssget) in the Erase command.

Kent Cooper, AIA
0 Likes
Message 10 of 10

neam
Collaborator
Collaborator

Tank you very much kennet

I tested your solution in my work and came up with the desired result

Thanks again

0 Likes