<?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 Help w/ MakeFeatureLayer and Assertion Error in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/help-w-makefeaturelayer-and-assertion-error/m-p/117024#M9194</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm trying to write a script that compiles all of the stuff I do to a geodatabase on a weekly basis. This includes:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1. Backing up the geodatabase&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2. Renaming the backed up geodatabase to include a time/date stamp&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3. Compacting the original geodatabase&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;4. Remove legacy accuracy data if data has been updated&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;5. Add/update XY coordinates for all point feature classes&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;6. Performing an attribute selection and then running the frequency tool on the selection to detect duplicate entries&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;7. Add the outputs from the frequency tool to an existing map document and join the tables to the appropriate feature classes&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm good through step 5 but I keep getting stuck on step 6 because of the need to make feature layers in order to do an attribute selection. I'm getting an AssertionError.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Anyway, here's what I have:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;#TASK 4 - Access map document, make feature layers from all feature
#classes, perform selection, copy features to new fcs, run frequency
#tool on new fcs, add feature layers and frequency tables to map
#document, join frequency tables to feature layers

#Set variables

mxd = arcpy.mapping.MapDocument("S:\\GIS\\gis_work\\2014\\FLAG\\ArchGDB_Maint_Model\\GIS\\Script_Test\\Admin_Map2.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
lyrList = arcpy.mapping.ListLayers(mxd, "*", df)

try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for lyr in lyrList:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Execute make feature layer for each feature class in map document
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; flyrList = arcpy.MakeFeatureLayer_management(lyr, "z"+str(lyr))

except arcpy.ExecuteError:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print arcpy.GetMessages()

try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for flyr in flyrList:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Execute select sites only
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(flyr, "NEW_SELECTION", ' "SUBTYPE" = 1 ')

except arcpy.ExecuteError:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print arcpy.GetMessages()

#Set variable
addLayer = arcpy.mapping.ListLayers(mxd, "*z*", df)
arcpy.env.workspace = r'S:\GIS\gis_work\2014\FLAG\ArchGDB_Maint_Model\GIS\Script_Test'

try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for flyr in flyrList:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Execute create new layer files from site selections
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SaveToLayerFile_management(flyr, flyr+"SITES")

except arcpy.ExecuteError:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print arcpy.GetMessages()

try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for flyr in flyrList:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Execute frequency tool on new site only fcs based on ASMIS ID field
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; freqtabList = arcpy.Frequency_analysis(flyr, str(flyr)+"_freq", "ASMIS_ID")

except arcpy.ExecuteError:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print arcpy.GetMessages()

try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for flyr in flyrList:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Add feature layers to map document
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.AddLayer(df, addLayer, "BOTTOM")

except arcpy.ExecuteError:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print arcpy.GetMessages()

try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for freqtab in freqtabList:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Add frequency tables to map document
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.AddTableView(df, freq)

except arcpy.ExecuteError:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print arcpy.GetMessages()

#TASK 5 - Save map document and remove lock

try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.save()
&amp;nbsp;&amp;nbsp;&amp;nbsp; del mxd

except arcpy.ExecuteError:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print arcpy.GetMessages()
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And here's the error I get:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;Executing: SaveToLayerFile zWUPA_Polygon S:\GIS\gis_work\2014\FLAG\ArchGDB_Maint_Model\GIS\Script_Test\zWUPA_PolygonSITES.lyr # CURRENT
Start Time: Tue Apr 01 11:52:53 2014
Failed to execute. Parameters are not valid.
ERROR 000732: Input Layer: Dataset zWUPA_Polygon does not exist or is not supported
Failed to execute (SaveToLayerFile).
Failed at Tue Apr 01 11:52:53 2014 (Elapsed Time: 0.01 seconds)
Executing: Frequency zWUPA_Polygon S:\GIS\gis_work\2014\FLAG\ArchGDB_Maint_Model\GIS\Script_Test\zWUPA_Polygon_freq ASMIS_ID #
Start Time: Tue Apr 01 11:52:54 2014
Failed to execute. Parameters are not valid.
ERROR 000732: Input Table: Dataset zWUPA_Polygon does not exist or is not supported
Failed to execute (Frequency).
Failed at Tue Apr 01 11:52:54 2014 (Elapsed Time: 0.10 seconds)

Traceback (most recent call last):
&amp;nbsp; File "S:\GIS\gis_work\2014\FLAG\ArchGDB_Maint_Model\Documents\ArchGDB_maintenance_tasks.py", line 173, in &amp;lt;module&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.AddLayer(df, addLayer, "BOTTOM")
&amp;nbsp; File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\utils.py", line 181, in fn_
&amp;nbsp;&amp;nbsp;&amp;nbsp; return fn(*args, **kw)
&amp;nbsp; File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\mapping.py", line 49, in AddLayer
&amp;nbsp;&amp;nbsp;&amp;nbsp; assert isinstance(add_layer, Layer)
AssertionError&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help would be greatly appreciated.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Kerry&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 01 Apr 2014 17:56:56 GMT</pubDate>
    <dc:creator>kg76</dc:creator>
    <dc:date>2014-04-01T17:56:56Z</dc:date>
    <item>
      <title>Help w/ MakeFeatureLayer and Assertion Error</title>
      <link>https://community.esri.com/t5/python-questions/help-w-makefeaturelayer-and-assertion-error/m-p/117024#M9194</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm trying to write a script that compiles all of the stuff I do to a geodatabase on a weekly basis. This includes:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1. Backing up the geodatabase&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2. Renaming the backed up geodatabase to include a time/date stamp&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3. Compacting the original geodatabase&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;4. Remove legacy accuracy data if data has been updated&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;5. Add/update XY coordinates for all point feature classes&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;6. Performing an attribute selection and then running the frequency tool on the selection to detect duplicate entries&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;7. Add the outputs from the frequency tool to an existing map document and join the tables to the appropriate feature classes&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm good through step 5 but I keep getting stuck on step 6 because of the need to make feature layers in order to do an attribute selection. I'm getting an AssertionError.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Anyway, here's what I have:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;#TASK 4 - Access map document, make feature layers from all feature
#classes, perform selection, copy features to new fcs, run frequency
#tool on new fcs, add feature layers and frequency tables to map
#document, join frequency tables to feature layers

#Set variables

mxd = arcpy.mapping.MapDocument("S:\\GIS\\gis_work\\2014\\FLAG\\ArchGDB_Maint_Model\\GIS\\Script_Test\\Admin_Map2.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
lyrList = arcpy.mapping.ListLayers(mxd, "*", df)

try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for lyr in lyrList:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Execute make feature layer for each feature class in map document
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; flyrList = arcpy.MakeFeatureLayer_management(lyr, "z"+str(lyr))

except arcpy.ExecuteError:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print arcpy.GetMessages()

try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for flyr in flyrList:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Execute select sites only
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(flyr, "NEW_SELECTION", ' "SUBTYPE" = 1 ')

except arcpy.ExecuteError:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print arcpy.GetMessages()

#Set variable
addLayer = arcpy.mapping.ListLayers(mxd, "*z*", df)
arcpy.env.workspace = r'S:\GIS\gis_work\2014\FLAG\ArchGDB_Maint_Model\GIS\Script_Test'

try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for flyr in flyrList:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Execute create new layer files from site selections
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SaveToLayerFile_management(flyr, flyr+"SITES")

except arcpy.ExecuteError:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print arcpy.GetMessages()

try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for flyr in flyrList:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Execute frequency tool on new site only fcs based on ASMIS ID field
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; freqtabList = arcpy.Frequency_analysis(flyr, str(flyr)+"_freq", "ASMIS_ID")

except arcpy.ExecuteError:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print arcpy.GetMessages()

try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for flyr in flyrList:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Add feature layers to map document
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.AddLayer(df, addLayer, "BOTTOM")

except arcpy.ExecuteError:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print arcpy.GetMessages()

try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for freqtab in freqtabList:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Add frequency tables to map document
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.AddTableView(df, freq)

except arcpy.ExecuteError:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print arcpy.GetMessages()

#TASK 5 - Save map document and remove lock

try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.save()
&amp;nbsp;&amp;nbsp;&amp;nbsp; del mxd

except arcpy.ExecuteError:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print arcpy.GetMessages()
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And here's the error I get:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;Executing: SaveToLayerFile zWUPA_Polygon S:\GIS\gis_work\2014\FLAG\ArchGDB_Maint_Model\GIS\Script_Test\zWUPA_PolygonSITES.lyr # CURRENT
Start Time: Tue Apr 01 11:52:53 2014
Failed to execute. Parameters are not valid.
ERROR 000732: Input Layer: Dataset zWUPA_Polygon does not exist or is not supported
Failed to execute (SaveToLayerFile).
Failed at Tue Apr 01 11:52:53 2014 (Elapsed Time: 0.01 seconds)
Executing: Frequency zWUPA_Polygon S:\GIS\gis_work\2014\FLAG\ArchGDB_Maint_Model\GIS\Script_Test\zWUPA_Polygon_freq ASMIS_ID #
Start Time: Tue Apr 01 11:52:54 2014
Failed to execute. Parameters are not valid.
ERROR 000732: Input Table: Dataset zWUPA_Polygon does not exist or is not supported
Failed to execute (Frequency).
Failed at Tue Apr 01 11:52:54 2014 (Elapsed Time: 0.10 seconds)

Traceback (most recent call last):
&amp;nbsp; File "S:\GIS\gis_work\2014\FLAG\ArchGDB_Maint_Model\Documents\ArchGDB_maintenance_tasks.py", line 173, in &amp;lt;module&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.AddLayer(df, addLayer, "BOTTOM")
&amp;nbsp; File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\utils.py", line 181, in fn_
&amp;nbsp;&amp;nbsp;&amp;nbsp; return fn(*args, **kw)
&amp;nbsp; File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\mapping.py", line 49, in AddLayer
&amp;nbsp;&amp;nbsp;&amp;nbsp; assert isinstance(add_layer, Layer)
AssertionError&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help would be greatly appreciated.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Kerry&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Apr 2014 17:56:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/help-w-makefeaturelayer-and-assertion-error/m-p/117024#M9194</guid>
      <dc:creator>kg76</dc:creator>
      <dc:date>2014-04-01T17:56:56Z</dc:date>
    </item>
    <item>
      <title>Re: Help w/ MakeFeatureLayer and Assertion Error</title>
      <link>https://community.esri.com/t5/python-questions/help-w-makefeaturelayer-and-assertion-error/m-p/117025#M9195</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You are attempting to add the addLayer variable which is a list of layers. And you are iterating over a single layer of your flyrList variable. I think you are getting your variable names confused.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Apr 2014 18:57:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/help-w-makefeaturelayer-and-assertion-error/m-p/117025#M9195</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2014-04-01T18:57:27Z</dc:date>
    </item>
  </channel>
</rss>

