PDA

View Full Version : Create Selection Set base on attribute value



Borg
2004-10-21, 01:27 PM
I suspect I'm going to be told this can't be done but here goes.
I would like to use ssget to select blocks that have a particular value
in a particular attribute. The blocks won't necessarily have the same
name but it would be the same attribute in each one.

I know that I could iterate through a selection set of all blocks to accomplish
this, but If I could do it with ssget that would be great.

kennet.sjoberg
2004-10-21, 01:55 PM
If You are using ssget I believe You must select all blocks and iterate each for the attribute
and add to a new selection set when attribute is true.
But there may be a (vl---thing that You can search fore.

: ) Happy Computing !

kennet

peter
2004-10-21, 02:26 PM
Try this

Peter Jamtgaard



(defun C:SSByAttributes (/ intCount entSelection lstAttributePairs
lstEntity objSelection ssSelections ssSelections2)
(setq ssSelections (ssget (list (cons 0 "INSERT"))))
(setq strTagString (getstring "\nEnter Tag string: ")
strTextString (getstring "\nEnter Text string: ")
)
(repeat (setq intCount (sslength ssSelections))

(setq intCount (1- intCount)
entSelection (ssname ssSelections intCOunt)
objSelection (vlax-ename->vla-object entSelection)
)
(if (= (vla-get-hasattributes objSelection) :vlax-true)
(progn
(setq lstAttributePairs (mapcar '(lambda (X)(cons (strcase (vla-get-tagstring X))
(strcase (vla-get-textstring X))
)
)
(vlax-safearray->list
(variant-value
(vla-getattributes
objSelection
)
)
)
)
)
(if (and (setq dprTagPair (assoc (strcase strTagString) lstAttributePairs))
(= (cdr dprTagPair)
(strcase strTextString)
)
)
(progn
(if ssSelections2
(setq ssSelections2 (ssadd entSelection ssSelections2))
(setq ssSelections2 (ssadd entSelection))
)
)
)
)
)
)
(if ssSelections2
(progn
(vl-cmdf "select" ssSelections2 "")
ssSelections2
)
nil
)
)

Borg
2004-10-21, 02:48 PM
Thanks Peter! That is outstanding! I was just expecting directional advise but you came through with flying colors as always.

Again, a million thanks.