MLeaderWidthFix

Short description

  • MLeaderWidthFix β€” normalize MTEXT / MLeader (MText-content) widths using a user-specified value with an average-width default
  • Computes an average width from the current selection to propose as the default input
  • Applies the chosen width to MTEXT and MLeaders that use MTEXT content; TEXT is reported as not directly settable
10 sample text and mask

Command:

  • β€’ MLeaderWidthFix

Description:

  • Selects a set of TEXT, MTEXT, and MULTILEADER entities from the current selection context.
  • Calculates a β€œdefault” width by averaging widths measured across the selected objects (TEXT extents, MTEXT bounding box width, and MLeader TextWidth when it is MTEXT-based).
  • Prompts the user for a new width, showing the computed average as the default value.
  • Applies the new width to MTEXT objects via Width and to MTEXT-content MLeaders via TextWidth (ContentType = 2).
  • For TEXT (DText), reports that width is not directly settable and skips modification.

Helper function: (if any)​

  • β€’ textbox (built-in) β€” used to obtain TEXT extents for a width estimate from the entity’s bounding box.
  • β€’ vla-getBoundingBox β€” used to compute MTEXT width from lower-left / upper-right bounding box X coordinates.
  • β€’ vl-catch-all-apply β€” wraps property writes to avoid hard failures when setting Width or TextWidth.
  • β€’ setenv β€” stores the last width value as WD_LastWidth (note: the prompt default is computed from the current selection, not read back from the environment variable).

Functionalities:

  • β€’ Selection β€” collects entities using ssget with filter TEXT,MTEXT,MULTILEADER; prints β€œNo valid entities selected” if none.
  • β€’ Width measurement: TEXT β€” uses textbox extents and computes width from X difference of the two corners; contributes to averaging.
  • β€’ Width measurement: MTEXT β€” reads bounding box and computes width from ur.x – ll.x; contributes to averaging.
  • β€’ Width measurement: MLeader β€” only includes MLeaders with ContentType = 2 (MTEXT content) and adds TextWidth to averaging.
  • β€’ Default width β€” sets default to total / count if count > 0; otherwise falls back to 1.0; formats as a string with 3 decimals for the prompt.
  • β€’ User input β€” prompts New Width <avg>:; if user presses Enter, uses the default value.
  • β€’ Apply: TEXT β€” prints a message indicating TEXT width is not directly settable and skips changes.
  • β€’ Apply: MTEXT β€” attempts to set Width to the chosen value using a protected property write.
  • β€’ Apply: MLeader (MTEXT content) β€” for ContentType = 2, attempts to set TextWidth to the chosen value using a protected property write.
  • β€’ Feedback β€” prints Applied width: with the final numeric value.

Result:

  • MTEXT objects have their Width set to the user-entered value, standardizing wrapping/column width across the selection.
  • MLeaders that use MTEXT content (ContentType = 2) have their TextWidth set to the same value.
  • TEXT entities are left unchanged and explicitly reported as skipped because their width is not directly settable via a simple Width property in this routine.

Images, animations etc.

10 sample text and mask
20 properties palette
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="MLeaderWidthFix">
<src:RibbonToolTip.ExpandedContent>
<StackPanel>
<TextBlock Background="AntiqueWhite" TextAlignment="Left">
<Bold>Function Syntax: MLeaderWidthFix</Bold>
<LineBreak/>
<Bold>Version: 1 Date: 23.07.2025</Bold>
<LineBreak/>
<LineBreak/>
<Hyperlink>AI+https://www.cadtutor.net/forum/topic/23656-help-modiying-text-width-lisp/page/2/</Hyperlink>
<LineBreak/>
<Hyperlink>AI+https://forums.autodesk.com/t5/autocad-forum/reduce-mtext-box-width-of-multiple-mtext/td-p/8951871</Hyperlink>
<LineBreak/>
<Bold>Command name</Bold><LineBreak/>
<Run Foreground="DarkRed">MLeaderWidthFix</Run><LineBreak/>

<Bold>Purpose</Bold><LineBreak/>
This program helps standardize the text wrapping width for selected annotation objects by calculating an average width from your selection, then letting you apply a new width to all applicable objects in that selection.<LineBreak/>

<Bold>What the user must do</Bold><LineBreak/>
β€’ Select objects on screen when prompted (the selection filter allows <Run Foreground="DarkRed">TEXT</Run>, <Run Foreground="DarkRed">MTEXT</Run>, and <Run Foreground="DarkRed">MULTILEADER</Run>).<LineBreak/>
β€’ Enter a new width value when prompted, or press Enter to accept the suggested default.<LineBreak/>

<Bold>Selection and supported object types</Bold><LineBreak/>
β€’ The selection is performed with <Run Foreground="DarkRed">ssget</Run> using a filter for <Run Foreground="DarkRed">TEXT, MTEXT, MULTILEADER</Run>.<LineBreak/>
β€’ Internally it distinguishes objects by <Run Foreground="DarkRed">ObjectName</Run>:<LineBreak/>

<Run Foreground="DarkRed">AcDbText</Run> (single-line TEXT)<LineBreak/>

<Run Foreground="DarkRed">AcDbMText</Run> (multiline MTEXT)<LineBreak/>

<Run Foreground="DarkRed">AcDbMLeader</Run> (Multileader)<LineBreak/>

