As a test I have:
- Authored a test.mxd with one layer called Localities in a single data frame called Layers
- Authored a test.rlf using View | Reports > Create Report of ArcGIS 10.2.2 for Desktop
- Created a Python AddIn which creates the expected PDF file from the Report (*.rlf).
This is the code which all works to create the PDF report from the Localities features within the current extent:
import arcpy
import pythonaddins
class ReportForExtent(object):
def __init__(self):
self.enabled = True
self.checked = False
def onClick(self):
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd,"Layers")[0]
lyr = arcpy.mapping.ListLayers(mxd,"Localities",df)[0]
arcpy.mapping.ExportReport(lyr,r"C:\temp\test.rlf",r"C:\temp\test.pdf","EXTENT",extent=df.extent)
del mxd
Is there a way to have the Python AddIn not just create the PDF file but also open it in Adobe Acrobat Reader?
Answer
You could use
import os
myfile = r"C:\temp\test.pdf"
os.system("start " + myfile)
Just tested running this chunk of code from Python add-in from ArcMap and it works fine. More discussion on using this is here.
Alternatively, as commented by @JasonScheirer you could use os.startfile
which works even if the pathname has a space in it, and the asker says does exactly what they were hoping.
No comments:
Post a Comment