Guys I found a .lsp that would change all dynamic blocks to regular block. The problem I have with it is the block names are being renamed to "Static XX (XX being different numbers) Is there a way to update this .lsp so that I retains the block names? Thank you so much in advance.
(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)))
)
Solved! Go to Solution.
Solved by pbejse. Go to Solution.
@burniksapwet wrote:
Guys I found a .lsp that would change all dynamic blocks to regular block. The problem I have with it is the block names are being renamed to "Static XX (XX being different numbers) Is there a way to update this .lsp so that I retains the block names? Thank you so much in advance.
Doable BUT what of two or more instances of that block present on the drawing? and both have different "dynamic" settings? Both of them cannot have the same name. One would inherit the original name, but one would be different is what i'm saying.
EDIT: hang on, so what you are wanting is replace the word STATIC with the original block name? if YES its easy
BTW, who is the original author of the code?
@pbejse wrote:
EDIT: hang on, so what you are wanting is replace the word STATIC with the original block name? if YES its easy
BTW, who is the original author of the code?
(defun _dynamic->static_block ( blocks insert len ) (vla-ConvertToStaticBlock insert (_make_key blocks (strcat (vla-get-effectivename insert)" ") len) ) )
I found it here. http://www.theswamp.org/index.php?topic=32681.msg382548#msg382548
For duplicate valves if you can maybe add a number at the end of the block name. If that is not possible i guess i will just have to make sure that there are only one type of block in that drawing. Thank you for replying.
And yes I would like for it to keep the block name instead of changing it to static. Thank you.
burniksapwet wrote:
...For duplicate valves if you can maybe add a number at the end of the block name...
...And yes I would like for it to keep the block name instead of changing it to static. Thank you...
Did you try the snippet posted at post #3.
Now if there are duplicates, leaving one block to retain its original name would take some more coding. We need to identify which one right after all the blocks are processed AND redefine the block keeping its current state as a static block.
burniksapwet wrote:
Also can it not have the number after it?
....If it's not to much to ask would you mind updating the full lsp so that I could just copy and paste it? ...
Only when there is no duplicate.
Try the attached lisp file
HTH
Thank you so much sir. This is exactly what I am looking for. We really do appreciate the time you took to help us out. More power to you.
pbejse,
Tried out your undynamic.lsp and it works great!
Wrestled all weekend trying to figure out how to limit its effects to just model space dynamic blocks (without success).
I'm barely limping along trying to figure out regular lisp, so everything i tried in your vlisp code really was just stabbing in the dark. A whole lot of reading, trying stuff, reading, trying stuff. Not even a hint of success. Luckily, the worst i could make it do was nothing at all.
Just what does it take to make the program ignore or filter out the paper space dynamics?
Thanks
I give up.
the best I could do for getting just the blocks in model space was
(setq blocks (ssget "_x" (list '(0 . "insert")'(410 . "Model"))))(vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object)))
which does get the set into vlisp as a vla-object, but as a selection set
#<VLA-OBJECT IAcadSelectionSet 2bba3c84>
whereas (setq blocks (vla-get-blocks(vla-get-activedocument (vlax-get-acad-object))))
#<VLA-OBJECT IAcadBlocks 28436304>
which apparently is what the program is looking for. I have not been able to get the iacadselectionset to become iacadblocks...
cheers
I may go ahead and try starting a new thread on this since it seems like i'm the only one keeps checking on it.
I have hundreds of dynamic blocks of exactly the same name and I would like their names to remain exactly same when they change to static blocks. My blocks are basically rectangular shapes with different rotations.
@pbejse wrote:burniksapwet wrote:
Also can it not have the number after it?
....If it's not to much to ask would you mind updating the full lsp so that I could just copy and paste it? ...
Only when there is no duplicate.Try the attached lisp fileHTH
@Anonymous wrote:
I have hundreds of dynamic blocks of exactly the same name and I would like their names to remain exactly same when they change to static blocks. My blocks are basically rectangular shapes with different rotations.
EXACTLY the same name? You mean it LOOKS exactly the same geometry, may be rotated or scaled or a different color but NOT with an anonymous name like *U5"? At its unaltered state.?
Using Architecture 2022, I get automation error. key not found. Can you please assist?
Hello,
Is there any way to add a conversion of the attributes inside block to normal texts before getting it as regular blocks?
Can't find what you're looking for? Ask the community or share your knowledge.