Author Topic: Strip block of Dynamic Properties  (Read 19308 times)

0 Members and 1 Guest are viewing this topic.

mexxx_

  • Guest
Re: Strip block of Dynamic Properties
« Reply #15 on: March 19, 2013, 06:04:39 AM »
Hello,

I have now found that all lines in the block included. Characterized the block unnecessarily large and blows to the drawing.

mexxx_

  • Guest
Re: Strip block of Dynamic Properties
« Reply #16 on: March 27, 2013, 04:40:23 AM »
Hello,

I delete the invisible Objects with this Code. Can you integrate this Code in your Code please?

Code: [Select]
(defun c:delinvb (/ acdoc ss i sset nme Blockdefinition)
  (vl-load-com)
  (setq acdoc (vla-get-activedocument
                (vlax-get-acad-object)
              )
  )
  (if (setq ss (ssget "_:L" '((0 . "INSERT"))))
    (repeat
      (setq i (sslength ss))
      (setq sset (ssname ss (setq i (1- i))))
      (setq nme (cdr (assoc 2 (entget sset))))
      (setq Blockdefinition (vla-item (vla-get-blocks acdoc) nme))
      (if
        (and
          (eq :vlax-false (vla-get-isxref Blockdefinition))
          (eq :vlax-false (vla-get-islayout Blockdefinition))
        )
          (vlax-for x Blockdefinition
       (if(=(vla-get-Visible  x) :vlax-false)
        (vla-delete x)
    )
)
      )
    )
    (princ)
  )
  (vla-regen acdoc acAllViewports)
  (princ)
)

Thanks  :-)

cadpoobah

  • Newt
  • Posts: 39
Re: Strip block of Dynamic Properties
« Reply #17 on: December 11, 2013, 02:44:10 PM »
Friday quick & dirty freebie ... not the most efficient but free ...

That's a Fenomonal Friday Freebie, MP! :-)

I made a couple mods.

Mod 1 - I wanted to preserve the original block name and just add the numeric suffix to it, rather than renaming them to the generic "STATIC_#".
In the "_dynamic->static_block" function, I changed:
Code: [Select]
(_make_key blocks "STATIC_" len)was changed to
Code: [Select]
(_make_key blocks (strcat (vla-get-EffectiveName insert) "_") len)
Mod 2 - The function was bombing if the block it found was nested within an Xref.
Code: [Select]
(foreach insert inserts
  (_dynamic->static_block blocks insert len)
)
was changed to
Code: [Select]
(foreach insert inserts
  (if (null (wcmatch (vla-get-name insert) "*|*"))
    (_dynamic->static_block blocks insert len)
    )
)

Works great otherwise! Thanks!
« Last Edit: May 24, 2017, 03:04:28 PM by cadpoobah »
Chris Lindner
----------------------------------------------------
www.shremshock.com
www.unpavedart.com
www.facebook.com/scout80800s

bluepencil

  • Guest
Re: Strip block of Dynamic Properties
« Reply #18 on: November 10, 2015, 05:45:17 AM »
Hi!I was also looking for a way protect my "investment" in creating dynamic blocks... and I want to also find a way to strip the dynamic properties of the blocks when i pass the drawings to client and other people.  Then i stumbled upon this post...

I tried to make the code into an AUTOLISP and loaded it to my AutoCAD and it gave me this error:

Command: UNDYNAMIC
; error: no function definition: VLAX-GET-ACAD-OBJECT


I am using AutoCAD 2016 (Beta for Mac)... and i am not code-savvy... please can you help me what does it mean?  Or this error happened because I am using AutoCAD for Mac?

Thanks a lot!

Lee Mac

  • Seagull
  • Posts: 12263
  • London, England
Re: Strip block of Dynamic Properties
« Reply #19 on: November 10, 2015, 06:14:34 AM »
The error occurs because you have not issued the (vl-load-com) expression to define the set of ActiveX(COM) functions before attempting to evaluate such functions; however, since you are using AutoCAD for Mac, the ActiveX extensions will be unavailable in any case.

bluepencil

  • Guest
Re: Strip block of Dynamic Properties
« Reply #20 on: November 10, 2015, 06:23:02 AM »
Hi Lee Mac,

Are there any workaround for this in the MAC platform?

Thanks!

Lee Mac

  • Seagull
  • Posts: 12263
  • London, England
Re: Strip block of Dynamic Properties
« Reply #21 on: November 10, 2015, 06:53:24 AM »
Are there any workaround for this in the MAC platform?

No, ActiveX(COM) is a proprietary MS technology and so not available on a Mac platform; there are the new setpropertyvalue / getpropertyvalue / dumpallproperties functions, which are an attempt by Autodesk to bridge this shortfall, but these will not help in this particular case.

bluepencil

  • Guest
Re: Strip block of Dynamic Properties
« Reply #22 on: November 10, 2015, 07:20:55 AM »
Thanks again!

I guess this means exploding or ref-edit-in-place of dynamic blocks will be part of my workflow... haha.

Thanks!

Lee Mac

  • Seagull
  • Posts: 12263
  • London, England
Re: Strip block of Dynamic Properties
« Reply #23 on: November 10, 2015, 08:41:18 AM »
Or switch to Windows  :wink:

Richardb1208

  • Guest
Re: Strip block of Dynamic Properties
« Reply #24 on: February 24, 2016, 06:00:26 AM »
Hi All

These lisps are brilliant!! Has anyone created / found a lisp that will take the UNDYNAMIC in a slightly different direction?

I have 400 drawings that contain Dynamic blocks that use the visibility method. I need to lobotomize the blocks at a global level but ensure that the end product is the block renamed to include the visibility state convention. i.e. BlockName_VisibilityState.

Can anyone help?

ronjonp

  • Needs a day job
  • Posts: 7027
Re: Strip block of Dynamic Properties
« Reply #25 on: February 24, 2016, 10:12:51 AM »
Hi All

These lisps are brilliant!! Has anyone created / found a lisp that will take the UNDYNAMIC in a slightly different direction?

I have 400 drawings that contain Dynamic blocks that use the visibility method. I need to lobotomize the blocks at a global level but ensure that the end product is the block renamed to include the visibility state convention. i.e. BlockName_VisibilityState.

Can anyone help?
Here you go .. welcome to TheSwamp :)  . be aware that the code does not checked for locked layers.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:staticblocks (/ name)
  2.     (vlax-for b2 b
  3.       (if (and (vlax-property-available-p b2 'isdynamicblock)
  4.           (minusp (vlax-get b2 'isdynamicblock))
  5.           (setq name (vl-some '(lambda (prop)
  6.                   (if (= "Visibility" (vla-get-propertyname prop))
  7.                (vlax-get prop 'value)
  8.                   )
  9.                 )
  10.                (vlax-invoke b2 'getdynamicblockproperties)
  11.            )
  12.           )
  13.      )
  14.    (if (tblobjname "block" (setq name (strcat (vla-get-effectivename b2) "_" name)))
  15.      (vla-put-name b2 name)
  16.      (vla-converttostaticblock b2 name)
  17.    )
  18.       )
  19.     )
  20.   )
  21.   (princ)
  22. )
  23.  

*Also if your dynamic blocks have other properties that can change under the visibility state, the renamed block will take on the properties of the first found.
« Last Edit: February 24, 2016, 02:18:31 PM by ronjonp »

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12263
  • London, England
Re: Strip block of Dynamic Properties
« Reply #26 on: February 24, 2016, 01:23:36 PM »
Nice one Ron - though, unfortunately I don't believe that you can rely on the Property Name of the Visibility State parameter being named "Visibility", since any dynamic block parameter may be arbitrarily named.

Therefore, as an extension of your code, I would propose:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:staticblocks ( / bln lst vis )
  2.         (vlax-for obj blk
  3.             (if (and (= "AcDbBlockReference" (vla-get-objectname obj))
  4.                      (vlax-property-available-p obj 'isdynamicblock)
  5.                      (= :vlax-true (vla-get-isdynamicblock obj))
  6.                      (or (setq bln (vla-get-effectivename  obj)
  7.                                vis (cdr (assoc bln lst))
  8.                          )
  9.                          (and (setq vis (LM:getvisibilityparametername obj))
  10.                               (setq lst (cons (cons bln vis) lst))
  11.                          )
  12.                      )
  13.                      (setq vis (LM:getdynpropvalue obj vis))
  14.                 )
  15.                 (if (tblsearch "block" (setq bln (strcat bln "_" vis)))
  16.                     (vla-put-name obj bln)
  17.                     (vla-converttostaticblock obj bln)
  18.                 )
  19.             )
  20.         )
  21.     )
  22.     (princ)
  23. )
  24.  
  25. ;; Get Dynamic Block Property Value  -  Lee Mac
  26. ;; Returns the value of a Dynamic Block property (if present)
  27. ;; blk - [vla] VLA Dynamic Block Reference object
  28. ;; prp - [str] Dynamic Block property name (case-insensitive)
  29.  
  30. (defun LM:getdynpropvalue ( blk prp )
  31.     (setq prp (strcase prp))
  32.     (vl-some '(lambda ( x ) (if (= prp (strcase (vla-get-propertyname x))) (vlax-get x 'value)))
  33.         (vlax-invoke blk 'getdynamicblockproperties)
  34.     )
  35. )
  36.  
  37. ;; Get Visibility Parameter Name  -  Lee Mac
  38. ;; Returns the name of the Visibility Parameter of a Dynamic Block (if present)
  39. ;; blk - [vla] VLA Dynamic Block Reference object
  40. ;; Returns: [str] Name of Visibility Parameter, else nil
  41.  
  42. (defun LM:getvisibilityparametername ( blk / vis )  
  43.     (if
  44.         (and
  45.             (vlax-property-available-p blk 'effectivename)
  46.             (setq blk
  47.                 (vla-item
  48.                     (vla-get-blocks (vla-get-document blk))
  49.                     (vla-get-effectivename blk)
  50.                 )
  51.             )
  52.             (= :vlax-true (vla-get-isdynamicblock blk))
  53.             (= :vlax-true (vla-get-hasextensiondictionary blk))
  54.             (setq vis
  55.                 (vl-some
  56.                    '(lambda ( pair )
  57.                         (if
  58.                             (and
  59.                                 (= 360 (car pair))
  60.                                 (= "BLOCKVISIBILITYPARAMETER" (cdr (assoc 0 (entget (cdr pair)))))
  61.                             )
  62.                             (cdr pair)
  63.                         )
  64.                     )
  65.                     (dictsearch
  66.                         (vlax-vla-object->ename (vla-getextensiondictionary blk))
  67.                         "ACAD_ENHANCEDBLOCK"
  68.                     )
  69.                 )
  70.             )
  71.         )
  72.         (cdr (assoc 301 (entget vis)))
  73.     )
  74. )
  75.  

