Jump to content

Custom block selection lisp


sakinen

Recommended Posts

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.

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 **")))))

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 5 years later...

What is wrong here get back a nil

 

Was ist hier falsch bekomme ein nil zurück

 

ATT.png

 

 

 

 

(defun c:test ()

(alert

(vl-princ-to-string

(Filter_set "Seco-opt-zwd" "MELDERNUMMER" '(1 2 3))))

(princ))

Edited by dober
Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...