sakinen Posted June 25, 2009 Share Posted June 25, 2009 I need to make selection by attribute value. Filter for selection is made by block name, block attribute and set of values of that attribute. For example i have a dozen of blocks in my drawing but i need only radiator block. This bloc has a several attributes but i need to filter by its room number attribute. Values are 1,2,3,4,5,6,7,8. I want to select only 2,4,7. Is there a lisp routine that i can modify or you have some other ideas. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 25, 2009 Share Posted June 25, 2009 You will have to use an SS filter to filter for the block name and attributed block, then one way to filter the collected set is to convert it to a list, and use such functions as "vl-remove-if" "vl-remove-if-not"... etc Quote Link to comment Share on other sites More sharing options...
flowerrobot Posted June 25, 2009 Share Posted June 25, 2009 Hi there.. What do you want to do with the items with the values 2,4,7 ? I would use this for the selection set This would get the attribute an item. (setq blockname (getstring ("\nWhat is the blocks name"))) (setq ss(ssget "X" '((0 . "INSERT")(2 . blockname)(66 . 1)))) Then for the numbers of the attributes (defun attget (ss1 count/ en edata) (if ss1 (progn (setq en (ssname ss1 count)) (setq edata (entget en)) (setq blockdata nil) (setq edata (entget (entnext (cdr (assoc -1 edata))))) (while (not(= (cdr (assoc 0 edata)) "SEQEND")) (setq blockdata (cons (cons (cdr (assoc 2 edata)) (cdr (assoc 1 edata))) blockdata)) (setq edata (entget (entnext (cdr (assoc -1 edata))))) ) ) (progn (alert "Their is no blocks") (exit) ) ) ) Then you could follow that with say Which would make a list. (if (or (= blockdata "2")(= blockdata "4")(= blockdata "7")) (setq list (cons (ssname count ss))) ) (setq count (1+ count)) Please excuse the cut and paste thing. this should get you on your way.. Unless you dont use lisp at. then well sorry, one of the others will help Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 25, 2009 Share Posted June 25, 2009 Another method: (defun Filter_set (blk tag lst / ss olst) (vl-load-com) (if (setq ss (ssget "_X" (list (cons 0 "INSERT") (cons 2 blk) (cons 66 1)))) (progn (foreach Blk (mapcar 'vlax-ename->vla-object (mapcar 'cadr (ssnamex ss))) (foreach Att (vlax-safearray->list (vlax-variant-value (vla-getAttributes Blk))) (if (and (eq tag (vla-get-TagString Att)) (vl-position (vla-get-TextString Att) lst)) (setq olst (cons (vlax-vla-object->ename Blk) olst))))))) (reverse olst)) (defun c:test () (alert (vl-princ-to-string (Filter_set "test Block" "RoomNumber" '(1 2 3)))) (princ)) Call it with Block Name, Tag Name, and list of Attribute Values to filter for. Quote Link to comment Share on other sites More sharing options...
sakinen Posted June 25, 2009 Author Share Posted June 25, 2009 Hi there..What do you want to do with the items with the values 2,4,7 ? I wan to select these specific blocks to change their lookup parameter value in properties tab. Quote Link to comment Share on other sites More sharing options...
sakinen Posted June 25, 2009 Author Share Posted June 25, 2009 Thanks a lot. This helps. Is there a way to make the lisp ask you to select the block you wont and then insert the attribute name? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 25, 2009 Share Posted June 25, 2009 Thanks a lot. This helps. Is there a way to make the lisp ask you to select the block you wont and then insert the attribute name? You would need to use the getstring function to prompt for a block/attribute name, and include some error checking to see if the names are valid etc. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted June 26, 2009 Share Posted June 26, 2009 I have a vba that does probably what you want but regarding last question its easiest to pick a correct block and just return its name you can do a confirm so pick again if wrong one. Then continue with program. You could also step through the attributes and pick the correct ones say enter = no Y = correct Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 26, 2009 Share Posted June 26, 2009 Block Selection Could be something like this: (while (progn (setq ent (car (entsel "\nSelect Block: "))) (cond ((eq 'ENAME (type ent)) (cond ((not (eq "INSERT" (cdadr (setq elst (entget ent))))) (princ "\n** Object is not a Block **")) ((not (eq 1 (cdr (assoc 66 elst)))) (princ "\n** Block is not Attributed **")) (t nil))) ; Exit Loop (t (princ "\n** Nothing Selected **"))))) Quote Link to comment Share on other sites More sharing options...
Commandobill Posted June 26, 2009 Share Posted June 26, 2009 Block Selection Could be something like this: (while (progn (setq ent (car (entsel "\nSelect Block: "))) [u][b] (cond ((eq 'ENAME (type ent))[/b][/u] (cond ((not (eq "INSERT" (cdadr (setq elst (entget ent))))) (princ "\n** Object is not a Block **")) ((not (eq 1 (cdr (assoc 66 elst)))) (princ "\n** Block is not Attributed **")) (t nil))) ; Exit Loop (t (princ "\n** Nothing Selected **"))))) what exactly is the purpose of this line? If (setq ent (car (entsel))) returns nil thats that... the second check then is pointless yes? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 26, 2009 Share Posted June 26, 2009 entsel can honour keywords, and I initially had provisions to include a "\nSelect Block [Name]: " in there so that the user could also specify a block name. But I changed my mind. Sorry for the confusion. Quote Link to comment Share on other sites More sharing options...
Commandobill Posted June 26, 2009 Share Posted June 26, 2009 Ok thought there was something i was missing Quote Link to comment Share on other sites More sharing options...
sakinen Posted June 26, 2009 Author Share Posted June 26, 2009 This is great stuff. Thank you all! Quote Link to comment Share on other sites More sharing options...
dober Posted March 10, 2015 Share Posted March 10, 2015 (edited) What is wrong here get back a nil Was ist hier falsch bekomme ein nil zurück (defun c:test () (alert (vl-princ-to-string (Filter_set "Seco-opt-zwd" "MELDERNUMMER" '(1 2 3)))) (princ)) Edited March 11, 2015 by dober Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.