PDA

View Full Version : Redefining your Dynamic Blocks



whdjr
2006-06-26, 08:28 PM
This is a jewel I wrote a while back that I use all the time when creating and testing Dynamic Blocks. You still need to 'ATTSYNC' the block after you make changes to update any attribute mods you might have made.

Let me know if you got any questions.

Save this as rib.lsp somewhere in your acad support path.
Load it by typing: (load "rib")
Run it by typing: rib

All you do is make a block just like you always have and save it. Then reopen it and add your dynamic properties to it and then save the block. Then open a file that has that block in it already(not with the new changes), and load and run RIB and then select the block and it will update with the new changes to your old block.

;;;
;;;This tool allows the user to select a block or dynamic block and redefines
;;;the block. It searches in the current directory first, then the AutoCAD
;;;support paths, then it looks for a global variable of the last place it
;;;found the block, and lastly lets you select the block to redefine it with.
;;;
;;;Copyright 2005 Will DeLoach
;;;
;;; $db_path$ - global variable same value as local variable file.
;;; Is very helpful when designing and tesing Dynamic Blocks.
;;;
;;;RIB = ReInsert Block
(defun c:rib (/
ss ; selection set of block to redefine
ent ; entity name of block
obj ; object of the entity
name ; name of block
path ; short path of block location
file ; full path of block location
)
(while (not ss)
(setvar "ErrNo" 0)
(prompt "\nSelect a Block to redefine: ")
(cond
((setq ss (ssget ":S:E" '((0 . "INSERT"))))
(if (> (sslength ss) 1)
(and
(princ
"\nMore than one Block was selected. Please select only one Block. "
)
(setq ss nil)
)
(setq ent (ssname ss 0))
)
)
((= (getvar "ErrNo") 52)
(princ "\nRight-Click detected. Program Terminated.")
(exit)
)
((null ss)
(princ "\nSelection missed. Please try again.")
)
)
)
(setq obj (vlax-ename->vla-object ent))
(if (and (vlax-property-available-p obj 'isdynamicblock)
(eq (vla-get-isdynamicblock obj) :vlax-true)
)
(setq name (vlax-get-property obj "effectivename"))
(setq name (vla-get-name obj))
)
(setq path (vla-get-path (vla-get-document obj)))
(cond ((setq file (findfile (strcat path "\\" name ".dwg"))))
((setq file (findfile (strcat name ".dwg"))))
((if (and $db_path$ (eq (vl-filename-base $db_path$) name))
(setq file $db_path$)
)
)
(T
(setq file (getfiled "Select a Block"
(strcat path "\\")
"dwg"
(+ 64 128)
)
$db_path$ file
)
)
)
(if file
(progn
(command "-insert" (strcat name "=" file) nil)
(princ (strcat "\nBlock " name " was loaded from " file))
)
(princ)
)
(princ)
)

BrenBren
2006-06-27, 02:51 PM
Will,

Just wanted to let you know that I moved this over here, as I feel it is a good tip and should probably be placed here; I know we have gotten requests on the wish list for AutoCAD to do this, so I felt this should probably have it's own thread.

Let me know if you've got any questions.