BRC Posted August 24, 2015 Posted August 24, 2015 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?topic=32681.msg382548#msg382548 (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 Quote
Lee Mac Posted August 24, 2015 Posted August 24, 2015 Hi BRC, and welcome to CADTutor Try the following code: ([color=BLUE]defun[/color] c:undyn [color=BLUE]nil[/color] (undyn ([color=BLUE]vla-get-activedocument[/color] ([color=BLUE]vlax-get-acad-object[/color]))) ([color=BLUE]princ[/color]) ) ([color=BLUE]defun[/color] undyn ( doc [color=BLUE]/[/color] blk lst ) ([color=BLUE]vlax-for[/color] def ([color=BLUE]setq[/color] blk ([color=BLUE]vla-get-blocks[/color] doc)) ([color=BLUE]if[/color] ([color=BLUE]=[/color] [color=BLUE]:vlax-false[/color] ([color=BLUE]vla-get-isxref[/color] def)) ([color=BLUE]vlax-for[/color] obj def ([color=BLUE]and[/color] ([color=BLUE]=[/color] [color=MAROON]"AcDbBlockReference"[/color] ([color=BLUE]vla-get-objectname[/color] obj)) ([color=BLUE]=[/color] [color=BLUE]:vlax-true[/color] ([color=BLUE]vla-get-isdynamicblock[/color] obj)) ([color=BLUE]vlax-write-enabled-p[/color] obj) ([color=BLUE]setq[/color] lst ([color=BLUE]cons[/color] obj lst)) ) ) ) ) ([color=BLUE]foreach[/color] obj lst ([color=BLUE]vla-converttostaticblock[/color] obj (uniqueblock blk ([color=BLUE]strcat[/color] ([color=BLUE]vla-get-effectivename[/color] obj) [color=MAROON]"_DYNlocked"[/color])) ) ) ) ([color=BLUE]defun[/color] uniqueblock ( col key [color=BLUE]/[/color] tmp ) ([color=BLUE]cond[/color] ( ([color=BLUE]not[/color] (item-p col key)) key) ( ([color=BLUE]setq[/color] tmp 1) ([color=BLUE]while[/color] (item-p col ([color=BLUE]strcat[/color] key ([color=BLUE]itoa[/color] ([color=BLUE]setq[/color] tmp ([color=BLUE]1+[/color] tmp)))))) ([color=BLUE]strcat[/color] key ([color=BLUE]itoa[/color] tmp)) ) ) ) ([color=BLUE]defun[/color] item-p ( col key ) ([color=BLUE]not[/color] ([color=BLUE]vl-catch-all-error-p[/color] ([color=BLUE]vl-catch-all-apply[/color] '[color=BLUE]vla-item[/color] ([color=BLUE]list[/color] col key)))) ) ([color=BLUE]vl-load-com[/color]) ([color=BLUE]princ[/color]) Quote
BRC Posted August 24, 2015 Author Posted August 24, 2015 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 Quote
Lee Mac Posted August 24, 2015 Posted August 24, 2015 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. this works wonderfully. thank you! Excellent, you're welcome. 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. Quote
BRC Posted August 24, 2015 Author Posted August 24, 2015 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.