|

Change Paper Size on Multiple Layouts with AutoLISP

Learn the safe sequence for changing CanonicalMediaName across layouts without assuming that every PC3 uses the same internal paper-size string.

Main idea: Paper size should be automated only after the target device and canonical media name have been verified.

Best use: Migrating many Layouts to one controlled plotter/media combination.

Start with the manual workflow

On one Layout, select the target PC3 and confirm the intended paper size. Then list the canonical media names from that exact device.

Build the automation in small layers

Step 1 — Fix the output device first

Where: PAGESETUP > Printer/Plotter

Do this: Select the PC3 that will be used by the automation.

Check: The target paper appears in that device’s media list.

Step 2 — Read canonical media names

Where: CPLISTMEDIA or ActiveX GetCanonicalMediaNames

Do this: Find the exact canonical string for the desired paper.

Check: You are not guessing from a localized UI label.

Step 3 — Prototype on one Layout

Where: Active Layout

Do this: Set CanonicalMediaName only on a copy/test Layout.

Check: The paper size updates without breaking margins/orientation.

Step 4 — Loop through selected Layouts

Where: AutoLISP Layouts collection

Do this: Apply the proven canonical value to the intended Layouts.

Check: Failures are reported individually.

Step 5 — Preview different sheet types

Where: Plot Preview

Do this: Check borders, orientation and printable area after the change.

Check: The device/media migration is visually correct.

Why paper-size automation is more difficult than it looks

The visible label “ARCH D” is not the full automation story. The available paper list belongs to the selected printer/PC3, and the internal canonical name can change with drivers. A routine that writes a media string before it has selected and refreshed the target device is therefore fragile.

A safer design uses an explicit mapping: for a given approved PC3, use this exact canonical media name for ARCH D, this one for ANSI D, and so on. If the requested value is not in the device’s current media list, the routine should report the Layout and stop or skip it rather than guessing.

What the code should control

  • ConfigName before CanonicalMediaName
  • RefreshPlotDeviceInfo
  • GetCanonicalMediaNames
  • CanonicalMediaName
  • Orientation and printable area verification

What you should deliberately leave manual at first

Do not automatically remap every existing custom media name by text similarity. If a driver exposes different sizes, build an explicit approved mapping table.

Failure modes to design for

  • Setting paper before device so the media name is invalid.
  • Using a localized paper label instead of canonical media name.
  • Assuming ARCH D and ANSI D are interchangeable.
  • Ignoring printable area changes after the device switch.

When this becomes a production tool

A production tool should validate the requested media against GetCanonicalMediaNames for each target device and stop/skip when the value is unavailable.

Official Autodesk references

Frequently asked questions

Why use canonical media names?

They are the API values tied to the selected plot device; the user-facing labels can vary by locale/driver.

Can I set one media name before I set the PC3?

That is risky because the available media list belongs to the device.

Should the routine change orientation too?

Only if your office standard has an explicit orientation rule. Verify paper size first.

Explore more in AutoLISP Plotting & PDF Automation.