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

0 Members and 1 Guest are viewing this topic.

Shade

  • Guest
Strip block of Dynamic Properties
« on: March 23, 2010, 01:07:55 pm »
Does any one have a lisp that will strip the dynamic properties from dynamic blocks?

I have an extensive DB library which I use quite heavily throughout my drawings, some payed for, others spent serious time on developing.
I starting freelance drafting about a year ago and would like to protect my investment in the DB's, both in money as well as time and effort.
My DB collection helps me produce drawings quicker and more accurately then the clients can in house.  Which is why my clients come to me with the work.
I have released the dwg files with the DB's, in them to the clients and have notice they are starting to use them in their offices.
One client has drop my services altogether because he is able to work cheaper in house with my DB collection then before.
I would like to strip any DB from my drawings to prevent other's from following suit.
The only way I figure to protect my db now is to explode all blocks before transferring to the clients.
If anyone has a better way of protecting my investment, please feel free to express it.

Any help would be greatly appreciated.....

Thanks
Shade  :mrgreen:




 

MP

  • Seagull
  • Posts: 16940
  • brevity != aggression
Re: Strip block of Dynamic Properties
« Reply #1 on: March 23, 2010, 01:10:05 pm »
What version of AutoCAD? What happens if you do a "Save As" to the lowest version available, does that "lobotomize" the dynamic blocks?

edit: DOH, just saw your sig. Last question stands.
\|// Set goal. Experiment tirelessly until
|oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox | About

MP

  • Seagull
  • Posts: 16940
  • brevity != aggression
Re: Strip block of Dynamic Properties
« Reply #2 on: March 23, 2010, 01:35:55 pm »
Okay, that doesn't work. I have 2008. Saved to r14 and re-opened -- the dynamic data round tripped ok.

Some lisp should be able to lobotomize it no prob tho.
\|// Set goal. Experiment tirelessly until
|oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox | About

alanjt

  • Needs a day job
  • Posts: 5310
  • Standby for witty remark...
Re: Strip block of Dynamic Properties
« Reply #3 on: March 23, 2010, 01:39:26 pm »
Just an example:
Code: [Select]
(vla-ConvertToStaticBlock (vlax-ename->vla-object (car (entsel))) "NewName")
Civil 3D 2017 ~ Windohz 7 64bit
Dropbox

MP

  • Seagull
  • Posts: 16940
  • brevity != aggression
Re: Strip block of Dynamic Properties
« Reply #4 on: March 23, 2010, 01:42:29 pm »
yep
\|// Set goal. Experiment tirelessly until
|oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox | About

alanjt

  • Needs a day job
  • Posts: 5310
  • Standby for witty remark...
Re: Strip block of Dynamic Properties
« Reply #5 on: March 23, 2010, 01:46:29 pm »
Granted, if you select multiples of the same Dynamic block, it will error. However, you just convert the first one, then rename the remaining accordingly.
Code: [Select]
(vla-put-name x "NewName")
Civil 3D 2017 ~ Windohz 7 64bit
Dropbox

MP

  • Seagull
  • Posts: 16940
  • brevity != aggression
Re: Strip block of Dynamic Properties
« Reply #6 on: March 23, 2010, 02:13:21 pm »
Be careful, that strategy will introduce errors unless all instances of a given block share the same state.
\|// Set goal. Experiment tirelessly until
|oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox | About

Lee Mac

  • Seagull
  • Posts: 11732
  • AutoCAD 2015 Windows 7 London, England
Re: Strip block of Dynamic Properties
« Reply #7 on: March 23, 2010, 02:31:35 pm »
Just an example:
Code: [Select]
(vla-ConvertToStaticBlock (vlax-ename->vla-object (car (entsel))) "NewName")

That's a new one for me thanks Alan  :-)

alanjt

  • Needs a day job
  • Posts: 5310
  • Standby for witty remark...
Re: Strip block of Dynamic Properties
« Reply #8 on: March 23, 2010, 02:36:05 pm »
Be careful, that strategy will introduce errors unless all instances of a given block share the same state.
Oh yeah, I wasn't thinking about that.

Just an example:
Code: [Select]
(vla-ConvertToStaticBlock (vlax-ename->vla-object (car (entsel))) "NewName")

That's a new one for me thanks Alan  :-)
:)  I remembered seeing it a while back when I wrote the routine that allows one to change the visibility states for multiple Dynamic blocks at once.
Civil 3D 2017 ~ Windohz 7 64bit
Dropbox

MP

  • Seagull
  • Posts: 16940
  • brevity != aggression
Re: Strip block of Dynamic Properties
« Reply #9 on: March 26, 2010, 01:43:38 pm »
Friday quick & dirty freebie ... not the most efficient but free ...

Code: [Select]
(defun c:UnDynamic

    (   /
        _get_item
        _right
        _make_key
        _dynamic->static_block
        _get_locked
        _get_dynamic_inserts
        _main
    )

    (defun _get_item ( collection key / item )
        (vl-catch-all-apply
           '(lambda ( ) (setq item (vla-item collection key)))
        )
        item
    )

    (defun _right ( str n / len )
        (if (< n (setq len (strlen str)))
            (substr str (1+ (- len n)))
            str
        )
    )

    (defun _make_key ( collection prefix len / key )
        (   (lambda ( i pad )
                (while
                    (_get_item collection
                        (setq key
                            (strcat prefix
                                (_right
                                    (strcat pad (itoa (setq i (1+ i))))
                                    len
                                )
                            )
                        )
                    )
                )
                key
            )
            0
            (   (lambda ( pad )
                    (while (< (strlen pad) len)
                        (setq pad (strcat "0" pad))
                    )
                    pad
                )
                ""
            )
        )
    )

    (defun _dynamic->static_block ( blocks insert len )
        (vla-ConvertToStaticBlock
            insert
            (_make_key blocks "STATIC_" len)
        )
    )

    (defun _get_locked ( layers / locked )
        (vlax-for layer layers
            (if (eq :vlax-true (vla-get-lock layer))
                (setq locked (cons layer locked))
            )
        )
        locked
    )

    (defun _get_dynamic_inserts ( blocks / inserts )
        (vlax-for block blocks
            (vlax-for object block
                (if (eq "AcDbBlockReference" (vla-get-objectname object))
                    (if (eq :vlax-true (vla-get-isdynamicblock object))
                        (setq inserts (cons object inserts))
                    )
                )
            )
        )
        inserts
    )

    (defun _main ( document / blocks inserts locked len )
        (if
            (setq inserts
                (_get_dynamic_inserts
                    (setq blocks (vla-get-blocks document))
                )
            )
            (progn
                (foreach layer (setq locked (_get_locked (vla-get-layers document)))
                    (vla-put-lock layer :vlax-false)
                )
                (setq len (strlen (itoa (length inserts))))
                (foreach insert inserts
                    (_dynamic->static_block blocks insert len)
                )
                (foreach layer locked
                    (vla-put-lock layer :vlax-true)
                )
            )
        )
        (princ)
    )

    (_main (vla-get-activedocument (vlax-get-acad-object)))

)

\|// Set goal. Experiment tirelessly until
|oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox | About

alanjt

  • Needs a day job
  • Posts: 5310
  • Standby for witty remark...
Re: Strip block of Dynamic Properties
« Reply #10 on: March 26, 2010, 02:01:55 pm »
Friday quick & dirty freebie ... not the most efficient but free ...
Alan is right, you really are an artist. Nice work.
Civil 3D 2017 ~ Windohz 7 64bit
Dropbox

Lee Mac

  • Seagull
  • Posts: 11732
  • AutoCAD 2015 Windows 7 London, England
Re: Strip block of Dynamic Properties
« Reply #11 on: March 26, 2010, 02:16:11 pm »
Friday quick & dirty freebie ... not the most efficient but free ...
Alan is right, you really are an artist. Nice work.

x2   :-)

MP

  • Seagull
  • Posts: 16940
  • brevity != aggression
Re: Strip block of Dynamic Properties
« Reply #12 on: March 26, 2010, 02:38:59 pm »
Tall praise given the source(s). Someday I will be worthy. Thanks guys.
\|// Set goal. Experiment tirelessly until
|oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox | About

trogg

  • Bull Frog
  • Posts: 243
Re: Strip block of Dynamic Properties
« Reply #13 on: November 14, 2010, 10:22:32 pm »
In my CAD customization class, we were warned that after we saved our drawings with dynamic blocks, if we save them as a .dxf we would lose the dynamic block functions and any hyper-links.
just a thought from a newbie.
Although - I really like the code though too

cmwade77

  • Swamp Rat
  • Posts: 1009
Re: Strip block of Dynamic Properties
« Reply #14 on: November 15, 2010, 01:43:23 pm »
The .dxf method would work, but may introduce more errors too.....the code looks good too though.