+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Forum Newbie
    Using
    AutoCAD 2013
    Join Date
    Aug 2015
    Posts
    3

    Default undynamic lisp modification

    Registered forum members do not see this ad.

    hi Lisp guru's,

    I have done some searches for lisps that can turn dynamic blocks into static, the one i have found incredibly done well was this Undynamic by MP
    http://www.theswamp.org/index.php?to...2548#msg382548

    Code:
    (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)))
    
    )
    i am a complete noob at lisp (but trying to learn). could you guys help me somehow incorporate (strcat (vlax-get-property obj 'Name) "_DYNlocked")) into the lisp above (sorry MP for modifying) so that the replaced static blocks retain the original dynamic block name.

    i am hoping in future i can do a block replace on the static blocks to update them back into dynamic blocks for utilization.

    thanks for your help!
    regards,
    BRC

  2. #2
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,366

    Default

    Hi BRC, and welcome to CADTutor

    Try the following code:
    Code:
    (defun c:undyn nil
        (undyn (vla-get-activedocument (vlax-get-acad-object)))
        (princ)
    )
    (defun undyn ( doc / blk lst )
        (vlax-for def (setq blk (vla-get-blocks doc))
            (if (= :vlax-false  (vla-get-isxref def))
                (vlax-for obj def
                    (and (= "AcDbBlockReference" (vla-get-objectname obj))
                         (= :vlax-true (vla-get-isdynamicblock obj))
                         (vlax-write-enabled-p obj)
                         (setq lst (cons obj lst))
                    )
                )
            )
        )
        (foreach obj lst
            (vla-converttostaticblock obj
                (uniqueblock blk (strcat (vla-get-effectivename obj) "_DYNlocked"))
            )
        )
    )
    (defun uniqueblock ( col key / tmp )
        (cond
            (   (not (item-p col key)) key)
            (   (setq tmp 1)
                (while (item-p col (strcat key (itoa (setq tmp (1+ tmp))))))
                (strcat key (itoa tmp))
            )
        )
    )
    (defun item-p ( col key )
        (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-item (list col key))))
    )
    (vl-load-com) (princ)
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  3. #3
    Forum Newbie
    Using
    AutoCAD 2013
    Join Date
    Aug 2015
    Posts
    3

    Default

    wow, the renowned LeeMac! i've seen your legendary work all over the forums. nice to meet you.

    this works wonderfully. thank you!
    next step i will attempt to do a lisp for block replacing them back into dynamic blocks. - i will do some research for this phase.

    plan is to static the dblocks when sending out to clients, then block replace to recover the dynamics when we recieve files back

  4. #4
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,366

    Default

    Quote Originally Posted by BRC View Post
    wow, the renowned LeeMac! i've seen your legendary work all over the forums. nice to meet you.
    Thank you for your kind words - nice to meet you too.

    Quote Originally Posted by BRC View Post
    this works wonderfully. thank you!
    Excellent, you're welcome.

    Quote Originally Posted by BRC View Post
    next step i will attempt to do a lisp for block replacing them back into dynamic blocks. - i will do some research for this phase.
    You'll probably want to attach a list of the dynamic block property values to the block either within an extension dictionary or as xdata, else it will be near impossible to determine the appropriate dynamic block properties to use when inserting the dynamic block to replace the static insert.
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  5. #5
    Forum Newbie
    Using
    AutoCAD 2013
    Join Date
    Aug 2015
    Posts
    3

    Default

    Registered forum members do not see this ad.

    you're right, i just tried doing a block replace and noticed it would revert back to it's original insertion of the block. this is far more complex than i thought it would be. i'll look into the extension dictionary and xdata mentioned.

Similar Threads

  1. Undynamic a Block
    By woodman78 in forum AutoLISP, Visual LISP & DCL
    Replies: 1
    Last Post: 21st Mar 2013, 03:59 pm
  2. modification of a lisp
    By monk in forum AutoLISP, Visual LISP & DCL
    Replies: 0
    Last Post: 26th Sep 2010, 05:05 pm
  3. Modification of LISP
    By cadamrao in forum AutoLISP, Visual LISP & DCL
    Replies: 7
    Last Post: 3rd May 2010, 10:04 am
  4. lisp modification
    By chelsea1307 in forum AutoLISP, Visual LISP & DCL
    Replies: 6
    Last Post: 24th Apr 2010, 12:50 am

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts