Multiple_text_mtext_2

Short description

Sort / Purpose: Convert multiple selected TEXT and MTEXT entities into a single MTEXT object while keeping each original line as a separate paragraph. β€’ Scope: Works on standard text objects in the current space and merges them into one formatted MTEXT container. β€’ Goal: Simplify editing and formatting by replacing several separate text items with one unified MTEXT that preserves visual layout and underlines.

Command:

Command name: T2M2 How to run: Load the LISP file, then type T2M2 in the command line and press Enter. β€’ Selection: When prompted, select any combination of TEXT and MTEXT entities to be converted into one MTEXT object.

Description:

β€’ Text collection: Builds an internal list of the text strings from all selected TEXT and MTEXT entities in the selection set. β€’ Underline conversion: Scans each string for “%%U” underline markers and replaces them with MTEXT underline codes using L and l so underlining is preserved correctly. β€’ Paragraph handling: For plain TEXT entities, prefixes each string with P so every original DText line becomes its own paragraph inside the final MTEXT. β€’ Concatenation: Concatenates all processed strings into one combined MTEXT content string in selection order. β€’ Placement: Creates a new MTEXT object at the insertion point of the first selected entity, using its text width to define the wrapping width. β€’ Property transfer: Copies key visual properties from the first entity to the new MTEXT such as Layer, Color, StyleName, and Height, as well as alignment and rotation. β€’ Cleanup: After successfully creating the new MTEXT, deletes all original TEXT and MTEXT entities that were part of the selection. β€’ No selection case: If no valid text objects are selected, prints a short message instead of doing any changes.

Helper function: (if any)​

Local helper functions inside the routine: β€’ *error*: Custom error handler that cleans up the created MTEXT object and any stored entities if an error or user cancel occurs. β€’ align_Mt: Determines a compatible MTEXT attachment point from either an existing MTEXT or a TEXT alignment setting so the new MTEXT aligns like the source. β€’ Get_MTOffset_pt: Computes a vertical offset point based on MTEXT height, bounding box, and attachment point, prepared for possible alignment offset logic. β€’ GetTextWidth: Calculates an appropriate text width for the new MTEXT, using TEXTBOX on TEXT entities or the Width property on MTEXT objects. β€’ ReplaceUnderline: Walks through each text string, converting “%%U” underline markers into MTEXT underline on and off codes L and l, ensuring open underlines are properly closed at the end if needed. Used system and VLA calls: β€’ vl-load-com: Enables use of ActiveX and VLA functions within the routine. β€’ vla-get-ActiveDocument: Gets the current drawing document object. β€’ vla-get-ModelSpace / Paperspace: Chooses the correct space object depending on where the user is working. β€’ vla-AddMText: Creates the final MTEXT entity containing the combined text.

Functionalities:

β€’ Multi text merge: Merges multiple individual TEXT and MTEXT items into a single MTEXT object for easier global editing. β€’ Paragraph preservation: Keeps each original TEXT line as its own paragraph inside MTEXT so line structure is not lost. β€’ Underline aware: Translates “%%U” underline codes into proper MTEXT underline formatting that works in modern text styles. β€’ Style consistency: Uses the first selected text object as a template for layer, color, text style, and height, ensuring the new MTEXT matches the existing annotation style. β€’ Alignment and rotation: Attempts to reproduce the same alignment and rotation of the first entity so the new MTEXT appears in the same visual position and orientation. β€’ Space aware: Automatically works in model space or paper space depending on the current active space of the document. β€’ Automatic cleanup: Removes all original text entities after creation of the MTEXT, preventing duplicates on screen.

Result:

Result: All selected TEXT and MTEXT objects are replaced by a single MTEXT entity that preserves line order, paragraph separation, and underline formatting while matching the original visual style. β€’ Cleaner editing: You can now edit the combined content in one MTEXT editor instead of handling many separate text entities. β€’ Consistent appearance: The new MTEXT inherits layer, color, style, height, alignment, and rotation from the first selected text item. β€’ Preserved structure: Individual lines from plain TEXT are kept as separate paragraphs, and underline codes are correctly converted to MTEXT format. β€’ Non reversible by command: Original text entities are deleted once the MTEXT is created, so the change is final unless you use Undo. Copy code: Copy T2M2 LISP

Images, animations etc.

