Short description
Command:
Description:
Helper function: (if any)β
Functionalities:
Result:
Images, animations etc.
Log in
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>

Leave a Reply
You must be logged in to post a comment.