CAD Forums > Dynamic Blocks

Selecting block instances based on their custom properties


Shay Gaghe:

I have authored a dynamic block with” block properties table” controller and dimension and geometric constraint and visibility states,

Im looking for a search flexibility where for example I can select all instances in the drawing or a selection set  that use visibility A and are 160x80, and other instances that use visibility B and are 110x50,needless to say, they are all instance of the same block.

Is there any organic way of doing this?



Pulled from my library...

Provide in main (ssget '((0 . "INSERT"))) additional filtering like : (ssget '((0 . "INSERT") (2 . "BlockName") (66 . 1))), but for dimensions like 160x80 or 110x50, you'll have to reiterate obtained selection set and filter out undesired from those 2 dimensions - consider using (vla-getboundingbox) method for acquireing dimesions of block...

--- Code - Auto/Visual Lisp: ---(defun c:selvisst (/ selvis ss)   (or (not (vl-catch-all-error-p (vl-catch-all-apply (function vlax-get-acad-object) nil))) (vl-load-com))   (defun selvis (/ ent i props ss your_visibility)                                          ; <--- Returns the selection set with the desired visibility states     (defun getvisstates (ss / unique LM:getvisibilitystatesnames i blk lst)       (defun unique (l)        (if l (cons (car l) (unique (vl-remove-if '(lambda (x) (or (= (strcase x) (car l)) (= x (car l)))) l))))      )       ;; Get Visibility States Names  -  Lee Mac      ;; Returns the names of the Visibility States of a Dynamic Block (if present)      ;; blk - [vla] VLA Dynamic Block Reference object      ;; Returns: [str] Names of Visibility States, else nil             (defun LM:getvisibilitystatesnames (blk / vis)        (if          (and            (vlax-property-available-p blk 'effectivename)            (setq blk              (vla-item                (vla-get-blocks (vla-get-document blk))                (vla-get-effectivename blk)              )            )           ;(= :vlax-true (vla-get-isdynamicblock blk)) to account for NUS dynamic blocks            (= :vlax-true (vla-get-hasextensiondictionary blk))            (setq vis              (vl-some               '(lambda (pair)                  (if                    (and                      (= 360 (car pair))                      (= "BLOCKVISIBILITYPARAMETER" (cdr (assoc 0 (entget (cdr pair)))))                    )                    (cdr pair)                  )                )                (dictsearch                  (vlax-vla-object->ename (vla-getextensiondictionary blk))                  "ACAD_ENHANCEDBLOCK"                )              )            )          )          ;(cdr (assoc 301 (entget vis)))          (mapcar 'cdr (vl-remove-if '(lambda (x) (/= (car x) 303)) (entget vis)))        )      )       (if ss        (repeat (setq i (sslength ss))          (setq blk (ssname ss (setq i (1- i))))          (if (= (vla-get-isdynamicblock (vlax-ename->vla-object blk)) :vlax-true)            (setq lst (append lst (LM:getvisibilitystatesnames (vlax-ename->vla-object blk))))          )        )      )      (unique (reverse lst))    )     (defun AT:ListSelect (title label height width multi lst / fn fo d item f)      ;; List Select Dialog (Temp DCL list box selection, based on provided list)      ;; title - list box title      ;; label - label for list box      ;; height - height of box      ;; width - width of box      ;; multi - selection method ["true": multiple, "false": single]      ;; lst - list of strings to place in list box      ;; Alan J. Thompson, 09.23.08 / 05.17.10 (rewrite)      (setq fo (open (setq fn (vl-filename-mktemp "" "" ".dcl")) "w"))      (foreach x (list (strcat "list_select : dialog { label = \"" title "\"; spacer;")                       (strcat ": list_box { label = \"" label "\";" "key = \"lst\";")                       (strcat "allow_accept = true; height = " (vl-princ-to-string height) ";")                       (strcat "width = " (vl-princ-to-string width) ";")                       (strcat "multiple_select = " multi "; } spacer; ok_cancel; }")                 )        (write-line x fo)      )      (close fo)      (new_dialog "list_select" (setq d (load_dialog fn)))      (start_list "lst")      (mapcar (function add_list) lst)      (end_list)      ;;;(setq item (set_tile "lst" "0"))      (action_tile "lst" "(setq item $value)")      (setq f (start_dialog))      (unload_dialog d)      (vl-file-delete fn)      (if (= f 1)        (mapcar '(lambda (n) (nth n lst)) (read (strcat "(" item ")")))      )    )     (setq ss              (ssget '((0 . "INSERT")))          your_visibility                          (mapcar                            'strcase                            (AT:ListSelect "CHOOSE VISIBILITY STATES YOU WANT TO HIGHLIGHT" "VISIBILITY STATES" 40 30 "true" (getvisstates ss))                          )    )    (repeat (setq i (sslength ss))      (if        (or          (eq (vla-get-IsDynamicBlock                (vlax-ename->vla-object                  (setq ent (ssname ss (setq i (1- i))))                )              )              :vlax-false          )          (and            (setq props                   (vl-remove-if-not                     '(lambda (x)                        (wcmatch (strcase (vla-get-PropertyName x))                                 "VISIBILITY*"                        )                      )                     (vlax-invoke                       (vlax-ename->vla-object ent)                       'GetDynamicBlockProperties                     )                   )            )            (vl-some              '(lambda (x)                 (if (null (vl-position                             (strcase (vlax-get x 'Value))                             your_visibility                           )                     )                   (ssdel ent ss)                 )               )              props            )          )        )         (ssdel ent ss)      )    )    ss  )   (if (null (vl-catch-all-error-p              (setq ss (vl-catch-all-apply 'selvis))            )      )    (sssetfirst nil ss)  )  (princ)) 
HTH., M.R.

Shay Gaghe:
thanks a lot for sharing
so there is no buit-in function  of doing that? LT usesr cannot do it?


[0] Message Index

Go to full version