<?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: Add Layer Assertion Error in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/add-layer-assertion-error/m-p/234669#M18192</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Perfect! It worked. Thanks a lot!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have another question, however. Whenever I start this script, I use GetParameterAsText(0) to specify a Workspace, but also the feature dataset where files are to be stored.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;However, later in the script, when I re-add these files, the script automatically opens files from my Deafult Geodatabase (the one on my C drive that I never use). This isn't a problem when I go into the Environment Settings and specify my Current and Scratch Workspaces.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is there anyway to set the feature dataset specified in GetParameterAsText(0) as my Current and Scratch Workspace? Not a huge deal, but it would save a step.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 29 Apr 2013 14:14:55 GMT</pubDate>
    <dc:creator>ZackBartlett</dc:creator>
    <dc:date>2013-04-29T14:14:55Z</dc:date>
    <item>
      <title>Add Layer Assertion Error</title>
      <link>https://community.esri.com/t5/python-questions/add-layer-assertion-error/m-p/234667#M18190</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a script that:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1. Reads the layers in my Table of Contents &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2. exports them to a feature dataset&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3. re-adds the exported features&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;4. applies a pre-determined symbology to them based on layer files.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've managed to complete steps 1 and 2, however, I am getting hung up with an Assertion Error at step 3.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My code is below. The error is arising in Section 3: RE-ADD NEWLY EXPORTED BASE FEATURES.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# SET UP

import arcpy, glob, os

base_features_Output = arcpy.GetParameter(0)

arcpy.env.Workspace = base_features_Output
arcpy.env.OverwriteOutput = True

arcpy.AddMessage("Workspace: " + str(arcpy.env.Workspace))

df_Target = arcpy.GetParameterAsText(1)

mxd = arcpy.mapping.MapDocument("CURRENT")
dataFrame = arcpy.mapping.ListDataFrames(mxd, df_Target)[0]
layerfile_list = r"N:\BASE_DATA\CANVEC\1_to_50k\lyrfiles"

# 1. LIST FEATURE CLASSES IN TABLE OF CONTENTS

TOC_shp_list = arcpy.mapping.ListLayers(mxd, "", dataFrame)

# 2. EXPORT TOC FEATURES TO GEODATABASE

arcpy.AddMessage("Exporting base features to geodatabase...")

for shp in TOC_shp_list:
&amp;nbsp;&amp;nbsp;&amp;nbsp; shp_ext = shp.name[7:]
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(str(shp_ext))
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.FeatureClassToFeatureClass_conversion(shp,base_features_Output,str(shp_ext))
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(str(shp) + " ---- EXPORTED")
&amp;nbsp;&amp;nbsp;&amp;nbsp; del shp_ext
arcpy.AddMessage("All base features exported to geodatabase.")

del shp
del TOC_shp_list

# 3. RE-ADD NEWLY EXPORTED BASE FEATURES

arcpy.AddMessage("Re-adding newly exported layers...")

FC_shp_list = arcpy.ListFeatureClasses()

for FC_shp in FC_shp_list:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(FC_shp)
&amp;nbsp;&amp;nbsp;&amp;nbsp; new_shplyr = arcpy.mapping.Layer(str(base_features_Output) + "\\" + str(FC_shp))
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(str(new_shplyr))
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.AddLayer(df_Target, new_shplyr, "TOP")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
arcpy.RefreshActiveView()
arcpy.RefreshTOC()

# 4. APPLY SYMBOLOGY

TOC_shp_list = arcpy.mapping.ListLayers(mxd, "", dataFrame)

for shp in TOC_shp_list:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for lyr in layerfile_list:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr == shp:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.ApplySymbologyFromLayer_management(shp, lyr)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del lyr
&amp;nbsp;&amp;nbsp;&amp;nbsp; del shp

arcpy.RefreshTOC()
arcpy.RefreshActiveView()&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;ArcMap is giving me the following error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Executing: ExpSymCanvec N:\BASE_DATA\CANVEC\Test.gdb\Base Layers&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Start Time: Fri Apr 26 14:38:09 2013&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Running script ExpSymCanvec...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Workspace: N:\BASE_DATA\CANVEC\Test.gdb\Base&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Exporting base features to geodatabase...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;TR_1760009_1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;031g05_TR_1760009_1 ---- EXPORTED&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;All base features exported to geodatabase.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Re-adding newly exported layers...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;TR_1760009_1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;TR_1760009_1&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; File "N:\DOCUMENTATION\PYTHON\Canvec_Symbolization\canvec_autosym_basedatatool.py", line 59, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; arcpy.mapping.AddLayer(df_Target, new_shplyr, "TOP")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\utils.py", line 181, in fn_&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; return fn(*args, **kw)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\mapping.py", line 48, in AddLayer&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; assert isinstance(data_frame, DataFrame)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;AssertionError&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed to execute (ExpSymCanvec).&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed at Fri Apr 26 14:38:25 2013 (Elapsed Time: 16.00 seconds)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Does anyone have any idea what's going on here? Any help would be appreciated.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 16:13:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-layer-assertion-error/m-p/234667#M18190</guid>
      <dc:creator>ZackBartlett</dc:creator>
      <dc:date>2021-12-12T16:13:24Z</dc:date>
    </item>
    <item>
      <title>Re: Add Layer Assertion Error</title>
      <link>https://community.esri.com/t5/python-questions/add-layer-assertion-error/m-p/234668#M18191</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The first argument for arcpy.mapping.AddLayer has to be a DataFrame instance, but you are passing it a string, the name of the dataframe.&amp;nbsp; You've already hooked to the DataFrame instance in your code, so just change this line:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;arcpy.mapping.AddLayer(df_Target, new_shplyr, "TOP")&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;to this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;arcpy.mapping.AddLayer(dataFrame, new_shplyr, "TOP")&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I think that will fix you up.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;good luck&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 28 Apr 2013 21:32:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-layer-assertion-error/m-p/234668#M18191</guid>
      <dc:creator>MikeHunter</dc:creator>
      <dc:date>2013-04-28T21:32:05Z</dc:date>
    </item>
    <item>
      <title>Re: Add Layer Assertion Error</title>
      <link>https://community.esri.com/t5/python-questions/add-layer-assertion-error/m-p/234669#M18192</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Perfect! It worked. Thanks a lot!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have another question, however. Whenever I start this script, I use GetParameterAsText(0) to specify a Workspace, but also the feature dataset where files are to be stored.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;However, later in the script, when I re-add these files, the script automatically opens files from my Deafult Geodatabase (the one on my C drive that I never use). This isn't a problem when I go into the Environment Settings and specify my Current and Scratch Workspaces.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is there anyway to set the feature dataset specified in GetParameterAsText(0) as my Current and Scratch Workspace? Not a huge deal, but it would save a step.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Apr 2013 14:14:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-layer-assertion-error/m-p/234669#M18192</guid>
      <dc:creator>ZackBartlett</dc:creator>
      <dc:date>2013-04-29T14:14:55Z</dc:date>
    </item>
  </channel>
</rss>

