Author Topic: Filter dynamic block by visibility  (Read 12581 times)

0 Members and 1 Guest are viewing this topic.

Yoland

  • Guest
Filter dynamic block by visibility
« on: January 30, 2008, 06:31:50 AM »
Hi,

I don't know how filter the dynamic blocks by your visibility.
Can your help me, please???

Thanks, and sorry for my poor english,

Bye
Yolanda

FengK

  • Guest
Re: Filter dynamic block by visibility
« Reply #1 on: January 30, 2008, 11:47:04 AM »
I don't think you can do that directly using dxf, if that's what you're looking for. Dynamic blocks support GetDynamicBlockProperties method and that's where you can start. Check out this thread: http://discussion.autodesk.com/thread.jspa?messageID=4864785

Yoland

  • Guest
Re: Filter dynamic block by visibility
« Reply #2 on: January 30, 2008, 11:53:31 AM »
Thanks Kellie,

I can select per example all doors that have p72 visibility and left p80 visibility. I don't know if I explain correctly

Thanks again
Yolanda

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Filter dynamic block by visibility
« Reply #3 on: January 30, 2008, 12:35:32 PM »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Yoland

  • Guest
Re: Filter dynamic block by visibility
« Reply #4 on: January 31, 2008, 06:28:11 AM »
Hi again,

I don't understand Autolisp. I think a thing easier to do. When you select objects, said that objects need. I think don't explain correctly. :(
When used QSELECT there isn't possibility to select the visibility characteristic, is true???

Thanks a lot to be patient.

Yolanda

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Filter dynamic block by visibility
« Reply #5 on: January 31, 2008, 12:27:29 PM »
OK...so I got this to work using Steve's GetDBProps sub-routine. The dynamic properties populate into a dialogue for selection. Once a property is selected, then the block selection is needed. The end result is *crosses fingers* a highlighted selection set of the blocks with the matching dynamic property.

Enjoy :)



Code: [Select]
(defun c:fdp (/ $value choice ent fn fno id proplst sel ss ss2
      strproplst x)
  (if (and (setq ent (car (entsel "\n Select dynamic block: ")))
   (isdynamic ent)
      )
    (progn
      (setq strproplst (mapcar '(lambda (x)
  (vl-prin1-to-string x)
)
       (GetDBProps ent)
       )
    proplst    (GetDBProps ent)
    fn        (vl-filename-mktemp nil nil ".dcl")
    fno        (open fn "w")
      )
      (write-line
(strcat
  "DynamicProperties : dialog {
  label = \"Dynamic Properties - By RJP\";
:boxed_column {
     label = \"Select Dynamic Property to Filter:\";
   : list_box {
      key = \"proplist\";
      height = 16;
      width = 8;
        multiple_select = false;
       }
    }
  : row {
     : button {
       label = \"&Select...\";
       key = \"select\";
       }
    : button {
       label = \"&Cancel\";
      is_cancel = true;
      key = \"cancel\";
       }
  }
}"
)
fno
      )
      (close fno)
      (setq id (load_dialog fn))
      (if (not (new_dialog "DynamicProperties" id))
(exit)
      )
      (start_list "proplist")
      (mapcar 'add_list strproplst)
      (end_list)
      (action_tile "proplist" "(setq choice $value)")
      (action_tile "select" "(done_dialog)")
      (action_tile
"cancel"
"(setq choice nil)(done_dialog)(vl-file-delete fn)"
      )
      (start_dialog)
      (unload_dialog id)
      (vl-file-delete fn)
      (if choice
(progn
  (setq sel (nth (read choice) proplst)
ss2 (ssadd)
  )
  (if
    (and (setq ss (ssget '((0 . "INSERT"))))
(setq ss (vl-remove-if
'(lambda (x)
   (not (isdynamic x))
)
(vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
      )
)
    )
     (mapcar '(lambda (x)
(if (member sel (getdbprops x))
  (ssadd x ss2)
)
      )
     ss
     )
  )
)
(princ "\nYou must select a property...")
      )
    )
    (princ "\nSelection missed or not dynamic block...")
  )
  (sssetfirst nil ss2)
  (princ)
)

