<?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 Problems with UpdateLayer - exporting field aliases to shapefile in Mapping Questions</title>
    <link>https://community.esri.com/t5/mapping-questions/problems-with-updatelayer-exporting-field-aliases/m-p/174414#M1898</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello All, &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am running into problems with UpdateLayer that I can???t figure out. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My goal is to write a script that exports a shapefile from a FGDB and adds the field-aliases existing in the FGDB-FC to the shapefile. I have run through the steps in the interactive Python-window but now I am trying to make it into a tool. I only get as far as using arcpy.mapping.UpdateLayer before it crashes.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is my code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;# -*- coding: cp1252 -*- import arcview import arcpy, os arcpy.env.overwriteOutput = True&amp;nbsp; #Setting up... arcpy.env.transferDomains = True arcpy.env.workspace = r"C:\GIS\ArcGIS\aliastest"&amp;nbsp; #Getting parameters inFC = arcpy.GetParameterAsText(0) outshp = arcpy.GetParameterAsText(1) wp = arcpy.GetParameterAsText(2)&amp;nbsp; #Converting arcpy.FeatureClassToFeatureClass_conversion(inFC, wp, outshp)&amp;nbsp; #Saving original FC to layer arcpy.MakeFeatureLayer_management(inFC, "inFCLyr") arcpy.SaveToLayerFile_management("inFCLyr", "H_Orig04")&amp;nbsp; #Saving converted shape to layer arcpy.MakeFeatureLayer_management(os.path.join(wp, outshp), "outShpvLyr") arcpy.SaveToLayerFile_management("outShpvLyr", "H_shp04.lyr")&amp;nbsp; #Preparing to update and replace srcLayer = arcpy.mapping.Layer(r"inFCLyr") upLayer = arcpy.mapping.Layer(r"outShpvLyr") mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd, "*")[0]&amp;nbsp; arcpy.mapping.AddLayer(df, srcLayer, "BOTTOM") arcpy.RefreshTOC() arcpy.RefreshActiveView()&amp;nbsp; arcpy.mapping.UpdateLayer(df, upLayer, srcLayer, False)&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It gets as far as the last line where it ends with:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt; File "c:\program files\arcgis\desktop10.1\arcpy\arcpy\utils.py", line 181, in fn_ &amp;nbsp;&amp;nbsp;&amp;nbsp; return fn(*args, **kw) &amp;nbsp; File "c:\program files\arcgis\desktop10.1\arcpy\arcpy\mapping.py", line 1876, in UpdateLayer &amp;nbsp;&amp;nbsp;&amp;nbsp; tc.ReplaceLayer(tl, rl) ValueError: DataFrameObject: Unexpected error&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Don't know what causes this! From what I can tell I am not doing anything arcpy.mapping wasn't designed for. I tested to make sure the parameters going into UpdateLayer where of the correct type, so it shouldn't be that. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For the last part of of the script, I will use replaceDatasoure to transfer aliases from the original FC to the exported shapefile. Once I get pass this... &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'd be really happy for any help on this.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 22 Feb 2013 12:55:19 GMT</pubDate>
    <dc:creator>StefanHaglund1</dc:creator>
    <dc:date>2013-02-22T12:55:19Z</dc:date>
    <item>
      <title>Problems with UpdateLayer - exporting field aliases to shapefile</title>
      <link>https://community.esri.com/t5/mapping-questions/problems-with-updatelayer-exporting-field-aliases/m-p/174414#M1898</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello All, &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am running into problems with UpdateLayer that I can???t figure out. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My goal is to write a script that exports a shapefile from a FGDB and adds the field-aliases existing in the FGDB-FC to the shapefile. I have run through the steps in the interactive Python-window but now I am trying to make it into a tool. I only get as far as using arcpy.mapping.UpdateLayer before it crashes.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is my code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;# -*- coding: cp1252 -*- import arcview import arcpy, os arcpy.env.overwriteOutput = True&amp;nbsp; #Setting up... arcpy.env.transferDomains = True arcpy.env.workspace = r"C:\GIS\ArcGIS\aliastest"&amp;nbsp; #Getting parameters inFC = arcpy.GetParameterAsText(0) outshp = arcpy.GetParameterAsText(1) wp = arcpy.GetParameterAsText(2)&amp;nbsp; #Converting arcpy.FeatureClassToFeatureClass_conversion(inFC, wp, outshp)&amp;nbsp; #Saving original FC to layer arcpy.MakeFeatureLayer_management(inFC, "inFCLyr") arcpy.SaveToLayerFile_management("inFCLyr", "H_Orig04")&amp;nbsp; #Saving converted shape to layer arcpy.MakeFeatureLayer_management(os.path.join(wp, outshp), "outShpvLyr") arcpy.SaveToLayerFile_management("outShpvLyr", "H_shp04.lyr")&amp;nbsp; #Preparing to update and replace srcLayer = arcpy.mapping.Layer(r"inFCLyr") upLayer = arcpy.mapping.Layer(r"outShpvLyr") mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd, "*")[0]&amp;nbsp; arcpy.mapping.AddLayer(df, srcLayer, "BOTTOM") arcpy.RefreshTOC() arcpy.RefreshActiveView()&amp;nbsp; arcpy.mapping.UpdateLayer(df, upLayer, srcLayer, False)&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It gets as far as the last line where it ends with:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt; File "c:\program files\arcgis\desktop10.1\arcpy\arcpy\utils.py", line 181, in fn_ &amp;nbsp;&amp;nbsp;&amp;nbsp; return fn(*args, **kw) &amp;nbsp; File "c:\program files\arcgis\desktop10.1\arcpy\arcpy\mapping.py", line 1876, in UpdateLayer &amp;nbsp;&amp;nbsp;&amp;nbsp; tc.ReplaceLayer(tl, rl) ValueError: DataFrameObject: Unexpected error&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Don't know what causes this! From what I can tell I am not doing anything arcpy.mapping wasn't designed for. I tested to make sure the parameters going into UpdateLayer where of the correct type, so it shouldn't be that. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For the last part of of the script, I will use replaceDatasoure to transfer aliases from the original FC to the exported shapefile. Once I get pass this... &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'd be really happy for any help on this.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 Feb 2013 12:55:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/problems-with-updatelayer-exporting-field-aliases/m-p/174414#M1898</guid>
      <dc:creator>StefanHaglund1</dc:creator>
      <dc:date>2013-02-22T12:55:19Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with UpdateLayer - exporting field aliases to shapefile</title>
      <link>https://community.esri.com/t5/mapping-questions/problems-with-updatelayer-exporting-field-aliases/m-p/174415#M1899</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Is it possible that you have upLayer and scrLayer reversed?&amp;nbsp; I see you are adding the source layer to the MXD, not the update layer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The layer you want to update needs to be in the mxd, the source layer does not.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jeff&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 25 Feb 2013 13:15:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/problems-with-updatelayer-exporting-field-aliases/m-p/174415#M1899</guid>
      <dc:creator>JeffBarrette</dc:creator>
      <dc:date>2013-02-25T13:15:17Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with UpdateLayer - exporting field aliases to shapefile</title>
      <link>https://community.esri.com/t5/mapping-questions/problems-with-updatelayer-exporting-field-aliases/m-p/174416#M1900</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks Jeffrey, you sent me in the right direction. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I ended up specifying the updatelayer better throughout the script. Maybe overworked it a bit but it's working. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here's my final script if someone runs into the same problem in the future. What it does is export a FC with domains and field aliasnames to a shapefile where domain descriptions are added through "arcpy.env.transferDomains = True" and also creating a .lyr-file where aliasnames are copied from the original FC. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# -*- coding: cp1252 -*-
