filter multiple entity

filter multiple entity

marlance
Advocate Advocate
850 Views
2 Replies
Message 1 of 3

filter multiple entity

marlance
Advocate
Advocate

Hi guys

 

is this code possible?

 

(setq ss (ssget))
(cond
((= ss "Text")(command "_.chprop" ss "" "_layer" "Text" ""))
((= ss "Mtext")(command "_.chprop" ss "" "_layer" "Mtext" ""))
((= ss "Circle")(command "_.chprop" ss "" "_layer" "Circle" ""))
((= ss "Line")(command "_.chprop" ss "" "_layer" "Line" ""))
)
0 Likes
851 Views
2 Replies
Replies (2)
Message 2 of 3

john.uhden
Mentor
Mentor

Please realize that (ssget) returns a selection set, a group of entities that matches whatever filter you may apply to the ssget function.

You must then cycle through each member of the selection set to see if it matches any other entity criteria you may have in mind.

 

For instance, say you want to select all the entities that are on layer "A" and then act separately on whether they are text items, or lines, or circles...

 

(if (setq ss (ssget '((8 . "A")))

  (progn

    (setq i 0)

    (repeat (sslength ss)

      (setq e (ssname ss i)

              etype (cdr (assoc 0 (entget e)))

              i (1+ i)

      )

      (cond

        ((= etype "LINE")(do this))

        ((= etype "CIRCLE")(do that))

        (1 (do something_else))

      )

    )

  )

)

 

There are variations on this method, but it's a great way to start learning about selection sets.  Selection set filtering can be really powerful and cut down code to focus on just what you want.  Please read more about it the help.

John F. Uhden

0 Likes
Message 3 of 3

dbroad
Mentor
Mentor

@john.uhden  Hey, welcome back.  Good to see your posts again.

 

@marlance.  As John said, selection sets are groups of objects and have no object properties themselves.  Something like this might work.  You should be able to complete it.

(if (ssget '((0 . "text,mtext,circle,line")))
    (vlax-for n (vla-get-activeselectionset
		  (vla-get-activedocument
		    (vlax-get-acad-obect)))
      (setq ot (vla-get-objectname n))
      (cond
	((= ot "AcDbText")
	 (vla-put-layer n "Text")
	 )
	((= ot "AcDbCircle")
	 (vla-put-layer n "Circle"))
;;;	... you should be able to figure out the rest
;;; please note that the layers need to already exist.
      );end cond
    );end vlax-for
);end if


As far as the goals you are proposing however, I would strongly discourage sorting objects onto layers by object type. They should be sorted by what functional purpose they serve.  There is no reason to layer at all unless you wish to manage visibility, color, lineweight, or linetype to accomplish a purpose.

Architect, Registered NC, VA, SC, & GA.
0 Likes