Dynamic Block functions from here.

Lee Mac

  • Seagull
  • Posts: 12263
  • London, England
Re: Strip block of Dynamic Properties
« Reply #27 on: February 24, 2016, 01:39:17 PM »
Maybe the following to account for other dynamic block parameters and for locked layers?

Code - Auto/Visual Lisp: [Select]
  1. (defun c:staticblocks ( / doc eff lck lst nbn new obn vis vpl )
  2.           new
  3.         (lambda ( old vis / cnt rtn )
  4.             (setq cnt 0)
  5.             (if (tblsearch "block" (setq rtn (strcat old "_" vis)))
  6.                 (while (tblsearch "block" (setq rtn (strcat old "_" vis "_" (itoa (setq cnt (1+ cnt)))))))
  7.             )
  8.             rtn
  9.         )
  10.     )
  11.     (vlax-for lay (vla-get-layers doc)
  12.         (if (= :vlax-true (vla-get-lock lay))
  13.             (progn
  14.                 (setq lck (cons lay lck))
  15.                 (vla-put-lock lay :vlax-false)
  16.             )
  17.         )
  18.     )
  19.     (vlax-for blk (vla-get-blocks doc)
  20.         (vlax-for obj blk
  21.             (cond
  22.                 (   (not
  23.                         (and
  24.                             (= "AcDbBlockReference" (vla-get-objectname obj))
  25.                             (vlax-property-available-p obj 'isdynamicblock)
  26.                             (= :vlax-true (vla-get-isdynamicblock obj))
  27.                         )
  28.                     )
  29.                 )
  30.                 (   (setq obn (vla-get-name obj)
  31.                           nbn (cdr (assoc obn lst))
  32.                     )
  33.                     (vla-put-name obj nbn)                        
  34.                 )
  35.                 (   (and
  36.                         (or (setq eff (vla-get-effectivename obj)
  37.                                   vis (cdr (assoc eff vpl))
  38.                             )
  39.                             (and (setq vis (LM:getvisibilityparametername obj))
  40.                                  (setq vpl (cons (cons eff vis) vpl))
  41.                             )
  42.                         )
  43.                         (setq vis (LM:getdynpropvalue obj vis))
  44.                         (setq nbn (new eff vis))
  45.                     )
  46.                     (vla-converttostaticblock obj nbn)
  47.                     (setq lst (cons (cons obn nbn) lst))
  48.                 )
  49.             )
  50.         )
  51.     )
  52.     (foreach lay lck (vla-put-lock lay :vlax-true))
  53.     (princ)
  54. )
  55.  
  56. ;; Get Dynamic Block Property Value  -  Lee Mac
  57. ;; Returns the value of a Dynamic Block property (if present)
  58. ;; blk - [vla] VLA Dynamic Block Reference object
  59. ;; prp - [str] Dynamic Block property name (case-insensitive)
  60.  
  61. (defun LM:getdynpropvalue ( blk prp )
  62.     (setq prp (strcase prp))
  63.     (vl-some '(lambda ( x ) (if (= prp (strcase (vla-get-propertyname x))) (vlax-get x 'value)))
  64.         (vlax-invoke blk 'getdynamicblockproperties)
  65.     )
  66. )
  67.  
  68. ;; Get Visibility Parameter Name  -  Lee Mac
  69. ;; Returns the name of the Visibility Parameter of a Dynamic Block (if present)
  70. ;; blk - [vla] VLA Dynamic Block Reference object
  71. ;; Returns: [str] Name of Visibility Parameter, else nil
  72.  
  73. (defun LM:getvisibilityparametername ( blk / vis )  
  74.     (if
  75.         (and
  76.             (vlax-property-available-p blk 'effectivename)
  77.             (setq blk
  78.                 (vla-item
  79.                     (vla-get-blocks (vla-get-document blk))
  80.                     (vla-get-effectivename blk)
  81.                 )
  82.             )
  83.             (= :vlax-true (vla-get-isdynamicblock blk))
  84.             (= :vlax-true (vla-get-hasextensiondictionary blk))
  85.             (setq vis
  86.                 (vl-some
  87.                    '(lambda ( pair )
  88.                         (if
  89.                             (and
  90.                                 (= 360 (car pair))
  91.                                 (= "BLOCKVISIBILITYPARAMETER" (cdr (assoc 0 (entget (cdr pair)))))
  92.                             )
  93.                             (cdr pair)
  94.                         )
  95.                     )
  96.                     (dictsearch
  97.                         (vlax-vla-object->ename (vla-getextensiondictionary blk))
  98.                         "ACAD_ENHANCEDBLOCK"
  99.                     )
  100.                 )
  101.             )
  102.         )
  103.         (cdr (assoc 301 (entget vis)))
  104.     )
  105. )
  106.  

ronjonp

  • Needs a day job
  • Posts: 7027
Re: Strip block of Dynamic Properties
« Reply #28 on: February 24, 2016, 02:19:17 PM »
Nice one Ron - though, unfortunately I don't believe that you can rely on the Property Name of the Visibility State parameter being named "Visibility", since any dynamic block parameter may be arbitrarily named.

Dynamic Block functions from here.
Ah yes .. silly me  :)

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

rkmcswain

  • Swamp Rat
  • Posts: 949
Re: Strip block of Dynamic Properties
« Reply #29 on: March 01, 2016, 07:26:12 AM »
Quote from: MP
Friday quick & dirty freebie ... not the most efficient but free ...
...and then 6 years later, stolen and presented without credit. 

https://lispbox.wordpress.com/2016/02/29/undinamic-all-blocks-in-one-click/