import arcview
import arcpy, os

#Getting parameters
inFC = arcpy.GetParameterAsText(0)
wp = arcpy.GetParameterAsText(1)
outshp = arcpy.GetParameterAsText(2)

#Setting up...
arcpy.env.overwriteOutput = True
arcpy.env.transferDomains = True
arcpy.env.workspace = wp
outshpN = outshp + ".shp"
outlyr = outshp
outlyrN = outlyr + ".lyr"

#Converting
arcpy.FeatureClassToFeatureClass_conversion(inFC, wp, outshpN)

#Saving original FC to layer
arcpy.MakeFeatureLayer_management(inFC, "inFCLyr")
arcpy.SaveToLayerFile_management("inFCLyr", "origlyr")

#Saving converted shape to layer
arcpy.MakeFeatureLayer_management(os.path.join(wp, outshpN), "outShpvLyr")
arcpy.SaveToLayerFile_management("outShpvLyr", "shplyr.lyr")

#Preparing to update and replace
srcLayer = arcpy.mapping.Layer(r"inFCLyr")
upLayer = arcpy.mapping.Layer(r"outShpvLyr")
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "*")[0]
arcpy.mapping.AddLayer(df, upLayer, "BOTTOM")
arcpy.RefreshTOC()
arcpy.RefreshActiveView()
upLayerDF = arcpy.mapping.ListLayers(mxd, "outShpvLyr", df)[0]

#Updating layer
arcpy.mapping.UpdateLayer(df, upLayerDF, srcLayer, False)

#Replacing datasource
lyr = arcpy.mapping.ListLayers(mxd, "inFCLyr", df) [0]
lyr.replaceDataSource(wp, "SHAPEFILE_WORKSPACE", outshp)
lyr.name = outlyr
lyr.description = " "

#Saving layer-file
arcpy.RefreshTOC()
arcpy.RefreshActiveView()
arcpy.SaveToLayerFile_management("inFCLyr", outlyrN, "RELATIVE")

#Cleaning up
arcpy.Delete_management(os.path.join(wp, "origlyr.lyr"))
arcpy.Delete_management(os.path.join(wp, "shplyr.lyr"))&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:00:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/problems-with-updatelayer-exporting-field-aliases/m-p/174416#M1900</guid>
      <dc:creator>StefanHaglund1</dc:creator>
      <dc:date>2021-12-11T09:00:45Z</dc:date>
    </item>
  </channel>
</rss>

