Short description
π ReplaceBlock is an AutoCAD AutoLISP utility that replaces selected block references with another block definition from the active drawing while keeping the original insertion point, scale, rotation, layer, and color.
Command:
π Command syntax: ReplaceBlock
Type ReplaceBlock in the AutoCAD command line, select one or more block references, choose the replacement block from the dialog list, then confirm with OK.
Description:
π ReplaceBlock provides a fast dialog-based workflow for changing existing INSERT block references to another block definition already available in the current DWG file.
π§© The routine first asks the user to select block references. It then scans the drawing block table, builds a sorted list of available block names, and displays a temporary DCL dialog named Replace Block with a filter field and a popup list.
π The filter field supports quick block-name searching by matching typed text against the available block list. After a replacement block is selected, the tool inserts a new block reference at each original block insertion point, copies the original X scale, Y scale, Z scale, rotation, layer, and color, and then deletes the previous block reference.
π‘οΈ Edits are wrapped inside an AutoCAD undo mark so the replacement operation can be reverted safely with one UNDO action.
Helper function: (if any)β
π§ GetBlockNames collects block definitions from the active drawing block table and returns a sorted block-name list.
π update_list refreshes the dialog popup list whenever the user changes the filter text.
πΎ *ReplaceBlockName* stores the last selected replacement block name during the AutoCAD session.
π§Ή The error handler unloads the DCL dialog, deletes the temporary DCL file, removes temporary selection-set references, and closes the undo mark when needed.
Functionalities:
π Replaces selected AutoCAD block references with another block definition.
π§© Accepts only INSERT entities through the selection filter.
π Lists available block definitions from the active drawing.
π Provides a DCL dialog with a live filter field for faster block lookup.
π Preserves insertion point, X scale, Y scale, Z scale, and rotation.
π¨ Preserves original block layer and color.
π§ Works in ModelSpace or PaperSpace depending on the active viewport context.
π‘οΈ Uses an undo group for safe rollback.
π§Ή Deletes the temporary DCL file after the command completes.
Result:
β
The selected block references are replaced with the chosen block definition while keeping their main geometric placement and display properties.
β
The workflow is faster than manually deleting, reinserting, scaling, rotating, and relayering blocks one by one.
Images, animations etc.
XAML code:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:src="clr-namespace:Autodesk.Windows;assembly=AdWindows"> <src:RibbonToolTip x:Key="ReplaceBlock"> <src:RibbonToolTip.ExpandedContent> <StackPanel> <TextBlock Background="AntiqueWhite" TextAlignment="Left"> <Bold>Function Syntax: ReplaceBlock</Bold> <LineBreak/> <Hyperlink>AI + https://forums.augi.com/showthread.php?169170-Block-replacement-lisp-needed</Hyperlink> <LineBreak/> <Bold><Run Foreground="DodgerBlue">Description</Run></Bold><LineBreak/> <Run Foreground="White">π ReplaceBlock is an AutoCAD AutoLISP block replacement utility for quickly changing selected block references to another existing block definition from the active drawing.</Run><LineBreak/> <Run Foreground="LimeGreen">The main benefit is faster block management, cleaner CAD editing, and reduced manual work when replacing repeated symbols, details, markers, or annotation blocks.</Run><LineBreak/> <LineBreak/> <Bold><Run Foreground="DodgerBlue">Command Syntax</Run></Bold><LineBreak/> <Run Foreground="White">π Run </Run><Bold><Run Foreground="Orange">ReplaceBlock</Run></Bold><Run Foreground="White"> in the AutoCAD command line.</Run><LineBreak/> <Run Foreground="White">The command asks the user to select one or more </Run><Bold><Run Foreground="Orange">INSERT</Run></Bold><Run Foreground="White"> block references, then opens a DCL dialog for choosing the replacement block.</Run><LineBreak/> <LineBreak/> <Bold><Run Foreground="DodgerBlue">SEO Optimized Description</Run></Bold><LineBreak/> <Run Foreground="White">π§© This AutoCAD block replacement tool scans the active drawing block table, displays available block names in a searchable dialog, and replaces selected block references with the selected block definition.</Run><LineBreak/> <Run Foreground="White">π The inserted replacement block keeps the original block insertion point, X scale, Y scale, Z scale, rotation, layer, and color.</Run><LineBreak/> <Run Foreground="White">π The dialog includes a filter box so users can quickly locate the required block name without scrolling through long block libraries.</Run><LineBreak/> <Run Foreground="White">π‘οΈ The replacement process is wrapped in an AutoCAD undo group, making the operation easier to reverse if the selected replacement block was not correct.</Run><LineBreak/> <LineBreak/> <Bold><Run Foreground="LimeGreen">Functionalities</Run></Bold><LineBreak/> <Run Foreground="White">π </Run><Bold><Run Foreground="LimeGreen">Replace selected blocks</Run></Bold><Run Foreground="White"> - changes selected block references to another existing drawing block definition.</Run><LineBreak/> <Run Foreground="White">π§© </Run><Bold><Run Foreground="LimeGreen">INSERT selection filter</Run></Bold><Run Foreground="White"> - accepts only AutoCAD block references for safe processing.</Run><LineBreak/> <Run Foreground="White">π </Run><Bold><Run Foreground="LimeGreen">Block table scan</Run></Bold><Run Foreground="White"> - reads available block definitions from the active DWG file.</Run><LineBreak/> <Run Foreground="White">π </Run><Bold><Run Foreground="LimeGreen">Searchable DCL dialog</Run></Bold><Run Foreground="White"> - filters block names using typed text and updates the popup list interactively.</Run><LineBreak/> <Run Foreground="White">π </Run><Bold><Run Foreground="LimeGreen">Placement preservation</Run></Bold><Run Foreground="White"> - keeps insertion point, rotation, and X/Y/Z scale from each original block reference.</Run><LineBreak/> <Run Foreground="White">π¨ </Run><Bold><Run Foreground="LimeGreen">Layer and color preservation</Run></Bold><Run Foreground="White"> - assigns the original block layer and color to the replacement block reference.</Run><LineBreak/> <Run Foreground="White">π§ </Run><Bold><Run Foreground="LimeGreen">ModelSpace and PaperSpace support</Run></Bold><Run Foreground="White"> - inserts replacements in the active space based on the current viewport context.</Run><LineBreak/> <Run Foreground="White">π‘οΈ </Run><Bold><Run Foreground="LimeGreen">Undo-safe workflow</Run></Bold><Run Foreground="White"> - groups edits inside an AutoCAD undo mark.</Run><LineBreak/> <Run Foreground="White">π§Ή </Run><Bold><Run Foreground="LimeGreen">Temporary file cleanup</Run></Bold><Run Foreground="White"> - removes the generated DCL file after execution.</Run><LineBreak/> <LineBreak/> <Bold><Run Foreground="DodgerBlue">Important Commands and Functions</Run></Bold><LineBreak/> <Run Foreground="White">π Main command: </Run><Bold><Run Foreground="Orange">ReplaceBlock</Run></Bold><LineBreak/> <Run Foreground="White">π Block collection: </Run><Bold><Run Foreground="Orange">vla-get-blocks</Run></Bold><LineBreak/> <Run Foreground="White">π Entity selection: </Run><Bold><Run Foreground="Orange">ssget</Run></Bold><Run Foreground="White"> with </Run><Bold><Run Foreground="Orange">INSERT</Run></Bold><Run Foreground="White"> filter.</Run><LineBreak/> <Run Foreground="White">π§© Replacement creation: </Run><Bold><Run Foreground="Orange">vla-insertblock</Run></Bold><LineBreak/> <Run Foreground="White">ποΈ Original removal: </Run><Bold><Run Foreground="Orange">vla-delete</Run></Bold><LineBreak/> <Run Foreground="White">π‘οΈ Undo protection: </Run><Bold><Run Foreground="Orange">vla-startundomark</Run></Bold><Run Foreground="White"> and </Run><Bold><Run Foreground="Orange">vla-endundomark</Run></Bold><LineBreak/> <LineBreak/> <Bold><Run Foreground="DodgerBlue">Typical Workflow</Run></Bold><LineBreak/> <Run Foreground="White">1οΈβ£ Type </Run><Bold><Run Foreground="Orange">ReplaceBlock</Run></Bold><Run Foreground="White"> in AutoCAD.</Run><LineBreak/> <Run Foreground="White">2οΈβ£ Select the block references that must be replaced.</Run><LineBreak/> <Run Foreground="White">3οΈβ£ Use the filter box to find the target block name.</Run><LineBreak/> <Run Foreground="White">4οΈβ£ Press OK to replace the selected blocks.</Run><LineBreak/> <Run Foreground="White">5οΈβ£ Use AutoCAD UNDO if the replacement must be reverted.</Run><LineBreak/> <LineBreak/> <Bold><Run Foreground="DarkRed">Notes and Limitations</Run></Bold><LineBreak/> <Run Foreground="White">β οΈ The replacement block must already exist in the active drawing.</Run><LineBreak/> <Run Foreground="White">β οΈ Attribute values and dynamic block properties are not transferred by this routine.</Run><LineBreak/> <Run Foreground="White">β οΈ Original block references are deleted after the replacement references are inserted.</Run><LineBreak/> <LineBreak/> <Bold><Run Foreground="Gold">Tags</Run></Bold><LineBreak/> <Run Foreground="Gold">π·οΈ AutoCAD, π·οΈ AutoLISP, π·οΈ Civil 3D, π·οΈ Replace Block, π·οΈ Block Reference, π·οΈ DCL Dialog, π·οΈ Visual LISP, π·οΈ CAD Automation</Run><LineBreak/> </TextBlock> <!-- Use MediaElement for GIF (static first frame) and Image as fallback --> <Grid> <!-- GIF (shows first frame only) --> <MediaElement Source="GIF" Stretch="Uniform" Visibility="Visible"/> </Grid> <Grid> <!-- GIF (shows first frame only) --> <MediaElement Source="GIF" Stretch="Uniform" Visibility="Visible"/> </Grid> <Grid> <!-- Fallback static image --> <MediaElement Source="JPG" Stretch="Uniform" Visibility="Visible"/> </Grid> </StackPanel> </src:RibbonToolTip.ExpandedContent> </src:RibbonToolTip> </ResourceDictionary>
