Delete Dynamic Block Visibility

Delete Dynamic Block Visibility

kieran.leadbetter
Advocate Advocate
1,435 Views
13 Replies
Message 1 of 14

Delete Dynamic Block Visibility

kieran.leadbetter
Advocate
Advocate

Hello, I am currently at the last stages of creating a massive batch lisp/script process and appreciate everyones help so far. I have just one last lisp which is required if anyone would happen to have one already made and happy to share their knowledge.

Currently I have 4 separately named dynamic blocks within each drawing, I am looking to either remove all dynamic blocks and replace them as identically named, I have found multiple lisps which do this, however all rename the blocks which defeats the purpose of my end goal, as keeping the block name allows me to redefine them in future if required.

OR alternatively a lisp which will delete all unselected Visibility functions from all dynamic blocks, meaning the block visibility which is currently shown, will remain the blocks default.

If either of these are possible, I would be beyond grateful to anyones help or advice as I have learned so much the past few days.

Kind Regards,

0 Likes
1,436 Views
13 Replies
Replies (13)
Message 2 of 14

pendean
Community Legend
Community Legend
So you want all the visibility variations of a dynamic block in your DWG file to maintain the exact name? That's not an AutoCAD ability. Sorry. There will need to be some difference in name for each instance.
0 Likes
Message 3 of 14

kieran.leadbetter
Advocate
Advocate
Sorry no, I want either any unused visiblities to be deleted, leaving only the shown one, i.e. there could be 3 visibilitys within a block, but after the lisp is run, there would only be 1 visibility in the block, which is the one already shown

OR

Have all dynamic block functionality deleted

Both methods require the block name to remain intact with no renaming occuring
0 Likes
Message 4 of 14

ronjonp
Mentor
Mentor

@kieran.leadbetter wrote:
...
Have all dynamic block functionality deleted

Both methods require the block name to remain intact with no renaming occuring

Blocks don't work like that. If you have a block definition with 3 visibilities and 3 block references with a different visibility shown then you need 3 separate block names. Why are you trying to remove the smarts from your blocks?

0 Likes
Message 5 of 14

Sea-Haven
Mentor
Mentor

What about Burst ? Could then make back into a new block.

0 Likes
Message 6 of 14

kieran.leadbetter
Advocate
Advocate

There will only be 1 variation of the block, there are 4 blocks being put into the model, but each block is separately named, there are no blocks within blocks
- Block Name
 - Visibility 1
 - Visibility 2
 - Visibility 3 

Its a task for a client, they have requested some blocks and due to the scale of the work, about 500 drawings currently, it was much faster and quicker on our end to create dynamic blocks to adjust it if any mistakes are created. However we do not want to send all the visibilities to the client currently as they only paid for one visibility at the current time.

The smarts are more for inoffice use, whereas once the dynamic functions are removed, we can sell them to the client

0 Likes
Message 7 of 14

kieran.leadbetter
Advocate
Advocate

Need a quicker method due to the scale, currently I have a lisp which explodes all dynamic blocks from the drawing, but adds a "_1" to the end,

So I undynamic the blocks then
Rename the blocks with _1 at the end manually,

Oh, would it be possible for a lisp to remove specific characters from all block names, so if I make the addition at the end of a block name really unique such as "_RemoveThisPart"

That way I could undynamic all blocks and just rename the blocks in bulk

0 Likes
Message 8 of 14

paullimapa
Mentor
Mentor

Not sure about the differences in how the different visibility would look. But if it was a door with each visibility being a different directional swing and you not remove all visibility but one then you’ll end up with situations where there would be doors swinging the wrong direction. Make sure your client is aware of the consequences involved with what he’s asking. 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 9 of 14

ronjonp
Mentor
Mentor

@kieran.leadbetter wrote:

Need a quicker method due to the scale, currently I have a lisp which explodes all dynamic blocks from the drawing, but adds a "_1" to the end,

So I undynamic the blocks then
Rename the blocks with _1 at the end manually,

Oh, would it be possible for a lisp to remove specific characters from all block names, so if I make the addition at the end of a block name really unique such as "_RemoveThisPart"

That way I could undynamic all blocks and just rename the blocks in bulk


