Select All (By Entity Type)

Select All (By Entity Type)

ebsoares
Collaborator Collaborator
2,782 Views
14 Replies
Message 1 of 15

Select All (By Entity Type)

ebsoares
Collaborator
Collaborator

Hi, all.

 

I've received some sweet help on a lisp routine yesterday (thanks @SeeMSixty7) and am now trying to apply the concepts to another, similar lisp routine.

What this one is supposed to do is make a selection of all instances of a specific entity type (requested by the user).

 

Here's the code so far:

(defun C:test (/ steaSelection steaString)
	
	; Prep initget with all possibilities:
	(initget (strcat "Text MText MLeader"))
	
	; Set *answerSTEA* with user input:
	(setq *answerSTEA*
		(cond
			( (getkword ; offer user a list of options
				(strcat "\nChoose [Text/MText/MLeader] <"
					(setq *answerSTEA* ; define default or previous choice
						(cond (*answerSTEA*) ("MLeader"))
					) ">: "
				)
			) )
			(*answerSTEA*) ; option if user just presses enter
		)
	)
	
	; Set steaString entity type based on *answerSTEA* variable:
	(cond
		((eq *answerSTEA* "Text") (setq steaString "Text"))
		((eq *answerSTEA* "MText") (setq steaString "MText"))
		((eq *answerSTEA* "MLeader") (setq steaString "MultiLeader"))
	)
	(if (> "*" "")
		(setq ss (ssget "_X" '((0 . *answerSTEA*))))
	)
	(if (zerop (getvar "CMDACTIVE"))
		(progn (sssetfirst ss ss)
			(princ "\nAll targeted elements selected (even on frozen layers)")
			(princ)
		)
		ss
	)
)

The part in bold is the one that's not cooperating right now (before this point the code works as expected)).

 

In (setq ss (ssget "_X" '((0 . *answerSTEA*)))) if we replace *answerSTEA* with , say, "Text" then it works - it selects all text elements in the drawing. So, I think that somehow the global variable *answerSTEA* is not working well in the IF conditional statement.

 

Any thoughts?

 

Thanks in advance,

 

Edgar

0 Likes
Accepted solutions (2)
2,783 Views
14 Replies
Replies (14)
Message 2 of 15

SeeMSixty7
Advisor
Advisor
Accepted solution

This is pretty much the same issue as yesterday.

 

Replace

(setq ss (ssget "_X" '((0 . *answerSTEA*))))

with

(setq ss (ssget "_X" (list (cons 0 *answerSTEA*))))

 

Remember that the ' in front of the Parenthesis means QUOTE (aka use verbatim what follows) No variables will be evaluated inside a quote.

 

Hope that helps.

 

Message 3 of 15

Shneuph
Collaborator
Collaborator

See post 2 here:

http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/selection-based-on-entity-type/m-p/65...

 

Same problem.

---sig---------------------------------------
'(83 104 110 101 117 112 104 64 71 109 97 105 108 46 99 111 109)
Message 4 of 15

ebsoares
Collaborator
Collaborator

You did it again, @SeeMSixty7! Thanks for re-pointing that out Smiley Happy

Thanks for the comment, too, @Shneuph.

 

It turns out, besides the problem with using quotes, I was also using the wrong variable! That line should use steaString, instead of *answerSTEA*, as that was causing other problems as well.

 

Again, I really appreciate all the help I've been given.

 

Edgar

0 Likes
Message 5 of 15

ВeekeeCZ
Consultant
Consultant

What is the point of (> "*" "") condition? It's always T.

 

No need for (strcat) -> (initget (strcat "Text MText MLeader"))

 

But you can have 

 

  (initget (setq keys "Text MText MLeader"))
  (getkword (strcat "\nChoose [" (vl-string-translate " " "/" keys) "]: "))

...don't forget (vl-load-com)

 

 

 

Other ways... working with the LISTs...

 

  (setq lst '(("Text" . "Text")
	      ("MText" . "MTEXT")
	      ("MLeader" . "MULTILEADER")))
  (setq steaString (cdr (assoc *answerSTEA* lst)))

... or

 

  (setq steaString (nth (vl-position *answerSTEA*
			  '("Text" "MText" "MLeader"))
			  '("TEXT" "MTEXT" "MULTILEADER")))

Have fun!

Message 6 of 15

ebsoares
Collaborator
Collaborator

Sweet! Smiley Very Happy

 

Thanks, @ВeekeeCZ!

0 Likes
Message 7 of 15

ebsoares
Collaborator
Collaborator

Hi again.

 

The lisp is now working very well... except it's working too well...

If we want to select all text elements in the file, it does that, but it also selects elements on layers that are turned off and/or frozen. If we go on and, say, make some property changes to the text elements, like changing the colors to blue, all the selected elements change as one - even the ones on layers that are off/frozen.

 

Is there a way to change the lisp so it will only select elements from layers that are on/thawed, so that what we see selected on screen (on zoom extents) is really all it selected?

 

Again, thanks in advance.

 

Edgar

 

PS.: Should I create a new post?

0 Likes
Message 8 of 15

Anonymous
Not applicable

(setq ss (ssget "_X" (list (cons 0 *answerSTEA*) (cons 70 0)))) ;to get thawed layers

0 Likes
Message 9 of 15

ebsoares
Collaborator
Collaborator

Thanks, @Anonymous!

 

Do you know if adding (cons 62 0) at the end, as in:

(setq ss (ssget "_X" (list (cons 0 *answerSTEA*) (cons 70 0) (cons 62 0))))

will it also only select from layers that are on? So both thawed and on?

 

Edgar

0 Likes
Message 10 of 15

SeeMSixty7
Advisor
Advisor

Sorry, mracad, I don't believe that will work.

 

The 70 dxf code for layer state is purely for layers inside the layer table and not entities in the drawing.

 

 

0 Likes
Message 11 of 15

SeeMSixty7
Advisor
Advisor

Edgar,

 

It gets a bit more complicated when you want to check layer states. The layer states are not stored in the entities. They are stored in the Layer Table of the Drawing.

 

The process is you will need to create a list of layers that are ON and THAWED. You need to do that by going through all the layers in the drawing and checking those states. If both conditions are met then add them to your list of Layers that you wish to search.

 

After you get that done then build your conditional ssget filter set. (for example if you are looking for text on the layers "A", "B", and "D")

It would look something like this.

 

(setq myss (ssget "X" (list (cons 0 . "TEXT") (cons -4 "<OR") (cons 8 "A") (cons 8 "B") (cons 8 "D") (cons -4 "OR>"))))

 

If you want more help putting it all together let me know.

Message 12 of 15

ВeekeeCZ
Consultant
Consultant
Accepted solution

@Anonymous wrote:

(setq ss (ssget "_X" (list (cons 0 *answerSTEA*) (cons 70 0)))) ;to get thawed layers


(setq ss (ssget "_A" (list (cons 0 *answerSTEA*)))) ;to get thawed layers

 

For more options off (ssget) see HERE

 

;-- this is not possible for turned off layers.

0 Likes
Message 13 of 15

ebsoares
Collaborator
Collaborator

That's great, @ВeekeeCZ! Thank you so much.

 

@SeeMSixty7 just explained that it would be more complicated to create a lisp that would ignore both off AND frozen layers, but this simple change you showed is the next best thing Smiley Happy

 

Edgar

0 Likes
Message 14 of 15

ebsoares
Collaborator
Collaborator

Thanks for taking the time to explain what needed to be done, @SeeMSixty7.

 

I went with the option @ВeekeeCZ offered, as it was such a simple fix and it will get the job done beautifully. Besides, our files usually have hundreds of layers and perusing through them one by one might take some time.

 

Edgar

0 Likes
Message 15 of 15

SeeMSixty7
Advisor
Advisor

I'm glad you found a solution. It is a much simpler approach for catching entities on non frozen layers. My option takes care of the layers that are off as well.

 

Another method may be to simply use a crossing selection using the extmin and extmax variables and then adding the filter for the entity type.

 

Enjoy and thanks for the kudos!

 

0 Likes