<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: needing some help  with python code lyr not defined in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/needing-some-help-with-python-code-lyr-not-defined/m-p/516001#M40501</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;i marked the&amp;nbsp; lines that are in question in bold. it says im missing parentheses syntax is wrong. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 30 Apr 2019 20:34:36 GMT</pubDate>
    <dc:creator>Anonymous User</dc:creator>
    <dc:date>2019-04-30T20:34:36Z</dc:date>
    <item>
      <title>needing some help  with python code lyr not defined</title>
      <link>https://community.esri.com/t5/python-questions/needing-some-help-with-python-code-lyr-not-defined/m-p/515994#M40494</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;i am having some issues&amp;nbsp; running&amp;nbsp; a simple&amp;nbsp; python script&amp;nbsp;&amp;nbsp; alongside my data&amp;nbsp; driven pages map. I am trying to&amp;nbsp; clip out&amp;nbsp; some roads and selected&amp;nbsp; names from the outside of my layer scope i have written the code down below could anyone help me with this&amp;nbsp;&amp;nbsp;&amp;nbsp; the&amp;nbsp;&amp;nbsp; lines in question&amp;nbsp; is&amp;nbsp; highlighted in bold.&amp;nbsp;&amp;nbsp;&amp;nbsp; still new to python&amp;nbsp; if someone can help&amp;nbsp; that would be great. thanks&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# Set overwrite option&lt;BR /&gt;arcpy.env.overwriteOutput = True&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;mxd = arcpy.mapping.MapDocument(r"W:\Information Technology\GIS\Projects\Wildlife\BigGame\PermitMaps\BigGameUnitsDDP_ElkLandscape.mxd")&lt;BR /&gt;df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]&lt;BR /&gt;for lyr in arcpy.mapping.ListLayers(mxd, "City*", df):&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.name == "City Points (2010)":&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; city_lyr = lyr&lt;BR /&gt;for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.dataDrivenPages.currentPageID = pageNum&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; pageRow = mxd.dataDrivenPages.pageRow&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; pageName = mxd.dataDrivenPages.pageNameField.name&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DDP_PageName = pageRow.getValue(pageName)&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for lyr in arcpy.mapping.ListLayers(mxd, "Elk*", df):&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.name == "ElkUnitsSDE - match":&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; unit_lyr = lyr&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(unit_lyr, 'NEW_SELECTION', '1=1')&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.name == "ElkUnitsBoundaryRds":&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; unit_boundary_lyr = lyr&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; unit_boundary_lyr.definitionQuery = "Units Like " + "'%" + DDP_PageName + "%'"&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;&amp;nbsp; print city_lyr.name&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print unit_lyr.name&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByLocation_management(city_lyr, 'INTERSECT', unit_lyr, '1 Mile', 'NEW_SELECTION', 'NOT_INVERT')&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; selcount = int(arcpy.GetCount_management(city_lyr)[0])&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print selcount&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if selcount == 0:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print ('No city points selected')&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CopyFeatures_management(city_lyr, r"W:\Information Technology\GIS\Projects\Wildlife\BigGame\PermitMaps\Python\BigGameUnits.gdb\Cities_Sel")&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; city_lyr.replaceDataSource(r'W:\Information Technology\GIS\Projects\Wildlife\BigGame\PermitMaps\Python\BigGameUnits.gdb', 'FILEGDB_WORKSPACE', 'Cities_Sel')&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for lyr in arcpy.mapping.ListLayers(mxd, '*', df):&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(lyr, "CLEAR_SELECTION")&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Exporting page {0} of {1}".format(str(mxd.dataDrivenPages.currentPageID), str(mxd.dataDrivenPages.pageCount))&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 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")&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; city_lyr.replaceDataSource(r'Database Connections\GIS_WEB.sde', 'SDE_WORKSPACE', 'GIS_WEB.SDE.CityPoints')&lt;BR /&gt;del mxd, df, city_lyr, unit_lyr, unit_boundary_lyr&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Apr 2019 19:57:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/needing-some-help-with-python-code-lyr-not-defined/m-p/515994#M40494</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2019-04-30T19:57:56Z</dc:date>
    </item>
    <item>
      <title>Re: needing some help  with python code</title>
      <link>https://community.esri.com/t5/python-questions/needing-some-help-with-python-code-lyr-not-defined/m-p/515995#M40495</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi &lt;A href="https://community.esri.com/migrated-users/357597"&gt;Devarsi Majumder&lt;/A&gt;‌,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Two questions:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;You indicate that you are having 'some issues' with the Python script above, and you ask for help. Can you please indicate what the issues are? What error messages do you get? We might be able to help if you indicate where things go wrong...&lt;/LI&gt;&lt;LI&gt;Can you please modify the question to mark your script as Python code (there is an option to do so under the three dots), as this will provide syntax highlighting and render the script more readable.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Egge-Jan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Apr 2019 20:11:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/needing-some-help-with-python-code-lyr-not-defined/m-p/515995#M40495</guid>
      <dc:creator>Egge-Jan_Pollé</dc:creator>
      <dc:date>2019-04-30T20:11:57Z</dc:date>
    </item>
    <item>
      <title>Re: needing some help  with python code</title>
      <link>https://community.esri.com/t5/python-questions/needing-some-help-with-python-code-lyr-not-defined/m-p/515996#M40496</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;the issues that&amp;nbsp; i am having is that it i ssaying that my&amp;nbsp; city.lyr is not defined&amp;nbsp; when&amp;nbsp; we have&amp;nbsp; defined&amp;nbsp; from waht&amp;nbsp; feature class to use also&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Apr 2019 20:14:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/needing-some-help-with-python-code-lyr-not-defined/m-p/515996#M40496</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2019-04-30T20:14:22Z</dc:date>
    </item>
    <item>
      <title>Re: needing some help  with python code</title>
      <link>https://community.esri.com/t5/python-questions/needing-some-help-with-python-code-lyr-not-defined/m-p/515997#M40497</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;where do i change&amp;nbsp; under the three dots&amp;nbsp; not sure where you are saying to change it also&amp;nbsp; the&amp;nbsp;&amp;nbsp; error message that i get is&amp;nbsp; saying that&amp;nbsp; my&amp;nbsp; city.lyr is not defined&amp;nbsp; when i have&amp;nbsp; it clearly defined above&amp;nbsp; thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Apr 2019 20:16:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/needing-some-help-with-python-code-lyr-not-defined/m-p/515997#M40497</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2019-04-30T20:16:20Z</dc:date>
    </item>
    <item>
      <title>Re: needing some help  with python code lyr not defined</title>
      <link>https://community.esri.com/t5/python-questions/needing-some-help-with-python-code-lyr-not-defined/m-p/515998#M40498</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Code formatting will also provide line numbers&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/blogs/dan_patterson/2016/08/14/script-formatting"&gt;/blogs/dan_patterson/2016/08/14/script-formatting&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Apr 2019 20:27:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/needing-some-help-with-python-code-lyr-not-defined/m-p/515998#M40498</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2019-04-30T20:27:41Z</dc:date>
    </item>
    <item>
      <title>Re: needing some help  with python code lyr not defined</title>
      <link>https://community.esri.com/t5/python-questions/needing-some-help-with-python-code-lyr-not-defined/m-p/515999#M40499</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;About marking the syntax highlighting:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;edit your answer and select the python code&lt;/LI&gt;&lt;LI&gt;use the option below to mark the syntax - sorry, my UI is in Dutch. in English it will read something like 'Mark syntax', I suppose.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;IMG class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/445361_pastedImage_1.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Apr 2019 20:29:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/needing-some-help-with-python-code-lyr-not-defined/m-p/515999#M40499</guid>
      <dc:creator>Egge-Jan_Pollé</dc:creator>
      <dc:date>2019-04-30T20:29:57Z</dc:date>
    </item>
    <item>
      <title>Re: needing some help  with python code lyr not defined</title>
      <link>https://community.esri.com/t5/python-questions/needing-some-help-with-python-code-lyr-not-defined/m-p/516000#M40500</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;i see&amp;nbsp;&amp;nbsp; where your saying&amp;nbsp; for&amp;nbsp; code formatting but&amp;nbsp; it say s that my print syntax is wrong due to missing parthenses.&amp;nbsp; is there a way you can help with this?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Apr 2019 20:34:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/needing-some-help-with-python-code-lyr-not-defined/m-p/516000#M40500</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2019-04-30T20:34:11Z</dc:date>
    </item>
    <item>
      <title>Re: needing some help  with python code lyr not defined</title>
      <link>https://community.esri.com/t5/python-questions/needing-some-help-with-python-code-lyr-not-defined/m-p/516001#M40501</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;i marked the&amp;nbsp; lines that are in question in bold. it says im missing parentheses syntax is wrong. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Apr 2019 20:34:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/needing-some-help-with-python-code-lyr-not-defined/m-p/516001#M40501</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2019-04-30T20:34:36Z</dc:date>
    </item>
    <item>
      <title>Re: needing some help  with python code lyr not defined</title>
      <link>https://community.esri.com/t5/python-questions/needing-some-help-with-python-code-lyr-not-defined/m-p/516002#M40502</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In your script editor, what line is causing the error? &amp;nbsp;&lt;/P&gt;&lt;P&gt;Syntax highlighting won't help if there is an error in the code.&amp;nbsp; Post the error message&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Apr 2019 20:39:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/needing-some-help-with-python-code-lyr-not-defined/m-p/516002#M40502</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2019-04-30T20:39:12Z</dc:date>
    </item>
    <item>
      <title>Re: needing some help  with python code lyr not defined</title>
      <link>https://community.esri.com/t5/python-questions/needing-some-help-with-python-code-lyr-not-defined/m-p/516003#M40503</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;when it says "City_Lyr is not defined", what this means is, you have not yet "defined" your city layer &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/grin.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is because in this line of code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;for lyr in arcpy.mapping.ListLayers(mxd, "City*", df):&lt;/SPAN&gt;&lt;BR style="background-color: #ffffff;" /&gt;&lt;SPAN style="background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.name == "City Points (2010)":&lt;/SPAN&gt;&lt;BR style="background-color: #ffffff;" /&gt;&lt;SPAN style="background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; city_lyr = lyr&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;it never actually gets to run the line of code:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;&lt;SPAN&gt;&amp;nbsp;city_lyr = lyr&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;&lt;SPAN&gt;Which is where you try to define it. The reason for that, I am not so sure, but the "If" statement is somehow not letting any of your layers get defined as the city lyr.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;&lt;SPAN&gt;Same issue regarding your other layer.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 01 May 2019 14:01:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/needing-some-help-with-python-code-lyr-not-defined/m-p/516003#M40503</guid>
      <dc:creator>LukeWebb</dc:creator>
      <dc:date>2019-05-01T14:01:43Z</dc:date>
    </item>
    <item>
      <title>Re: needing some help  with python code lyr not defined</title>
      <link>https://community.esri.com/t5/python-questions/needing-some-help-with-python-code-lyr-not-defined/m-p/516004#M40504</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is this in ArcGIS Pro and for python 3?&lt;/P&gt;&lt;P&gt;If so, print statements now go in brackets&lt;/P&gt;&lt;P&gt;print "hello"&amp;nbsp; # old 2.7&lt;/P&gt;&lt;P&gt;print("hello") # new python 3.*&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 May 2019 08:47:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/needing-some-help-with-python-code-lyr-not-defined/m-p/516004#M40504</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2019-05-17T08:47:10Z</dc:date>
    </item>
  </channel>
</rss>

