i am having some issues running a simple python script alongside my data driven pages map. I am trying to clip out some roads and selected names from the outside of my layer scope i have written the code down below could anyone help me with this the lines in question is highlighted in bold. still new to python if someone can help that would be great. thanks
import arcpy
# Set overwrite option
arcpy.env.overwriteOutput = True
mxd = arcpy.mapping.MapDocument(r"W:\Information Technology\GIS\Projects\Wildlife\BigGame\PermitMaps\BigGameUnitsDDP_ElkLandscape.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
for lyr in arcpy.mapping.ListLayers(mxd, "City*", df):
if lyr.name == "City Points (2010)":
city_lyr = lyr
for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
mxd.dataDrivenPages.currentPageID = pageNum
pageRow = mxd.dataDrivenPages.pageRow
pageName = mxd.dataDrivenPages.pageNameField.name
DDP_PageName = pageRow.getValue(pageName)
for lyr in arcpy.mapping.ListLayers(mxd, "Elk*", df):
if lyr.name == "ElkUnitsSDE - match":
unit_lyr = lyr
arcpy.SelectLayerByAttribute_management(unit_lyr, 'NEW_SELECTION', '1=1')
if lyr.name == "ElkUnitsBoundaryRds":
unit_boundary_lyr = lyr
unit_boundary_lyr.definitionQuery = "Units Like " + "'%" + DDP_PageName + "%'"
print city_lyr.name
print unit_lyr.name
arcpy.SelectLayerByLocation_management(city_lyr, 'INTERSECT', unit_lyr, '1 Mile', 'NEW_SELECTION', 'NOT_INVERT')
selcount = int(arcpy.GetCount_management(city_lyr)[0])
print selcount
if selcount == 0:
print ('No city points selected')
else:
arcpy.CopyFeatures_management(city_lyr, r"W:\Information Technology\GIS\Projects\Wildlife\BigGame\PermitMaps\Python\BigGameUnits.gdb\Cities_Sel")
city_lyr.replaceDataSource(r'W:\Information Technology\GIS\Projects\Wildlife\BigGame\PermitMaps\Python\BigGameUnits.gdb', 'FILEGDB_WORKSPACE', 'Cities_Sel')
for lyr in arcpy.mapping.ListLayers(mxd, '*', df):
arcpy.SelectLayerByAttribute_management(lyr, "CLEAR_SELECTION")
print "Exporting page {0} of {1}".format(str(mxd.dataDrivenPages.currentPageID), str(mxd.dataDrivenPages.pageCount))
arcpy.mapping.ExportToPDF(mxd, r"W:\Information Technology\GIS\Projects\Wildlife\BigGame\PermitMaps\2019 Permit Maps\Elk" + "_" + str(DDP_PageName) + ".pdf", resolution=150, georef_info="false", jpeg_compression_quality=75, image_quality="NORMAL")
city_lyr.replaceDataSource(r'Database Connections\GIS_WEB.sde', 'SDE_WORKSPACE', 'GIS_WEB.SDE.CityPoints')
del mxd, df, city_lyr, unit_lyr, unit_boundary_lyr
Hi Devarsi Majumder,
Two questions:
Thanks in advance,
Egge-Jan
where do i change under the three dots not sure where you are saying to change it also the error message that i get is saying that my city.lyr is not defined when i have it clearly defined above thanks
About marking the syntax highlighting:
i marked the lines that are in question in bold. it says im missing parentheses syntax is wrong.
In your script editor, what line is causing the error?
Syntax highlighting won't help if there is an error in the code. Post the error message
Is this in ArcGIS Pro and for python 3?
If so, print statements now go in brackets
print "hello" # old 2.7
print("hello") # new python 3.*
the issues that i am having is that it i ssaying that my city.lyr is not defined when we have defined from waht feature class to use also
Code formatting will also provide line numbers
i see where your saying for code formatting but it say s that my print syntax is wrong due to missing parthenses. is there a way you can help with this?