(defun GetDBProps (objent)
;;;
;;; Returns: a list containing all custom properties of a given dynamic block
;;; By Steve Doman - revised 12/14/05
;;; Based on code from Herman Mayfarth and Tony Tanzillo
;;;
;;; Syntax : (GetDBProps ename|object)
;;;          where objent is an ename or vla-object of dynamic block
;;;
;;; Example: (GetDBProps (car (entsel "\nSelect dynamic block: ")))
;;;
  (if (= 'ENAME (type objent))
    (setq objent (vlax-ename->vla-object objent))
  )
  (vl-remove-if
    '(lambda (y) (= (car y) "Origin"))
    (mapcar '(lambda (x)
       (cons (vlax-get-property x "PropertyName")
     (vlax-variant-value (vlax-get-property x "Value"))
       )
     )
    (vlax-safearray->list
      (vlax-variant-value (vla-getdynamicblockproperties objent))
    )
    )
  )
)
(defun isdynamic (objent /)
  (if (= 'ENAME (type objent))
    (setq objent (vlax-ename->vla-object objent))
  )
  (if (= (vla-get-ObjectName objent) "AcDbBlockReference")
    (= (vla-get-IsDynamicBlock objent) :vlax-true)
  )
)
« Last Edit: February 05, 2008, 10:40:10 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Yoland

  • Guest
Re: Filter dynamic block by visibility
« Reply #6 on: February 01, 2008, 03:25:53 AM »
Hi ronjonp,

Thanks, thanks, thanks!!!

I crossing fingers and the routine runs correctly.

Bye and another time THANKS!!!!

YOLANDA

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Filter dynamic block by visibility
« Reply #7 on: February 01, 2008, 07:48:21 AM »
Let me know how it goes :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Yoland

  • Guest
Re: Filter dynamic block by visibility
« Reply #8 on: February 05, 2008, 05:27:08 AM »
Hi,

Your routine works fine.
You select a dynamic block, in a dialog box show the characteristics of them, you select a characteristic in the dialog box, and automatic it select all blocks that have this characteristic.

I’m Spanish, and this question I done in other forum (Spanish language) the answer that they done was:


Code: [Select]
;|******************************************************
            Rutina "filtrado_bloques_din_vis" verifica
            si hay bloques dinamicos con una cierta
            visibilidad dentro de una selección
            de bloques........
            *<ES CASE SENSITIVE-MAYÚSCULAS/minúsculas>*
            *by PREXEM-VICTOR ADOLFO BRACAMONTE-2008*
  ******************************************************|;
(defun c:filtrado_bloques_din_vis ( /
                    sel
                    filtrado
                    visibilidad
                    contador
                   )
  (vl-load-com)
;|          Hago una selección de bloques;
            y luego debo introducir el
            nombre de la visibilidad del
            bloque dinámico del que
            deseo obtener su cantidad, y
            me devuelve un numero de bloques
            dinámicos con esa visibilidad, pero
            primero verifica si es bloque
            dinámico:        |;
  (setq sel (ssget '((0 . "INSERT"))))
  (setq   visibilidad
    (getstring
      t
  "\ndar nombre de visibilidad a filtrar: "
      )
   contador  0
  )
  (repeat
    (sslength sel)
      (if
      (and
   (=
     (vlax-get-property
        (vlax-ename->vla-object
       (ssname sel contador)
       )
        'isdynamicblock
        )
      :vlax-true
      )
        (equal visibilidad
      (lee_prop_bdin (ssname sel contador))
              );equal
   );and
      (setq filtrado
        (cons
          (ssname sel contador)
          filtrado
          )
       )
    );if
    (setq contador (+ 1 contador))
  );repeat
  (princ "\n**************************************************")
  (princ "\nCantidad de bloques dinamicos con esa visibilidad: ")
  (princ (length filtrado))
  (princ "\n**************************************************")
    (if (= (length filtrado) 0)
    (prompt
 "\n*NO HAY BLOQUES DINÁMICOS CON ESA VISIBILIDAD EN LA SELECCIÓN HECHA*"
      )
    );if
  (princ)
);fin defun c:filtrado_bloques_din_vis
;;;*************************************************************
;;;    función "lee_prop_bdin" lee valor de la visibilidad de
;;;    un bloque dinámico.........autor anónimo........
(defun lee_prop_bdin (
         ent /
         prop
         vlaobj
         variables
         valores
         lista
         total_valores
         contador
         valor
         )
  (setq prop "Visibilidad")
  (setq   vlaobj (vlax-ename->vla-object ent))
  (if (= (vlax-get-property vlaobj 'isdynamicblock) :vlax-true)
   (progn
     (setq   variables (vla-getdynamicblockproperties vlaobj)
      valores (vlax-variant-value variables)
      lista (vlax-safearray->list valores)
      total_valores (length lista)
      contador 0
     )
     (while
       (< contador total_valores)
       (if
         (= (vlax-get-property
         (nth contador lista)
         "PropertyName"
         )
       prop
       )
     (progn
     (setq valor
       (vlax-get-property
         (nth contador lista)
         "Value"
         )
      )
     (setq contador total_valores))
     (setq contador (1+ contador))
      );if
     );while
   );progn
  );if
  (if valor (vlax-variant-value valor))
);lee_prop_bdin
;;;**********************************************************
Another time, thanks

Yolanda

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Filter dynamic block by visibility
« Reply #9 on: February 05, 2008, 10:37:15 AM »
Glad it worked for you. I updated the code above to remove some redundant lines.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ingnelson

  • Mosquito
  • Posts: 1
Re: Filter dynamic block by visibility
« Reply #10 on: May 11, 2023, 11:08:14 AM »
Could you modify the code to use 2 dynamic properties instead 1 , please? i need to filter a block using 2 properties.