Author Topic: Selecting block instances based on their custom properties  (Read 292 times)

0 Members and 1 Guest are viewing this topic.

Shay Gaghe

  • Newt
  • Posts: 81
Selecting block instances based on their custom properties
« on: June 01, 2022, 12:00:53 PM »
Hi

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?

Thanks

S

ribarm

  • Gator
  • Posts: 2701
  • Marko Ribar, architect
Re: Selecting block instances based on their custom properties
« Reply #1 on: June 01, 2022, 12:56:41 PM »
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: [Select]
  1. (defun c:selvisst (/ selvis ss)
  2.  
  3.  
  4.   (defun selvis (/ ent i props ss your_visibility)
  5.                                           ; <--- Returns the selection set with the desired visibility states
  6.  
  7.     (defun getvisstates (ss / unique LM:getvisibilitystatesnames i blk lst)
  8.  
  9.       (defun unique (l)
  10.         (if l (cons (car l) (unique (vl-remove-if '(lambda (x) (or (= (strcase x) (car l)) (= x (car l)))) l))))
  11.       )
  12.  
  13.       ;; Get Visibility States Names  -  Lee Mac
  14.       ;; Returns the names of the Visibility States of a Dynamic Block (if present)
  15.       ;; blk - [vla] VLA Dynamic Block Reference object
  16.       ;; Returns: [str] Names of Visibility States, else nil
  17.        
  18.       (defun LM:getvisibilitystatesnames (blk / vis)
  19.         (if
  20.           (and
  21.             (vlax-property-available-p blk 'effectivename)
  22.             (setq blk
  23.               (vla-item
  24.                 (vla-get-blocks (vla-get-document blk))
  25.                 (vla-get-effectivename blk)
  26.               )
  27.             )
  28.            ;(= :vlax-true (vla-get-isdynamicblock blk)) to account for NUS dynamic blocks
  29.             (= :vlax-true (vla-get-hasextensiondictionary blk))
  30.             (setq vis
  31.               (vl-some
  32.                '(lambda (pair)
  33.                   (if
  34.                     (and
  35.                       (= 360 (car pair))
  36.                       (= "BLOCKVISIBILITYPARAMETER" (cdr (assoc 0 (entget (cdr pair)))))
  37.                     )
  38.                     (cdr pair)
  39.                   )
  40.                 )
  41.                 (dictsearch
  42.                   (vlax-vla-object->ename (vla-getextensiondictionary blk))
  43.                   "ACAD_ENHANCEDBLOCK"
  44.                 )
  45.               )
  46.             )
  47.           )
  48.           ;(cdr (assoc 301 (entget vis)))
  49.           (mapcar 'cdr (vl-remove-if '(lambda (x) (/= (car x) 303)) (entget vis)))
  50.         )
  51.       )
  52.  
  53.       (if ss
  54.         (repeat (setq i (sslength ss))
  55.           (setq blk (ssname ss (setq i (1- i))))
  56.           (if (= (vla-get-isdynamicblock (vlax-ename->vla-object blk)) :vlax-true)
  57.             (setq lst (append lst (LM:getvisibilitystatesnames (vlax-ename->vla-object blk))))
  58.           )
  59.         )
  60.       )
  61.       (unique (reverse lst))
  62.     )
  63.  
  64.     (defun AT:ListSelect (title label height width multi lst / fn fo d item f)
  65.       ;; List Select Dialog (Temp DCL list box selection, based on provided list)
  66.       ;; title - list box title
  67.       ;; label - label for list box
  68.       ;; height - height of box
  69.       ;; width - width of box
  70.       ;; multi - selection method ["true": multiple, "false": single]
  71.       ;; lst - list of strings to place in list box
  72.       ;; Alan J. Thompson, 09.23.08 / 05.17.10 (rewrite)
  73.       (setq fo (open (setq fn (vl-filename-mktemp "" "" ".dcl")) "w"))
  74.       (foreach x (list (strcat "list_select : dialog { label = \"" title "\"; spacer;")
  75.                        (strcat ": list_box { label = \"" label "\";" "key = \"lst\";")
  76.                        (strcat "allow_accept = true; height = " (vl-princ-to-string height) ";")
  77.                        (strcat "width = " (vl-princ-to-string width) ";")
  78.                        (strcat "multiple_select = " multi "; } spacer; ok_cancel; }")
  79.                  )
  80.         (write-line x fo)
  81.       )
  82.       (close fo)
  83.       (new_dialog "list_select" (setq d (load_dialog fn)))
  84.       (start_list "lst")
  85.       (mapcar (function add_list) lst)
  86.       (end_list)
  87.       ;;;(setq item (set_tile "lst" "0"))
  88.       (action_tile "lst" "(setq item $value)")
  89.       (setq f (start_dialog))
  90.       (unload_dialog d)
  91.       (vl-file-delete fn)
  92.       (if (= f 1)
  93.         (mapcar '(lambda (n) (nth n lst)) (read (strcat "(" item ")")))
  94.       )
  95.     )
  96.  
  97.     (setq ss              (ssget '((0 . "INSERT")))
  98.           your_visibility
  99.                           (mapcar
  100.                             'strcase
  101.                             (AT:ListSelect "CHOOSE VISIBILITY STATES YOU WANT TO HIGHLIGHT" "VISIBILITY STATES" 40 30 "true" (getvisstates ss))
  102.                           )
  103.     )
  104.     (repeat (setq i (sslength ss))
  105.       (if
  106.         (or
  107.           (eq (vla-get-IsDynamicBlock
  108.                 (vlax-ename->vla-object
  109.                   (setq ent (ssname ss (setq i (1- i))))
  110.                 )
  111.               )
  112.               :vlax-false
  113.           )
  114.           (and
  115.             (setq props
  116.                    (vl-remove-if-not
  117.                      '(lambda (x)
  118.                         (wcmatch (strcase (vla-get-PropertyName x))
  119.                                  "VISIBILITY*"
  120.                         )
  121.                       )
  122.                      (vlax-invoke
  123.                        (vlax-ename->vla-object ent)
  124.                        'GetDynamicBlockProperties
  125.                      )
  126.                    )
  127.             )
  128.             (vl-some
  129.               '(lambda (x)
  130.                  (if (null (vl-position
  131.                              (strcase (vlax-get x 'Value))
  132.                              your_visibility
  133.                            )
  134.                      )
  135.                    (ssdel ent ss)
  136.                  )
  137.                )
  138.               props
  139.             )
  140.           )
  141.         )
  142.          (ssdel ent ss)
  143.       )
  144.     )
  145.     ss
  146.   )
  147.  
  148.               (setq ss (vl-catch-all-apply 'selvis))
  149.             )
  150.       )
  151.     (sssetfirst nil ss)
  152.   )
  153.   (princ)
  154. )
  155.  

HTH., M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Shay Gaghe

  • Newt
  • Posts: 81
Re: Selecting block instances based on their custom properties
« Reply #2 on: June 02, 2022, 01:41:26 AM »
Hi
thanks a lot for sharing
so there is no buit-in function  of doing that? LT usesr cannot do it?