Function Syntax: AttachImagesToBlocks / CopyPDFsToBlocks / AddPDFsToBlockDefs Version: 1.1 Date: 20.06.2026 6:38:47PM N/A short_description: 🚀 AttachImagesToBlocks is an AutoCAD and Civil 3D AutoLISP utility for matching PDF files and raster images to drawing block references. It can attach files in model space, copy and rename PDFs on disk, or embed the attached underlay into the matched block definition. The main benefit is faster block-based underlay placement, cleaner file naming, and improved AutoCAD Civil 3D production automation. command: 🧰 Load the LISP with APPLOAD or (load "AttachImagesToBlocks.lsp"). 🚀 Run AttachImagesToBlocks to attach matched PDF or image files in model space at block insertion points. 📤 Run CopyPDFsToBlocks to copy and rename PDF files on disk without modifying the drawing. 🧩 Run AddPDFsToBlockDefs to attach a matched file, transform it into the block definition, and remove the temporary model space copy. 📘 Target platform: AutoCAD and Civil 3D with AutoLISP, Visual LISP COM, DCL dialogs, and the AutoCAD -ATTACH command. description: 📘 This AutoLISP program opens one shared DCL dialog for attaching, copying, renaming, and embedding external PDF or raster image files based on matching block references. 🔍 The user selects a source folder, scans supported files, defines the file page rule, defines the block prefix rule, and reviews the matched rows in the list. 📐 In attach mode, the tool places the matched file at the block insertion point plus optional dX and dY offsets with a user-defined scale. 📤 In copy and rename mode, the tool creates renamed PDF copies using the matched block name or a custom prefix, standard name, suffix, and page number pattern. 🧩 In add-to-block-definition mode, the routine attaches the file temporarily, transforms it from model space into the block coordinate system, copies it into the block table record, and deletes the temporary entity. This is useful for AutoCAD Civil 3D plan production, PDF sheet indexing, underlay placement, raster image management, and block-based drawing organization. helper_function: 🚀 Command entry points - c:AttachImagesToBlocks, c:CopyPDFsToBlocks, and c:AddPDFsToBlockDefs start the three workflows. 🔍 Folder scan engine - AIB:scan-folder collects PDF, JPG, JPEG, PNG, TIF, TIFF, and BMP files and applies wildcard filtering. 📌 File page parser - AIB:image-page-num extracts leading or trailing page numbers using rules like ##_* and *_#. 🏷️ Block page parser - AIB:block-page-num extracts digits after a block prefix such as Page_. 🧩 Match builder - AIB:build-matches links each file row to a matched block name, block reference, entity name, and insertion point. 🎨 DCL dialog generator - AIB:write-dcl builds the runtime interface with mode radio buttons, folder fields, matching rules, list controls, help, and suggestions. 🧠 Suggestion engine - AIB:suggest-rules scores possible file rules and block prefixes to suggest the best match setup. 📐 Attachment capture - AIB:attach-and-capture runs -ATTACH and detects the newly created underlay entity. 🔄 Block-definition transform - AIB:ref->def and AIB:add-obj-to-blkdef transform temporary model space geometry into block definition coordinates. 📤 Copy workflow - AIB:exec-copy copies and renames files using the matched block name or a custom rename pattern. 🔒 Settings persistence - AIB:run-dialog saves scale, offsets, layer, folders, rules, filters, and naming values to AIB_settings.cfg. functionalities: 🚀 Attach files to block locations - places matched PDF or image files at block insertion points in model space. 📤 Copy and rename PDFs - creates organized PDF copies using block names or user-defined naming patterns. 🧩 Embed files into block definitions - moves an attached underlay from model space into the matched block definition. 🔍 Scan supported file types - detects PDF, JPG, JPEG, PNG, TIF, TIFF, and BMP files. 🏷️ Match by page number - pairs files and blocks using extracted page numbers from file names and block names. 🧠 Suggest matching rules - helps users discover the correct file rule and block prefix automatically. 🔢 Manage match rows - supports select all, select none, toggle, remove, move up, move down, and add external files. 📐 Use offsets and scale - controls placement with dX, dY, and scale settings. 🧹 Organize generated underlays by layer - creates or activates a target layer before placement. 📝 Preview rename pattern - shows the expected output naming format before copying files. 📘 Use built-in help - displays matching rule documentation and live examples from the scanned files and drawing blocks. 🔒 Undo batch attachment - wraps attachment and embedding operations in AutoCAD undo logic. result: ✅ The final result is a practical AutoCAD and Civil 3D automation tool that links external PDF and raster files to matching drawing blocks. It reduces manual attachment work, improves file naming consistency, supports block-based underlay workflows, and speeds up CAD production drawing management. additional_info: 📌 This utility works with external files, block references, underlays, images, file copying, and drawing organization. 🔴 It does not create Civil 3D alignments, profiles, section views, corridors, surfaces, labels, or bands. 🟧 AIB:get-blockrefs scans model space block references, so block matching is model space focused. 🔐 Folder browsing and file copying use Windows COM objects including Shell.Application and Scripting.FileSystemObject. 🧰 The routine uses the unified AutoCAD -ATTACH command for PDF and raster attachment compatibility. 📌 For PDF files, the attach command uses page 1; the parsed page number is used for matching file names to block names. 🧠 Settings are saved to AIB_settings.cfg in the current DWG folder.