Rebuild a selection set

Rebuild a selection set

msarqui
Collaborator Collaborator
652 Views
4 Replies
Message 1 of 5

Rebuild a selection set

msarqui
Collaborator
Collaborator

Hello guys,

 

May I have your help, please?

I am stuck in a problem. Let's say I have a selection set with TEXTS and MTEXTS. Then, I EXPLODE this selection set to have only TEXTS.

So, the selection set is no longuer good to use because it does not have those new TEXTS.

It would be possible to "rebuild" that selection set, without the need to "manually" select those new TEXTS? In another words, it would be possible to add the new TEXTS to the selection?

Here is what I am trying:

 

(defun c:EMT ()
(setq ss (ssget '((0 . "*TEXT"))))
(setvar "qaflags" 1)
(command "_.explode" ss "")
(command) 
(setvar "qaflags" 0)
;How do I rebuild the ss selection set here to include the new texts?
)

Thanks

Marcelo

0 Likes
Accepted solutions (1)
653 Views
4 Replies
Replies (4)
Message 2 of 5

ВeekeeCZ
Consultant
Consultant
Accepted solution

As most of these "convert" function EXPLODE does not convert MTEXT to TEXT, but creates a new TEXT entity.

TEXT entity leave without any change.

 

So the procedure will follow these steps:

- save the last entity in the drawing, start a new ss (selection set)

- go thru the old ent on ss and add ent into new ss all those entities which still exists in the drawing (if (entget ent) is T) = all TEXT ents

- all new entities coming from EXPLODE command add into new ss as well = all TEXTs converted from MTEXTs

 

Spoiler
(defun c:EMT ()
  (setq ss (ssget '((0 . "*TEXT"))))

  (setq enlast (entlast)
	ssn (ssadd))

  (setvar "qaflags" 1)
  (command "_.explode" ss "")
  (command)
  (setvar "qaflags" 0)

  (repeat (setq i (sslength ss))	
    (if (and (setq en (ssname ss (setq i (1- i))))
	     (entget en))
      (ssadd en ssn)))

  (while (setq enlast (entnext enlast))
    (if (entget enlast)
      (ssadd enlast ssn)))

  (setq ss ssn)
)

 

Message 3 of 5

Kent1Cooper
Consultant
Consultant

@msarqui wrote:

... I have a selection set with TEXTS and MTEXTS. Then, I EXPLODE this selection set to have only TEXTS.

So, the selection set is no longuer good to use because it does not have those new TEXTS.

.... it would be possible to add the new TEXTS to the selection? ....


It's easier than you think.  The results of Explode are always stored as the "Previous" selection.  The Text entities that were rejected by the Explode command will still be in the ss selection set, so you just need to add the Previous selection to ss.  Add this at the end:

 

(setq ssM (ssget "_P")); the Text entities resulting from Exploding Mtext
(repeat (setq n (sslength ssM))
  (ssadd (ssname ssM (setq n (1- n))) ss)
; add each one to ss that still contains previous Text
); repeat

Kent Cooper, AIA
0 Likes
Message 4 of 5

dbroad
Mentor
Mentor

@ВeekeeCZ and @Kent1Cooper have given you most of the solution.  @ВeekeeCZ 's solution is the most comprehensive, acknowledging that the original selection set will contain enames that are unreferenced(marked deleted) after the explode command.  There is one change that I would make to @ВeekeeCZ 's code.  Using the last entity method, you need to get the very last entity.  Every now and then, the last entity could be an attributed block reference.  The entnext in this case would get the first attribute of the last block reference in the drawing.

 

(setq lastent (entlast))
(while (entnext lastent) (setq lastent (entnext lastent)))

;;this would prepare the get the first exploded text entity rather 
;;than a possible attribute

You could also use a ssdel method to run through the first selection set to delete the deleted objects and use Kent's method of adding the previous selection set rather than everthing after the last entity.

 

Another approach would be to loop through the first selection set looking for mtext entities. Create a new empty selection set and transfer only text entities to the new selection set.  Explode only mtext objects one at a time and add the previous selection set to the new selection set.  Exploding one at a time keeps you from needing to change the qaflags system variable which can be dangerous if you don't add an error handler to change it back.

Architect, Registered NC, VA, SC, & GA.
Message 5 of 5

msarqui
Collaborator
Collaborator

Thank guys,

BeekeeCZ's solution is pretty cool for my needs.
 
Marcelo
0 Likes