Function Syntax: t2m2 Version: 1 Date: 05.08.2025 N/A Purpose 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. Primary Command T2M2 creates a single MTEXT object from the selection, then deletes the original text entities. User Workflow 1. Run T2M2 in the AutoCAD command line. 2. Select one or more objects filtered to TEXT and MTEXT only. 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. 4. The program deletes the original TEXT and MTEXT objects after creating the combined MTEXT. Selection Requirements and Outcome
  • If no objects are selected, it prints No text selected. and exits.
  • If objects are selected, it creates exactly one new MTEXT object and removes the originals using entdel.
Core Functionalities
  • Multi selection conversion collects strings from every selected TEXT or MTEXT and merges them into one MTEXT content stream.
  • Paragraph preservation ensures that each TEXT object becomes a separate paragraph inside the resulting MTEXT by prefixing TEXT strings with the MTEXT paragraph control \P.
  • Underline translation converts legacy underline sequences %%U into MTEXT underline toggles \L and \l so underline appears correctly in MTEXT.
  • Width calculation computes the new MTEXT width based on the first selected object using GetTextWidth.
  • Property inheritance copies key properties from the first selected object to the new MTEXT including layer, color, style name, and height.
  • Alignment and rotation matching sets MTEXT attachment point and rotation to match the first object so the result is positioned consistently.
  • Undo safety and cleanup includes an error handler that attempts to close undo marks and delete partially created objects if an error occurs.
Important Commands and Aspects ssget filters selection to TEXT and MTEXT. vla-get-TextString reads the displayed text content from each object. ReplaceUnderline converts %%U underline control codes to MTEXT underline toggles. \P is inserted for TEXT items to force new paragraphs in the final MTEXT content. vla-AddMText creates the combined MTEXT using insertion point and computed width. entdel deletes the original selected text entities after successful creation. How the New MTEXT is Built
  • The routine iterates through the selection set and builds a list of text fragments called textlist.
  • Each fragment is post processed by ReplaceUnderline to rewrite underline codes appropriately.
  • If the source object is TEXT, the fragment is prefixed with \P so it becomes a separate paragraph when combined.
  • All fragments are concatenated using apply and strcat into one combined string named combined.
Placement, Size, and Formatting Rules
  • Insertion point The new MTEXT insertion point is taken from the first selected object using vla-get-InsertionPoint.
  • Width The new MTEXT width is derived from the first object via GetTextWidth, which uses a textbox measurement for TEXT and MTEXT width property otherwise.
  • Layer, color, style, height These properties are copied from the first object to the new MTEXT using vlax-put-property across Layer, Color, StyleName, Height.
  • Attachment and rotation The routine sets the MTEXT attachment point based on the first object alignment using align_Mt and applies the same rotation value.
Space Resolution 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 vla-AddMText. Error Handling Behavior
  • If an error occurs, it attempts to end an undo mark on the active document if one was started.
  • If a new MTEXT object was created but the routine fails, it deletes that MTEXT to avoid leaving partial results.
  • 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.
Operational Summary 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 \P, it will convert underline markers %%U 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.