|

AutoCAD: Batch Change Polyline Width with PLW (AutoLISP Tool)

Description

The PolyWidthChange.lsp (PLW) script is a production-ready AutoLISP utility designed to batch standardize polyline widths in AutoCAD drawings.

It processes:

  • Lightweight Polylines (LWPOLYLINE)
  • Heavy 2D Polylines (POLYLINE)

in a single operation, regardless of how they were originally created.

The routine automatically filters incompatible objects, such as 3D polylines, using safe error handling. This prevents command failure and keeps execution clean, even in messy drawings.

Use this tool when you need consistent linework across:

  • Site plans
  • Architectural layouts
  • Electrical and MEP schematics

This is not a workaround. It’s a direct fix for inconsistent polyline widths at scale.


Download the script here.


Step-by-Step Instructions

Load the Script

  • Drag and drop PolyWidthChange.lsp into the drawing or
  • Type APPLOAD, then select the file

Reference: AutoCAD

Recommended (for daily use): To keep the command available in every drawing, add the script to your Startup Suite inside the APPLOAD dialog.


Initialize the Command

Type:

PLW

Press Enter


Define Width

  • Enter a numerical value or
  • Pick two points to define the distance interactively

The routine uses getdist, so it follows your current units and scale.


Select Objects

  • Use window selection, crossing, or manual picks
  • The filter ensures only polyline entities are processed

Execution

Press Enter

  • All valid polylines are updated immediately
  • A message reports how many objects were modified

The AutoLISP Code

This is the exact implementation used. It is stable, handles edge cases, and avoids crashes caused by unsupported entities.

```lisp id="plw-code" ;;; ========================================================================== ;;; Command: PLW ;;; Description: Changes the global width of selected polylines to a user-specified value. ;;; ==========================================================================

(vl-load-com) ; Ensure Visual LISP extensions are loaded

(defun c:PLW ( / newWidth ss i ent obj count) ;; Prompt user for the new global width (setq newWidth (getdist "\nEnter new global width for polylines: "))

;; Proceed only if a valid width was entered (if newWidth (progn (prompt "\nSelect polylines to change width: ") ;; Allow user to select objects, filtering only for polylines (setq ss (ssget '((0 . "*POLYLINE"))))
  (if ss
    (progn
      (setq i 0
            count 0) ; Counter for successfully changed polylines

      ;; Loop through the selection set
      (while (< i (sslength ss))
        (setq ent (ssname ss i))
        (setq obj (vlax-ename->vla-object ent))

        ;; Try to set the ConstantWidth property. 
        ;; We use vl-catch-all-apply to silently skip 3D polylines that don't support width.
        (if (not (vl-catch-all-error-p 
                   (vl-catch-all-apply 'vla-put-ConstantWidth (list obj newWidth))))
          (setq count (1+ count))
        )

        (setq i (1+ i))
      )
      ;; Print completion message
      (princ (strcat "\nSuccessfully updated the width of " (itoa count) " polyline(s)."))
    )
    (princ "\nNo polylines selected.")
  )
)
(princ "\nCommand canceled: No width entered.")

)

(princ) ; Exit quietly )

(prompt "\nPolyWidthChange.lsp loaded. Type PLW to run.") (princ) ```

Why Use a Custom LISP for Polyline Width?

The Properties Palette works for small selections, but it breaks down in real-world drawings.

Typical issues:

  • Mixed polyline types
  • Legacy objects behaving differently
  • Partial updates or ignored values
  • Manual edits at vertex level

This routine avoids all of that.

It relies on:

  • ActiveX (Visual LISP) through vlax-ename->vla-object
  • Direct access to ConstantWidth
  • Safe execution using vl-catch-all-apply

That gives you:

  • Batch processing without interruption
  • Consistent results across mixed objects
  • No manual cleanup required

For CAD managers, this is a straightforward way to enforce lineweight standards across multiple files.

Official references:


What the Script Actually Does (Important Behavior)

This routine sets the ConstantWidth property on each polyline.

That means:

  • Any existing variable-width segments are replaced
  • The entire polyline becomes uniform

Example:

  • Original: Start width = 0, End width = 10
  • After PLW: Entire polyline = 5 (if 5 is entered)

This is intentional. The goal is standardization, not preservation of variable geometry.


Practical Use Cases

Standardizing Imported Drawings

External DWGs often contain inconsistent widths. Run PLW once to normalize everything.


Pre-Plot Cleanup

Ensures uniform visual output before printing or exporting to PDF.


Legacy Drawing Cleanup

Old files with mixed polyline definitions are handled in one pass.


CAD Standards Enforcement

Use it as part of a QA workflow before issuing drawings.


Limitations

  • Applies ConstantWidth only
  • Replaces variable-width segments with a single uniform width
  • Skips:
    • 3D polylines
    • Unsupported entities

This behavior is deliberate to maintain speed and stability.


Tips from Production Use

  • Run OVERKILL before PLW to remove duplicates
  • Combine with layer filters to target specific elements
  • Add to your startup suite for immediate availability
  • Use before plotting to avoid inconsistent line appearance

FAQ

Does this work on 3D polylines?

No. They don’t support ConstantWidth. The script skips them automatically.


Why use getdist instead of getreal?

Because getdist allows point picking and respects drawing units directly.


What happens if I select unsupported objects?

They are ignored. The command continues without interruption.


Can it handle large selections?

Yes. It uses ActiveX, so performance remains stable even with large datasets.


Does it overwrite existing widths?

Yes. All selected compatible polylines are forced to a single uniform width.


Can I keep this tool permanently loaded?

Yes. Add it to the Startup Suite in APPLOAD so it loads with every session.


Can it preserve variable widths?

No. It is designed to standardize, not preserve variation.