Function Syntax: ctc Version: 1 Date: 08.09.2025 AI + https://www.theswamp.org/index.php?topic=21764.msg263322#msg263322 Purpose This program lets the user copy text content from selected AutoCAD objects to the Windows clipboard, with a choice of output formatting (single line versus paragraph style). Primary Command CTC launches a dialog to choose the export mode, then runs the corresponding copy routine. User Workflow 1. Run CTC in the AutoCAD command line. 2. A dialog titled Clipboard Export Options appears with two radio options. 3. Choose one format and click OK or Cancel. 4. If OK, the program prompts the user to select objects in the drawing. 5. The program extracts text from each selected object, cleans MTEXT formatting codes, and copies the final result to the clipboard. Dialog and Option Memory The dialog is generated at runtime into a temporary DCL file and loaded dynamically. The last chosen radio option is remembered between runs in *ctc-last-option* (defaults to rb01 on first run). Supported Object Types for Selection The selection filter includes the following DXF types: TEXT MTEXT ATTRIB ATTDEF DIMENSION MULTILEADER INSERT (blocks, including attributes when present) Modes and Output Formats
  • Mode 1 CTC_1 and option rb01 No paragraphs, intended to produce a more single line style by removing linefeed characters and normalizing spacing during cleanup, while still appending each extracted item into the final clipboard text.
  • Mode 2 CTC_2 and option rb02 With paragraphs, intended to preserve a line by line structure, including inserting line breaks for specific known words that begin with P in the source content.
Key Functionalities
  • Interactive option selection using a temporary DCL dialog written by writeCTCDCL and displayed by radioCTCDCL.
  • Dispatch to the selected routine via c:CTC which calls c:CTC_1 or c:CTC_2 based on the chosen radio button.
  • Batch extraction of text from each selected object, building a combined output string named rawText.
  • Cleaning and normalization of MTEXT and formatting artifacts using StripMTextCodes_1 or StripMTextCodes_2.
  • Clipboard export using the COM object htmlfile and its clipboarddata interface with setdata to write plain text to the clipboard.
  • Error handling and cleanup via a local *error* function that releases COM objects and runs garbage collection to reduce leaked handles.
Extraction Rules by Object Type
  • TEXT, MTEXT, ATTRIB, ATTDEF Extracts the primary text value from DXF group 1 and then cleans it with the selected strip function.
  • DIMENSION Reads the text override first, and if empty uses the numeric measurement converted to text, then cleans it.
  • MULTILEADER Reads the leader text string from the object and then cleans it.
  • INSERT blocks If the block has attributes, it iterates attributes and appends each attribute text string after cleaning. If the block has no attributes, it uses the effective block name as the output text.
Text Cleaning and Normalization Details The program contains two cleaning functions that remove AutoCAD MTEXT markup and normalize spacing, with slightly different paragraph behavior per mode. Unicode and Special Symbol Handling Both strip functions attempt to convert sequences of the form \U+xxxx into actual characters using hex conversion, and also explicitly substitute common sequences into symbols such as ≥ ≤ ± and °. Removal of MTEXT Formatting Codes Both strip functions remove or delete common inline formatting sequences and patterns, including items like font, height, color, alignment, underline, overline, and other backslash driven codes that typically end with a semicolon. They also remove a curated list of known garbage fragments that appear in the specific content the script is designed to process. Whitespace and Line Break Normalization
  • Replaces the MTEXT non breaking space marker \~ with a normal space.
  • Replaces actual linefeed characters with spaces to normalize raw input prior to other cleanup operations.
  • Collapses multiple consecutive spaces down to single spaces.
Mode Specific Paragraph Behavior
  • CTC_1 strip function includes logic intended to remove stray P artifacts that can appear due to paragraph markers, with a special exception to avoid breaking the token PE-HD.
  • CTC_2 strip function introduces paragraph line breaks for a known list of P prefixed words by replacing those words with the same word without the leading P and inserting a linefeed before it.
  • CTC_2 strip function also collapses double line breaks into single line breaks at the end of cleanup.
User Visible Output
  • If text is found, the command prints a message indicating how many objects were processed and echoes the copied text to the command line, and the same text is placed into the clipboard.
  • If no readable text is found, it prints a message indicating that nothing readable was found.
  • If the selection is empty or the user cancels, it prints a cancel message and exits cleanly.
Important Commands and Symbols to Recognize CTC main entry point command. CTC_1 copy to clipboard without paragraph style cleaning. CTC_2 copy to clipboard with paragraph style cleaning. writeCTCDCL creates the DCL dialog definition file. radioCTCDCL shows the dialog and returns the selected option. *ctc-last-option* stores the last selected dialog option for the next run. htmlfile COM object used to access Windows clipboard data. Operational Summary This program will require the user to select supported objects in the drawing, then it will extract relevant text content, sanitize MTEXT formatting codes and known artifacts, and copy the resulting text to the clipboard in either a normalized single line style or a paragraph oriented line by line style, depending on the chosen dialog option.