<?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: ValueError with DataFrame in arcpy.mapping.AddLayerToGroup in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/valueerror-with-dataframe-in-arcpy-mapping/m-p/140038#M10917</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The arcpy.env.workspace was set earlier to the path where all of the files are.&amp;nbsp; Because everything else is working fine with regards to the MXD, the dataFrame, and adding layers, it would seem like a mute point even if it wasn't set.&amp;nbsp; This may be because the script is being run in the same directory as where all of the other files exist.&amp;nbsp; I am going to run a test where I read in an MXD that already contains a group layer and then see if I can add a layer to that group layer.&amp;nbsp; My thought is maybe after I initially added that group layer to the dataFrame, maybe I needed to do something like a save or a refresh or something because maybe the AddLayerToGroup didn't see that the group layer was added.&amp;nbsp; That doesn't make sense but who knows.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 02 Aug 2014 13:23:25 GMT</pubDate>
    <dc:creator>PeterLen</dc:creator>
    <dc:date>2014-08-02T13:23:25Z</dc:date>
    <item>
      <title>ValueError with DataFrame in arcpy.mapping.AddLayerToGroup</title>
      <link>https://community.esri.com/t5/python-questions/valueerror-with-dataframe-in-arcpy-mapping/m-p/140034#M10913</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am using ArcGIS 10.1 and am using Python to try to add a layer (.lyr file) to a group layer.&amp;nbsp; What I have is this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;mxd = arcpy.mapping.MapDocument(NEW_MXD)&lt;/P&gt;&lt;P&gt;dataFrame = arcpy.mapping.ListDataFrames(mxd)[0]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# Add group layer&lt;/P&gt;&lt;P&gt;groupLayer = arcpy.mapping.Layer(r"EmptyGroupLayer.lyr")&lt;/P&gt;&lt;P&gt;arcpy.mapping.AddLayer(dataFrame, groupLayer, "TOP")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# Add layer to group layer&lt;/P&gt;&lt;P&gt;tmpLayer = arcpy.mapping.Layer(r"zipcodes.lyr")&lt;/P&gt;&lt;P&gt;arcpy.mapping.AddLayerToGroup(dataFrame, groupLayer, tmpLayer, "BOTTOM")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I verified that the "groupLayer" is a group layer and tmpLayer is not.&amp;nbsp; I get the following error from a stack trace when the AddLayerToGroup is executed:&lt;/P&gt;&lt;P&gt;---------------------------------------------&lt;/P&gt;&lt;P&gt;Error: DataFrameObject: Unexpected error&lt;/P&gt;&lt;P&gt;Traceback (most recent call last):&lt;/P&gt;&lt;P&gt;&amp;nbsp; File "main.py", line 78, in &amp;lt;module&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; main()&lt;/P&gt;&lt;P&gt;&amp;nbsp; File "main.py", line 46, in main&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.AddLayerToGroup(dataFrame, groupLayer, tmpLayer, "BOTTOM")&lt;/P&gt;&lt;P&gt;&amp;nbsp; File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\utils.py", line 18&lt;/P&gt;&lt;P&gt;1, in fn_&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return fn(*args, **kw)&lt;/P&gt;&lt;P&gt;&amp;nbsp; File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\mapping.py", line&lt;/P&gt;&lt;P&gt;93, in AddLayerToGroup&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; data_frame._arc_object.InsertLayer(target_group_layer._arc_object, my_copy,&lt;/P&gt;&lt;P&gt;len(lyrlist)+1)&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #e23d39;"&gt;&lt;STRONG&gt;ValueError: DataFrameObject: Unexpected error&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;---------------------------------------------&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Not sure what I am missing as I feel that I am following the same process as other examples I have seen on the web.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any thoughts on what the value error for the data frame might be?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks - Peter&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 02 Aug 2014 03:09:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/valueerror-with-dataframe-in-arcpy-mapping/m-p/140034#M10913</guid>
      <dc:creator>PeterLen</dc:creator>
      <dc:date>2014-08-02T03:09:10Z</dc:date>
    </item>
    <item>
      <title>Re: ValueError with DataFrame in arcpy.mapping.AddLayerToGroup</title>
      <link>https://community.esri.com/t5/python-questions/valueerror-with-dataframe-in-arcpy-mapping/m-p/140035#M10914</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;where is New_MXD defined?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 02 Aug 2014 03:39:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/valueerror-with-dataframe-in-arcpy-mapping/m-p/140035#M10914</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2014-08-02T03:39:31Z</dc:date>
    </item>
    <item>
      <title>Re: ValueError with DataFrame in arcpy.mapping.AddLayerToGroup</title>
      <link>https://community.esri.com/t5/python-questions/valueerror-with-dataframe-in-arcpy-mapping/m-p/140036#M10915</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The NEW_MXD is just a variable assigned earlier that has the name of an MXD file:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;NEW_MXD = "temp.mxd"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I simply add the tmpLayer via the arcpy.mapping.AddLayer to add it as a layer to the data frame, all is good.&amp;nbsp; Both the group layer and the tmp layer are displayed properly in the MXD.&amp;nbsp; Something is just happening when I try to add the tmpLayer via the AddLayerToGroup.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 02 Aug 2014 12:11:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/valueerror-with-dataframe-in-arcpy-mapping/m-p/140036#M10915</guid>
      <dc:creator>PeterLen</dc:creator>
      <dc:date>2014-08-02T12:11:04Z</dc:date>
    </item>
    <item>
      <title>Re: ValueError with DataFrame in arcpy.mapping.AddLayerToGroup</title>
      <link>https://community.esri.com/t5/python-questions/valueerror-with-dataframe-in-arcpy-mapping/m-p/140037#M10916</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Unless your environments are set, via arcpy, I thought the path to the project needed to be set explicitly as to the folder and filename...could be wrong&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 02 Aug 2014 12:29:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/valueerror-with-dataframe-in-arcpy-mapping/m-p/140037#M10916</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2014-08-02T12:29:44Z</dc:date>
    </item>
    <item>
      <title>Re: ValueError with DataFrame in arcpy.mapping.AddLayerToGroup</title>
      <link>https://community.esri.com/t5/python-questions/valueerror-with-dataframe-in-arcpy-mapping/m-p/140038#M10917</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The arcpy.env.workspace was set earlier to the path where all of the files are.&amp;nbsp; Because everything else is working fine with regards to the MXD, the dataFrame, and adding layers, it would seem like a mute point even if it wasn't set.&amp;nbsp; This may be because the script is being run in the same directory as where all of the other files exist.&amp;nbsp; I am going to run a test where I read in an MXD that already contains a group layer and then see if I can add a layer to that group layer.&amp;nbsp; My thought is maybe after I initially added that group layer to the dataFrame, maybe I needed to do something like a save or a refresh or something because maybe the AddLayerToGroup didn't see that the group layer was added.&amp;nbsp; That doesn't make sense but who knows.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 02 Aug 2014 13:23:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/valueerror-with-dataframe-in-arcpy-mapping/m-p/140038#M10917</guid>
      <dc:creator>PeterLen</dc:creator>
      <dc:date>2014-08-02T13:23:25Z</dc:date>
    </item>
    <item>
      <title>Re: ValueError with DataFrame in arcpy.mapping.AddLayerToGroup</title>
      <link>https://community.esri.com/t5/python-questions/valueerror-with-dataframe-in-arcpy-mapping/m-p/140039#M10918</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Okay, so I think I found what was going on.&amp;nbsp; The AddLayerToGroup takes a DataFrame as its first argument.&amp;nbsp; The groupLayer:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;groupLayer = arcpy.mapping.Layer(r"EmptyGroupLayer.lyr")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;was never part of the main DataFrame (from the MXD) even after I added it:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;arcpy.mapping.AddLayer(dataFrame, groupLayer)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I guess the error was thrown because the groupLayer was not recognized as being part of the dataFrame that was sent in as an argument to the AddLayerToGroup:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;arcpy.mapping.AddLayerToGroup(dataFrame, groupLayer, tmpLayer)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In order to get it to work, all I did was retrieve the groupLayer from the dataFrame after I added it:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;groupLayer&lt;/STRONG&gt; = arcpy.mapping.Layer(r"EmptyGroupLayer.lyr")&lt;/P&gt;&lt;P&gt;groupLayer.name = "AAAA"&lt;/P&gt;&lt;P&gt;arcpy.mapping.AddLayer(dataFrame, groupLayer)&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;groupLayer = arcpy.mapping.ListLayers(mxd, "AAAA", dataFrame)[0]&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then when I did the AddLayerToGroup, all was well.&amp;nbsp; Why I had to retrieve the layer from the dataFrame after adding it to it is a bit odd, but everything seems to work when I do that.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 02 Aug 2014 20:40:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/valueerror-with-dataframe-in-arcpy-mapping/m-p/140039#M10918</guid>
      <dc:creator>PeterLen</dc:creator>
      <dc:date>2014-08-02T20:40:22Z</dc:date>
    </item>
    <item>
      <title>Re: ValueError with DataFrame in arcpy.mapping.AddLayerToGroup</title>
      <link>https://community.esri.com/t5/python-questions/valueerror-with-dataframe-in-arcpy-mapping/m-p/140040#M10919</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Grief...at least it works&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 02 Aug 2014 20:44:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/valueerror-with-dataframe-in-arcpy-mapping/m-p/140040#M10919</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2014-08-02T20:44:23Z</dc:date>
    </item>
    <item>
      <title>Re: ValueError with DataFrame in arcpy.mapping.AddLayerToGroup</title>
      <link>https://community.esri.com/t5/python-questions/valueerror-with-dataframe-in-arcpy-mapping/m-p/140041#M10920</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yeah, thanks for your replies Dan.&amp;nbsp; This may all have been avoided if the arcpy library allowed you to create a Group Layer object outright, but apparently it doesn't and that is why people had used alternatives like reading in a .lyr file like I was doing.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 02 Aug 2014 23:24:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/valueerror-with-dataframe-in-arcpy-mapping/m-p/140041#M10920</guid>
      <dc:creator>PeterLen</dc:creator>
      <dc:date>2014-08-02T23:24:28Z</dc:date>
    </item>
  </channel>
</rss>