<Bold>Main workflow</Bold><LineBreak/>
β€’ Loads the Visual LISP COM interface with <Run Foreground="DarkRed">vl-load-com</Run> so it can read and write object properties via ActiveX.<LineBreak/>
β€’ Computes a default width suggestion by scanning the selection and summing widths:<LineBreak/>

For <Run Foreground="DarkRed">AcDbText</Run>: estimates width using <Run Foreground="DarkRed">textbox</Run> on the entity data.<LineBreak/>

For <Run Foreground="DarkRed">AcDbMText</Run>: measures bounding box width using <Run Foreground="DarkRed">vla-getBoundingBox</Run> and the lower-left and upper-right points.<LineBreak/>

For <Run Foreground="DarkRed">AcDbMLeader</Run>: only processes leaders whose <Run Foreground="DarkRed">ContentType</Run> is <Run Foreground="DarkRed">2</Run> (MText content) and reads width via <Run Foreground="DarkRed">TextWidth</Run>.<LineBreak/>
β€’ Calculates the average width: <Run Foreground="DarkRed">avgwidth = total / count</Run> (fallback is <Run Foreground="DarkRed">1.0</Run> if nothing was measured).<LineBreak/>
β€’ Prompts the user for a new width with <Run Foreground="DarkRed">getdist</Run>, showing the average as the default value.<LineBreak/>
β€’ Stores the chosen width to an environment variable using <Run Foreground="DarkRed">setenv</Run> key <Run Foreground="DarkRed">WD_LastWidth</Run> (note: this value is stored, but this code does not read it back on the next run).<LineBreak/>
β€’ Applies the new width to each selected object where possible:<LineBreak/>

<Run Foreground="DarkRed">AcDbMText</Run>: sets property <Run Foreground="DarkRed">Width</Run> to the chosen value (protected by <Run Foreground="DarkRed">vl-catch-all-apply</Run>).<LineBreak/>

<Run Foreground="DarkRed">AcDbMLeader</Run> with <Run Foreground="DarkRed">ContentType = 2</Run>: sets property <Run Foreground="DarkRed">TextWidth</Run> to the chosen value (protected by <Run Foreground="DarkRed">vl-catch-all-apply</Run>).<LineBreak/>

<Run Foreground="DarkRed">AcDbText</Run>: does not change width (prints a message that width is not directly settable and skips).<LineBreak/>
β€’ Prints a completion message: <Run Foreground="DarkRed">Applied width: ...</Run><LineBreak/>

<Bold>Functionalities (bullet list)</Bold><LineBreak/>
β€’ Filters selection to annotation-like objects: <Run Foreground="DarkRed">TEXT</Run>, <Run Foreground="DarkRed">MTEXT</Run>, <Run Foreground="DarkRed">MULTILEADER</Run>.<LineBreak/>
β€’ Automatically derives a suggested default width based on the average width of selected items.<LineBreak/>
β€’ Prompts for a user-defined target width with an Enter-to-accept default behavior.<LineBreak/>
β€’ Updates width for <Run Foreground="DarkRed">MTEXT</Run> objects by setting <Run Foreground="DarkRed">Width</Run>.<LineBreak/>
β€’ Updates width for <Run Foreground="DarkRed">MULTILEADER</Run> objects only when they contain MText content (<Run Foreground="DarkRed">ContentType = 2</Run>) by setting <Run Foreground="DarkRed">TextWidth</Run>.<LineBreak/>
β€’ Uses error-safe property setting through <Run Foreground="DarkRed">vl-catch-all-apply</Run> to avoid hard crashes if a property cannot be written.<LineBreak/>
β€’ Stores the last entered width in <Run Foreground="DarkRed">WD_LastWidth</Run> via <Run Foreground="DarkRed">setenv</Run> for potential reuse by other routines or future enhancements.<LineBreak/>

<Bold>Important notes and limitations</Bold><LineBreak/>
β€’ <Run Foreground="DarkRed">TEXT</Run> objects are effectively read-only for direct width control in this routine; they are measured for the average but not modified during apply.<LineBreak/>
β€’ <Run Foreground="DarkRed">MULTILEADER</Run> objects are only modified if they are MText-based leaders (<Run Foreground="DarkRed">ContentType = 2</Run>); leaders with block content are ignored for width changes.<LineBreak/>
β€’ If the user selects nothing valid, the routine prints: No valid entities selected.<LineBreak/>

</TextBlock>
            
<Grid>
<Image Source="10-sample text and mask.PNG" Stretch="Uniform"/>
</Grid>
<Grid>
<Image Source="20-properties palette.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: 🏷️ Dimnesions

  • MLeaderWidthFix

    β€”

    by

    Short description MLeaderWidthFix β€” normalize MTEXT / MLeader (MText-content) widths using a user-specified value with an average-width default Computes an average width from the current selection to propose as the default input Applies the chosen width to MTEXT and MLeaders that use MTEXT content; TEXT is reported as not directly settable Command: β€’ MLeaderWidthFix Description:…

  • MleaderStraight

    β€”

    by

    Short description MLeader Perp Align + DCL chooser (Model or Paper space aware) Aligns MLeader landing by projecting the first vertex to a perpendicular reference through the end vertex Scope chooser: interactive selection or all MLeaders in current space/layout Works in ModelSpace or PaperSpace based on current active space Command: β€’ MleaderStraightTools Description: Displays a…