ExportToPDF Q

2930
1
04-04-2016 10:40 AM
CCWeedcontrol
Occasional Contributor III

My fellow mappers split taxparcel and part of the splitting process they have to include a pdf or jpg of the split with the new split/adjusted parcel, example attached (Split(2).png) . I am trying automate the process to make it easier for them as it currently take multiple steps to create this split print out. They currently have driven data pages set up but they don't need the layout of the driven pages they need just a basic exported map like the one i have attached with a few items, like the north arrow and scale bar and possibly initials of the mapper , as example attached (Split(2).png) . I have currently looked through arcpy.mapping.ListLayoutElements but i am not sure if arcpy can create new features like the north arrow, scale bar and text. If so how?

The current code creates a pdf of the selected parcel. I noticed that if i add "df" to the {data_frame} in arcpy.mapping.ListLayoutElements it exports the like the following attached Split_df.png. If a file, export map and chose pdf, it looks alot better then using arcpy.mapping.ExportToPDF, why is this?

if i removed the "df". it will defult to PAGE_LAYOUT.

code

import arcpy, os

import arcpy.mapping
from arcpy import env

# Set workspace
arcpy.env.workspace = "C:/Temp"
arcpy.env.overwriteOutput = 'True'
env.qualifiedFieldNames = False

directory="C:/Temp/Split.pdf"
if os.path.exists(directory):
    try:
        os.remove(directory)
    except:
        print "Exception: ",str(sys.exc_info())
else:
    print 'File not found at ',directory

#deletes the geodatabase prior if it exists
try:
    if arcpy.Exists("C:/temp/NewFeatures.shp"):
        arcpy.Delete_management("C:/temp/NewFeatures.shp")
except:
    pass    


mxd = arcpy.mapping.MapDocument("current")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
lyr = arcpy.mapping.ListLayers(mxd, "DSD.DBO.TaxParcels")[0]


if int(arcpy.GetCount_management("TaxParcels").getOutput(0)) > 0:
   
    arcpy.FeatureClassToFeatureClass_conversion("TaxParcels", "C:/temp", "NewFeatures.shp")

#Adding Labels
layer = arcpy.mapping.ListLayers(mxd, "NewFeatures")[0] 
if layer.supports("LABELCLASSES"):
    for lblclass in layer.labelClasses:
        lblclass.className = "DXF_TEXT" 
        lblclass.expression = '"%s" & [DXF_TEXT] & VBNewLine & "AC" & " " & Round([ACRES],2)& "%s"' % ("<BOL><CLR red='140'><FNT size='12'>" , "</FNT></CLR></BOL>") #WORKS!
    lblclass.showClassLabels = True
layer.showLabels = True
df.extent = lyr.getSelectedExtent()
df.scale = 10000
arcpy.RefreshActiveView()

arcpy.mapping.ExportToPDF(mxd,"C:/Temp/Split.pdf",df)
0 Kudos
1 Reply
DanPatterson_Retired
MVP Emeritus

it is specific in the help ExportToPDF—Help | ArcGIS for Desktop

one way exports the dataframe and the other the layout. .... so with what looks best or what is needed

data_frame

A variable that references a DataFrame object. Use the string/constant "PAGE_LAYOUT" to export the map document's page layout instead of an individual data frame.

(The default value is PAGE_LAYOUT)