Pixel

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="Multiple_text_mtext">
<src:RibbonToolTip.ExpandedContent>
<StackPanel>
<TextBlock Background="AntiqueWhite" TextAlignment="Left">
<Bold>Function Syntax: t2m2</Bold>
<LineBreak/>
<Bold>Version: 1 Date: 05.08.2025</Bold>
<LineBreak/>
<LineBreak/>
<Hyperlink>N/A</Hyperlink>
<LineBreak/>
<Bold>Purpose</Bold><LineBreak/>
This routine converts multiple selected TEXT and MTEXT objects into one new MTEXT object, preserving readable paragraph separation and transferring key properties from the first selected object.<LineBreak/>
<LineBreak/>

<Bold>Primary Command</Bold><LineBreak/>
<Span Foreground="DarkRed"><Bold>T2M2</Bold></Span> creates a single MTEXT object from the selection, then deletes the original text entities.<LineBreak/>
<LineBreak/>

<Bold>User Workflow</Bold><LineBreak/>
1. Run <Span Foreground="DarkRed"><Bold>T2M2</Bold></Span> in the AutoCAD command line.<LineBreak/>
2. Select one or more objects filtered to <Span Foreground="DarkRed"><Bold>TEXT</Bold></Span> and <Span Foreground="DarkRed"><Bold>MTEXT</Bold></Span> only.<LineBreak/>
3. The program reads each selected object string, converts underline markers, concatenates them into one MTEXT content string, then inserts a new MTEXT at the first object insertion point.<LineBreak/>
4. The program deletes the original TEXT and MTEXT objects after creating the combined MTEXT.<LineBreak/>
<LineBreak/>

<Bold>Selection Requirements and Outcome</Bold><LineBreak/>
<ul><LineBreak/>
  <li>If no objects are selected, it prints <Span Foreground="DarkRed"><Bold>No text selected.</Bold></Span> and exits.<LineBreak/></li><LineBreak/>
  <li>If objects are selected, it creates exactly one new <Span Foreground="DarkRed"><Bold>MTEXT</Bold></Span> object and removes the originals using <Span Foreground="DarkRed"><Bold>entdel</Bold></Span>.<LineBreak/></li><LineBreak/>
</ul><LineBreak/>
<LineBreak/>

<Bold>Core Functionalities</Bold><LineBreak/>
<ul><LineBreak/>
  <li><Bold>Multi selection conversion</Bold> collects strings from every selected TEXT or MTEXT and merges them into one MTEXT content stream.<LineBreak/></li><LineBreak/>
  <li><Bold>Paragraph preservation</Bold> ensures that each TEXT object becomes a separate paragraph inside the resulting MTEXT by prefixing TEXT strings with the MTEXT paragraph control <Span Foreground="DarkRed"><Bold>\P</Bold></Span>.<LineBreak/></li><LineBreak/>
  <li><Bold>Underline translation</Bold> converts legacy underline sequences <Span Foreground="DarkRed"><Bold>%%U</Bold></Span> into MTEXT underline toggles <Span Foreground="DarkRed"><Bold>\L</Bold></Span> and <Span Foreground="DarkRed"><Bold>\l</Bold></Span> so underline appears correctly in MTEXT.<LineBreak/></li><LineBreak/>
  <li><Bold>Width calculation</Bold> computes the new MTEXT width based on the first selected object using <Span Foreground="DarkRed"><Bold>GetTextWidth</Bold></Span>.<LineBreak/></li><LineBreak/>
  <li><Bold>Property inheritance</Bold> copies key properties from the first selected object to the new MTEXT including layer, color, style name, and height.<LineBreak/></li><LineBreak/>
  <li><Bold>Alignment and rotation matching</Bold> sets MTEXT attachment point and rotation to match the first object so the result is positioned consistently.<LineBreak/></li><LineBreak/>
  <li><Bold>Undo safety and cleanup</Bold> includes an error handler that attempts to close undo marks and delete partially created objects if an error occurs.<LineBreak/></li><LineBreak/>
</ul><LineBreak/>
<LineBreak/>

