Error When Running Calculate Value

2242
27
08-31-2016 03:21 PM
ChrisHolmes
Occasional Contributor III

Hello Everyone,

I have a model which runs the calculate value tool:

The code in the tool is:

When the model runs the following errors are displayed:

I'm not sure what the errors are related to. What's strange is that the code does seem to execute: it displays the extent of the site_polygon layer, sets the scale to 1:4000, then creates the JPG file.

Any insights appreciated. Thanks!

Tags (2)
0 Kudos
27 Replies
ChrisHolmes
Occasional Contributor III

Thanks Xander. So with those changes it does seem to change the extent of the dataframe:

Executing: ExportMXD2JPG32 LOC2016-003

Start Time: Thu Sep 01 15:53:39 2016

Running script ExportMXD2JPG32...

Using MXD H:\chris\LOC2016-003\LOC2016-003 - actual_use.mxd

DF extent on startup is: -9047.84819850156 5650698.4605047 -8349.34680149874 5651193.7614953 NaN NaN NaN NaN

DF scale on startup is: 4000.0

extent of lyr: -10106.7650000002 5656720.382 -10069.7270000003 5656763.791 NaN NaN NaN NaN

extent of new_extent: -10106.7650000002 5656720.382 -10069.7270000003 5656763.791 NaN NaN NaN NaN

DF extent after assignment is: -10437.4966985017 5656494.4360047 -9738.99530149886 5656989.7369953 NaN NaN NaN NaN

DF scale after assignment is: 4000.0

Exporting to JPEG: H:\chris\LOC2016-003\LOC2016-003 - actual_use.jpg

Error: PageLayoutObject: Error in executing ExportToJPEG

Completed script ExportMXD2JPG32...

Failed to execute (ExportMXD2JPG32).

Failed at Thu Sep 01 15:54:14 2016 (Elapsed Time: 35.46 seconds)

But this now seems to bring around a new error. Thanks again

0 Kudos
DanPatterson_Retired
MVP Emeritus

Chris...

 H:\chris\LOC2016-003\LOC2016-003 - actual_use.jpg

maybe try locations without '-' and spaces just for a check

H:\chris\x.jpg

might be a good suggestion

XanderBakker
Esri Esteemed Contributor

Another thing you might want to try is to export to another format (like PDF or PNG) to see if this yields the same error.

0 Kudos
ChrisHolmes
Occasional Contributor III

That's a good idea. Thanks Xander.

0 Kudos
ChrisHolmes
Occasional Contributor III

Thanks Dan, I'll give that a try.

0 Kudos
ChrisHolmes
Occasional Contributor III

Well, that worked! Nice clean results and the expected result on the map:

Executing: ExportMXD2JPG32 LOC2016-003

Start Time: Fri Sep 02 08:42:29 2016

Running script ExportMXD2JPG32...

Using MXD H:\chris\LOC2016-003\LOC2016-003 - actual_use.mxd

DF extent on startup is: -9047.84819850156 5650698.4605047 -8349.34680149874 5651193.7614953 NaN NaN NaN NaN

DF scale on startup is: 4000.0

extent of lyr: -10106.7650000002 5656720.382 -10069.7270000003 5656763.791 NaN NaN NaN NaN

extent of new_extent: -10106.7650000002 5656720.382 -10069.7270000003 5656763.791 NaN NaN NaN NaN

DF extent after assignment is: -10437.4966985017 5656494.4360047 -9738.99530149886 5656989.7369953 NaN NaN NaN NaN

DF scale after assignment is: 4000.0

Exporting to JPEG: H:\chris\test.jpg

Completed script ExportMXD2JPG32...

Succeeded at Fri Sep 02 08:43:07 2016 (Elapsed Time: 38.43 seconds)

I always have to remember the whole Modelbuilder doesn’t like spaces! It just needs to become a practice.

A big thanks to both Xander and Dan for all the help.

0 Kudos
ChrisHolmes
Occasional Contributor III

Thanks Dan. Funny how it's easy to miss the tiny things. It didn't fix the errors though. I did find though that by commenting out mxd.save() it executes correctly. Not sure why it doesn't want to save to that location.

0 Kudos
ChrisHolmes
Occasional Contributor III

I thought I would post the final script that created the expected results in the jpg file:

def main():
    import arcpy
    # will overwrite existing jpg
    arcpy.env.overwriteOutput = True

    # read the parameter from the tool
    loc_no = arcpy.GetParameterAsText(0)

    # define the path of the mxd
    mxd_file = r'H:\chris\{0}\{0} - actual_use.mxd'.format(loc_no)
    jpg_file = r'H:\chris\{0}\{0}-actual_use.jpg'.format(loc_no)
    if arcpy.Exists(mxd_file):
        arcpy.AddMessage("Using MXD {0}".format(mxd_file))
        try:
            mxd = arcpy.mapping.MapDocument(mxd_file)
            df = arcpy.mapping.ListDataFrames(mxd)[0]
            arcpy.AddMessage("DF extent on startup is: {0}".format(df.extent))
            arcpy.AddMessage("DF scale on startup is: {0}".format(df.scale))
            lyr = arcpy.mapping.ListLayers(mxd, 'site_polygon', df)[0]
            ext = lyr.getExtent()
            arcpy.AddMessage("extent of lyr: {0}".format(ext))
            new_extent = df.extent
            new_extent.XMin, new_extent.YMin = ext.XMin, ext.YMin
            new_extent.XMax, new_extent.YMax = ext.XMax, ext.YMax
            arcpy.AddMessage("extent of new_extent: {0}".format(new_extent))
            df.extent = new_extent
            df.scale = 4000
            arcpy.AddMessage("DF extent after assignment is: {0}".format(df.extent))
            arcpy.AddMessage("DF scale after assignment is: {0}".format(df.scale))
            arcpy.AddMessage("Exporting to JPEG: {0}".format(jpg_file))
            arcpy.mapping.ExportToJPEG(mxd, jpg_file)
            del mxd
        except Exception as e:
            arcpy.AddError("Error: {0}".format(e))
    else:
        arcpy.AddWarning("MXD {0} not found!".format(mxd_file))

if __name__ == '__main__':
    main()

Something interesting is that while the image exported is what I'm expecting:

Nothing ever changed in the map window from when the mxd opened. I always expected that the extent would change in the map window and then the image would be created based on that:

0 Kudos