@kieran.leadbetter  Your blocks must be fantastic. Renaming, removing parts,  bringing back to life. Anything is possible, but there are also better work flows.

0 Likes
Message 10 of 14

kieran.leadbetter
Advocate
Advocate
Hello again, sorry for late reply, I was on annual leave for a week, back in office and ready to learn again.

Currently there about a hundred blocks with varying dynamic abilities, each block uses a specific block name, but there are no blocks within each block in order to keep it somewhat simpler when editing blocks.

If there are 3 Visibility States, A B and C, and A is selected, I need B and C to be removed from Visibility Selection, doesn't matter if the unseen lines within the block are deleted or just permanently invisible.

One block name is:

NCR 6629 Collar_ADV 15'' 4_High

I need to retain this block name in order to redefine the block on a large scale across aprox 450 Information Sheets, possibly more in future. The bulk redefine lisp you created the other week works brilliant, alongside it I am also using a UnDynamic_AllBlocks Lisp, however this in turn renames the block to:

NCR Collar_ADV 15'' 4_High_1.

So my 2 options are:

1: Ideal Goal
- Redefine All Blocks
- Delete unrequired visibility types
- Purge All
- Rename All Blocks Lisp (Remove the _1 at the end of block names)
- Save and Quit, ready for next redefine when required

2:
- Redefine All Blocks
- Make all blocks UnDynamic (This creates the issue of if the block is redefined, I will have to manually select the correct visibility each time)
- Purge All
- Rename All Blocks Lisp (Remove the _1 at the end of block names)
- Save and Quit, ready for next redefine when required
0 Likes
Message 11 of 14

kieran.leadbetter
Advocate
Advocate
This shouldn't be an issue for the purpose of my task, the Blocks I am creating will only appear once within a drawing, meaning as long as the correct visibility state is selected and retained, while only deleting/removing the ones not selected, it will allow us to redefine blocks in a mass bulk method saving weeks of work
0 Likes
Message 12 of 14

Sea-Haven
Mentor
Mentor

A Google barely tested seems to work. Dynamic Block to Static Block - Renamed after Visibility State - Autodesk Community - AutoCAD

 

Once ran you need to purge dynamic block out then can rename removing the item number on end, "WINDOW 2",  ran twice 2 visibilty states, 3rd go "WINDOW 3"

0 Likes
Message 13 of 14

smallƑish
Advocate
Advocate

Try this;

 

(defun c:UnDynamic
    (   /
        _get_item
        _right
        _make_key
        _dynamic->static_block
        _get_locked
        _get_dynamic_inserts
        _main
     	bn_lst
    	adoc
    )
    (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
                )
                ""
            )
        )
    )


;;;				Autodesk Lisp Forum            			;;;

      
      (defun _dynamic->static_block ( blocks insert len blst / f bn  bnr)
       (setq bn  (vla-get-effectivename insert))    
        (vla-ConvertToStaticBlock
            insert
            (setq bnr (_make_key blocks (strcat bn " ") len))
        )
        (setq bnr (list bn (vl-string-left-trim (strcat bn " ") bnr) insert))   
        (if (setq f (assoc bn blst))
			 (subst bnr f blst)(cons bnr blst))
	)

;;;				Autodesk Lisp Forum            			;;;

      
    (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
		(Setq bn_lst
                    (_dynamic->static_block blocks insert len bn_lst))
                      
                )
                (foreach layer locked
                    (vla-put-lock layer :vlax-true)
                )
            )
        )
        (princ)
    )


;;;				Autodesk Lisp Forum            			;;;

	(repeat 4 (vla-purgeall (setq adoc (vla-get-activedocument (vlax-get-acad-object)))))
      
	(_main adoc)
      
	(repeat 4 (vla-purgeall adoc))
	(setq blocks (vla-get-blocks adoc))
	(foreach itm bn_lst
		(vl-catch-all-error-p (vl-catch-all-apply 'vla-put-name 
		          (list (vla-item blocks (Strcat (Car itm)" "(cadr itm))) (Car itm))))
	   )

;;;				Autodesk Lisp Forum            			;;;
          
)
0 Likes
Message 14 of 14

ronjonp
Mentor
Mentor

@smallƑish 

Credit to the late author Michael Puckett. There are also a few more examples in that thread.

0 Likes