<Bold>Important Commands and Aspects</Bold><LineBreak/>
<Span Foreground="DarkRed"><Bold>ssget</Bold></Span> filters selection to TEXT and MTEXT.<LineBreak/>
<Span Foreground="DarkRed"><Bold>vla-get-TextString</Bold></Span> reads the displayed text content from each object.<LineBreak/>
<Span Foreground="DarkRed"><Bold>ReplaceUnderline</Bold></Span> converts %%U underline control codes to MTEXT underline toggles.<LineBreak/>
<Span Foreground="DarkRed"><Bold>\P</Bold></Span> is inserted for TEXT items to force new paragraphs in the final MTEXT content.<LineBreak/>
<Span Foreground="DarkRed"><Bold>vla-AddMText</Bold></Span> creates the combined MTEXT using insertion point and computed width.<LineBreak/>
<Span Foreground="DarkRed"><Bold>entdel</Bold></Span> deletes the original selected text entities after successful creation.<LineBreak/>
<LineBreak/>

<Bold>How the New MTEXT is Built</Bold><LineBreak/>
<ul><LineBreak/>
  <li>The routine iterates through the selection set and builds a list of text fragments called textlist.<LineBreak/></li><LineBreak/>
  <li>Each fragment is post processed by <Span Foreground="DarkRed"><Bold>ReplaceUnderline</Bold></Span> to rewrite underline codes appropriately.<LineBreak/></li><LineBreak/>
  <li>If the source object is TEXT, the fragment is prefixed with <Span Foreground="DarkRed"><Bold>\P</Bold></Span> so it becomes a separate paragraph when combined.<LineBreak/></li><LineBreak/>
  <li>All fragments are concatenated using <Span Foreground="DarkRed"><Bold>apply</Bold></Span> and <Span Foreground="DarkRed"><Bold>strcat</Bold></Span> into one combined string named combined.<LineBreak/></li><LineBreak/>
</ul><LineBreak/>
<LineBreak/>

<Bold>Placement, Size, and Formatting Rules</Bold><LineBreak/>
<ul><LineBreak/>
  <li><Bold>Insertion point</Bold> The new MTEXT insertion point is taken from the first selected object using <Span Foreground="DarkRed"><Bold>vla-get-InsertionPoint</Bold></Span>.<LineBreak/></li><LineBreak/>
  <li><Bold>Width</Bold> The new MTEXT width is derived from the first object via <Span Foreground="DarkRed"><Bold>GetTextWidth</Bold></Span>, which uses a textbox measurement for TEXT and MTEXT width property otherwise.<LineBreak/></li><LineBreak/>
  <li><Bold>Layer, color, style, height</Bold> These properties are copied from the first object to the new MTEXT using <Span Foreground="DarkRed"><Bold>vlax-put-property</Bold></Span> across Layer, Color, StyleName, Height.<LineBreak/></li><LineBreak/>
  <li><Bold>Attachment and rotation</Bold> The routine sets the MTEXT attachment point based on the first object alignment using <Span Foreground="DarkRed"><Bold>align_Mt</Bold></Span> and applies the same rotation value.<LineBreak/></li><LineBreak/>
</ul><LineBreak/>
<LineBreak/>

<Bold>Space Resolution</Bold><LineBreak/>
The routine determines whether to create the MTEXT in model space or paper space by checking the active space and MSpace state, then selects the correct container for <Span Foreground="DarkRed"><Bold>vla-AddMText</Bold></Span>.<LineBreak/>
<LineBreak/>

<Bold>Error Handling Behavior</Bold><LineBreak/>
<ul><LineBreak/>
  <li>If an error occurs, it attempts to end an undo mark on the active document if one was started.<LineBreak/></li><LineBreak/>
  <li>If a new MTEXT object was created but the routine fails, it deletes that MTEXT to avoid leaving partial results.<LineBreak/></li><LineBreak/>
  <li>If temporary entities were tracked in a list, it deletes them as well, then prints an error message unless the error is a user cancel or break.<LineBreak/></li><LineBreak/>
</ul><LineBreak/>
<LineBreak/>

<Bold>Operational Summary</Bold><LineBreak/>
This program will require the user to select one or more TEXT or MTEXT objects, then it will combine their strings into a single new MTEXT object placed at the first object position, it will preserve separate paragraphs for TEXT items using <Span Foreground="DarkRed"><Bold>\P</Bold></Span>, it will convert underline markers <Span Foreground="DarkRed"><Bold>%%U</Bold></Span> into MTEXT underline toggles, it will copy key formatting properties from the first selected object, and finally it will delete the original selected entities so only the combined MTEXT remains.<LineBreak/>


