Function Syntax: MLeaderWidthFix Version: 1 Date: 23.07.2025 AI+https://www.cadtutor.net/forum/topic/23656-help-modiying-text-width-lisp/page/2/ AI+https://forums.autodesk.com/t5/autocad-forum/reduce-mtext-box-width-of-multiple-mtext/td-p/8951871 Command name MLeaderWidthFix Purpose 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. What the user must do • Select objects on screen when prompted (the selection filter allows TEXT, MTEXT, and MULTILEADER). • Enter a new width value when prompted, or press Enter to accept the suggested default. Selection and supported object types • The selection is performed with ssget using a filter for TEXT, MTEXT, MULTILEADER. • Internally it distinguishes objects by ObjectName: AcDbText (single-line TEXT) AcDbMText (multiline MTEXT) AcDbMLeader (Multileader) Main workflow • Loads the Visual LISP COM interface with vl-load-com so it can read and write object properties via ActiveX. • Computes a default width suggestion by scanning the selection and summing widths: For AcDbText: estimates width using textbox on the entity data. For AcDbMText: measures bounding box width using vla-getBoundingBox and the lower-left and upper-right points. For AcDbMLeader: only processes leaders whose ContentType is 2 (MText content) and reads width via TextWidth. • Calculates the average width: avgwidth = total / count (fallback is 1.0 if nothing was measured). • Prompts the user for a new width with getdist, showing the average as the default value. • Stores the chosen width to an environment variable using setenv key WD_LastWidth (note: this value is stored, but this code does not read it back on the next run). • Applies the new width to each selected object where possible: AcDbMText: sets property Width to the chosen value (protected by vl-catch-all-apply). AcDbMLeader with ContentType = 2: sets property TextWidth to the chosen value (protected by vl-catch-all-apply). AcDbText: does not change width (prints a message that width is not directly settable and skips). • Prints a completion message: Applied width: ... Functionalities (bullet list) • Filters selection to annotation-like objects: TEXT, MTEXT, MULTILEADER. • Automatically derives a suggested default width based on the average width of selected items. • Prompts for a user-defined target width with an Enter-to-accept default behavior. • Updates width for MTEXT objects by setting Width. • Updates width for MULTILEADER objects only when they contain MText content (ContentType = 2) by setting TextWidth. • Uses error-safe property setting through vl-catch-all-apply to avoid hard crashes if a property cannot be written. • Stores the last entered width in WD_LastWidth via setenv for potential reuse by other routines or future enhancements. Important notes and limitationsTEXT objects are effectively read-only for direct width control in this routine; they are measured for the average but not modified during apply.MULTILEADER objects are only modified if they are MText-based leaders (ContentType = 2); leaders with block content are ignored for width changes. • If the user selects nothing valid, the routine prints: No valid entities selected.