|
POST
|
Hello Everyone, I am working on a model where the first step is a small script that uses os.startfile to open an mxd file. The script takes less than a second to run but it can take around 20 seconds for the mxd file to fully open. Is there something that I can do to prevent the next step of the model from running until the mxd is fully open rather than right after the script completes? Thanks all, Chris
... View more
09-02-2016
10:09 AM
|
0
|
2
|
2516
|
|
POST
|
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:
... View more
09-02-2016
08:11 AM
|
0
|
0
|
1538
|
|
POST
|
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.
... View more
09-02-2016
07:50 AM
|
0
|
0
|
1538
|
|
POST
|
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
... View more
09-01-2016
02:57 PM
|
0
|
5
|
1538
|
|
POST
|
It seems to have dealt with the error. But the data frame extents still do not seem to take the value of new_extent. Thank you Dan
... View more
09-01-2016
02:40 PM
|
0
|
0
|
2062
|
|
POST
|
Thanks Dan. That seems to have fixed the error. The results now display as: Executing: ExportMXD2JPG3 LOC2016-003 Start Time: Thu Sep 01 14:35:03 2016 Running script ExportMXD2JPG3... 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: -9047.84819850156 5650698.4605047 -8349.34680149874 5651193.7614953 NaN NaN NaN NaN DF scale after assignment is: 4000.0 Exporting to JPEG: H:\chris\LOC2016-003\LOC2016-003 - actual_use.jpg Completed script ExportMXD2JPG3... Succeeded at Thu Sep 01 14:35:40 2016 (Elapsed Time: 36.85 seconds) Still seems though that the extents are not changing.
... View more
09-01-2016
01:41 PM
|
0
|
9
|
2062
|
|
POST
|
Thanks Xander. When I run that code, I get the following error message: Executing: ExportMXD2JPG3 LOC2016-003 Start Time: Thu Sep 01 14:21:14 2016 Running script ExportMXD2JPG3... 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 Error: 'DataFrame' object has no attribute 'ext' Completed script ExportMXD2JPG3... Failed to execute (ExportMXD2JPG3). Failed at Thu Sep 01 14:21:32 2016 (Elapsed Time: 17.89 seconds) Thanks for your help, very much appreciated!
... View more
09-01-2016
01:23 PM
|
0
|
11
|
2062
|
|
POST
|
Thanks Xander. Here are the results: Executing: ExportMXD2JPG2 LOC2016-003 Start Time: Thu Sep 01 13:22:29 2016 Running script ExportMXD2JPG2... 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 DF extent after assignment is: -9047.84819850156 5650698.4605047 -8349.34680149874 5651193.7614953 NaN NaN NaN NaN DF scale after assignment is: 4000.0 Exporting to JPEG: H:\chris\LOC2016-003\LOC2016-003 - actual_use.jpg Completed script ExportMXD2JPG2... Succeeded at Thu Sep 01 13:22:59 2016 (Elapsed Time: 29.68 seconds)
... View more
09-01-2016
12:24 PM
|
0
|
13
|
2062
|
|
POST
|
Hi Xander, I'm going to attach a file with a table showing on the left the code in the Calculate Value tool and on the right the code in the python script you sent me (thanks again!). The row below the row with the code shows the jpg file created using both methods. The one for the Calculate Value tool shows the correct image, the one for the python script shows the mxd as it appears when it's opened up (so it doesn't seem to do what's in the code). To me the code in both methods looks the same so I don't know why the code in the python script doesn't seem to run?
... View more
09-01-2016
10:23 AM
|
0
|
15
|
2062
|
|
POST
|
So would the code in the script be the same as what I put in the Calculate Value tool and does the passing the parameter part get handled in properties > parameters when I create the script tool?
... View more
09-01-2016
07:22 AM
|
0
|
18
|
2878
|
|
POST
|
LocNo is just a string value that would be provided by the end user. Thanks
... View more
09-01-2016
07:14 AM
|
0
|
20
|
2878
|
|
POST
|
Actually, that would be my preference. I just haven't figured out yet how to pass a parameter from a model to a script. As you see I need to pass in a parameter LocNo. Can you point me to an example that would help me figure out how to do that? I would still need to make it part of a script tool as this is part of a larger model. Thanks Xander!
... View more
09-01-2016
06:50 AM
|
0
|
22
|
2878
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 11-10-2020 03:34 PM | |
| 1 | 02-23-2021 11:53 AM | |
| 1 | 02-16-2021 09:15 AM | |
| 1 | 12-10-2020 07:46 AM | |
| 1 | 01-18-2019 09:54 AM |
| Online Status |
Offline
|
| Date Last Visited |
04-22-2021
04:31 PM
|