</TextBlock>
            
<Grid>
<Image Source="PNG" Stretch="Uniform"/>
</Grid>

<Grid>
<MediaElement
 Source="GIF"
 Stretch="Uniform"
 Visibility="Visible"/>
 </Grid>

</StackPanel>
</src:RibbonToolTip.ExpandedContent>
</src:RibbonToolTip>
</ResourceDictionary>



Additional info:

Share this page:

Leave a Reply

Page Tag: 🏷️ Text_menu

  • Multiple_text_mtext_2

    β€”

    by

    Short description Sort / Purpose: Convert multiple selected TEXT and MTEXT entities into a single MTEXT object while keeping each original line as a separate paragraph. β€’ Scope: Works on standard text objects in the current space and merges them into one formatted MTEXT container. β€’ Goal: Simplify editing and formatting by replacing several separate…

  • Copy_to_Clipboard_Xref

    β€”

    by

    Short description Sort / Purpose: Interactively pick nested TEXT, MTEXT, DIMENSION, LEADER, and BLOCK entities, extract their text and send it to the clipboard, then clean up temporary copies. β€’ Scope: Works on nested entities inside blocks or references using CTC3 as a β€œpick-through” text exporter. β€’ Goal: Quickly grab text content from visually picked…

  • Copy_to_Clipboard

    β€”

    by

    Short description Sort / Purpose: Export cleaned text from selected drawing annotations directly to the Windows clipboard in a copy ready format. β€’ Clipboard Export: Gathers text from TEXT, MTEXT, attributes, dimensions, multileaders, and blocks, then sends the processed result to the clipboard. β€’ Two Output Styles: Lets you choose between one line concatenated text…

  • RotateMtextVport

    β€”

    by

    Short description Rotate Text and Mtext in Viewport Aligns TEXT objects to viewport rotation while resetting MTEXT to horizontal orientation. Command: Command: RotateMtextVport Description: This command adjusts text orientation based on the current viewport rotation: MTEXT objects are reset to 0Β° rotation (horizontal) with top-left attachment point TEXT objects are rotated to match the viewport’s…

  • Background_Mask

    β€”

    by

    Short description Comming soon … Command: Comming soon … Description: Comming soon … Helper function: (if any)​ Comming soon … Functionalities: Comming soon … Result: Comming soon … Images, animations etc. Lisp code: Expand Code ⬇ Select Code Copy Code Comming soon … Share this page:

  • Lower

    β€”

    by

    Short description Sort / Purpose: Convert selected TEXT and MTEXT entities to either all upper case or all lower case in a single operation. β€’ Scope: Operates only on existing TEXT and MTEXT objects that you select in the drawing. β€’ Goal: Standardize the letter case of annotations quickly for consistent drawing documentation. Command: Command…

  • Upper

    β€”

    by

    Short description Short LISP to convert selected TEXT and MTEXT objects to uppercase. Command: Command: TC β€” Converts the string contents of selected TEXT/MTEXT to uppercase. Description: This routine prompts the user to select TEXT and MTEXT entities, then reads every entity’s text content, converts it to uppercase using STRCASE, and rewrites the modified string…

  • PrefixSuffixRound

    β€”

    by

    Short description Purpose: Add or remove prefixes and suffixes (with wildcard patterns) and round numeric text content for TEXT/MTEXT/ATTRIB/INSERT attributes Core idea: Use fixed-string and wildcard-based string comparisons to strip or template-rebuild text, plus optional rounding of numeric strings Persistence: Remembers last-used settings in environment variables (PSOT_*) for fast reuse across sessions and commands Command:…

  • PlusMinusNumericValue

    β€”

    by

    Short description Purpose: Increment or decrement numeric values inside TEXT, MTEXT, ATTDEF, and ATTRIB strings using a dialog-driven plus/minus value and target position Scope: Works on selected text-based entities, parsing each string to find embedded numbers, then modifies one or more of those numbers according to user settings Persistence: Stores last used increment value and…

  • Text2Multileader_00

    β€”

    by

    Short description AM β€” convert selected TEXT/MTEXT into a single MLeader with combined text and preserved max width Sorts text by insertion point (Y order) and concatenates into one string Creates an MLeader by picking arrowhead and landing points, then applies TextString and TextWidth Deletes the original text entities after building the combined content Command:…