Changing plot settings through Dynamo and Python

Hi all,

I’m trying to adjust the plot size of my layouts using Dynamo + Python. There seems to be lots of different code available for this online but I just can’t get it to work on my file.

This is the current code I’m using

adoc = Application.DocumentManager.MdiActiveDocument
editor = adoc.Editor

with adoc.LockDocument():
    with adoc.Database as db:
        with db.TransactionManager.StartTransaction() as t:
            pageSize  = "ANSI_B_(11.00_x_17.00_Inches)"
            styleSheet = "monochrome.ctb"
            device = "DWF6 ePlot.pc3"
            name = "FinalLayout"
            lm = LayoutManager.Current
            id = lm.GetLayoutId(name)
            lay = t.GetObject(id, OpenMode.ForWrite)
            with PlotSettings(lay.ModelType) as ps:
                psv = PlotSettingsValidator.Current

                devs = psv.GetPlotDeviceList()

                if (devs.Contains(device)):
                    psv.SetPlotConfigurationName(ps, device, None)

                mns = psv.GetCanonicalMediaNameList(ps)

                if (mns.Contains(pageSize)):
                    psv.SetCanonicalMediaName(ps, pageSize)

                ssl = psv.GetPlotStyleSheetList()

                if (ssl.Contains(styleSheet)):
                    psv.SetCurrentStyleSheet(ps, styleSheet);

                upgraded = False

                if (not lay.IsWriteEnabled):
                    upgraded = True


                if (upgraded):

It runs fine without errors but I’m just not seeing anything happen.

Any advice would be much appreciated!!

You didn’t share the last code
You may have forgotten add line

1 Like

Thanks @hosneyalaa,

Duh… can’t believe I missed that. So this almost fully solves the issue.

The only problem I’m still having is the layout doesn’t update unless I click to a different tab and back again.

Any thoughts?

1 Like

Try editor.Regen()


Amazing, that’s the one. Thank you so much, really appreciate it!!

1 Like