<?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: replaceFieldMap() appears broken in arcpy in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/replacefieldmap-appears-broken-in-arcpy/m-p/315867#M24581</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Yes, I agree, exporting the field map to a string, parsing it, and passing it back in is a little scary but at least it works. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Anyway, I'm glad I could help.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Joel&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 21 Jul 2011 14:58:54 GMT</pubDate>
    <dc:creator>JoelCalhoun</dc:creator>
    <dc:date>2011-07-21T14:58:54Z</dc:date>
    <item>
      <title>replaceFieldMap() appears broken in arcpy</title>
      <link>https://community.esri.com/t5/python-questions/replacefieldmap-appears-broken-in-arcpy/m-p/315862#M24576</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;ArcPy People:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The scenario is a simple one. I want to join a table view to a feature layer, clean up the output fields so the field name does not contain the table name, and export the contents to a file geodatabase using either FeatureClassToFeatureClass_management or TableToTable_management. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The python/arcpy script crashes out when it encounters either of these functions with the fieldMappings object as a parameter.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I can remove unwanted fields from the fieldMappings using removeFieldMap(). But when I replace a fieldMap in the fieldMappings with a newly formatted field name, the replaceFieldMap() command causes the script to fail. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;We can easily rename output fields using the Geoprocessing Tools out of ArcCatalog and Model Builder. The problem is with arcpy and the replaceFieldMap().&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My workaround thus far is to use layerfiles with a pre canned set of output field names. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It would be nice to have something a little more elegant. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;(I am not sure if ESRI have raised this as a bug, local support here will try and recreate the issue using their own data and scripts)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Susan Jones&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;GIS Consultant&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Spatial Logic Ltd&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="mailto:&amp;quot;sjones@spatiallogic.co.nz&amp;quot;" rel="nofollow"&gt;sjones@spatiallogic.co.nz&lt;/A&gt;&lt;BR /&gt;&lt;A href="http://www.spatiallogic.co.nz" rel="nofollow"&gt;http://www.spatiallogic.co.nz&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Jul 2011 06:09:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/replacefieldmap-appears-broken-in-arcpy/m-p/315862#M24576</guid>
      <dc:creator>SusanJones</dc:creator>
      <dc:date>2011-07-18T06:09:15Z</dc:date>
    </item>
    <item>
      <title>Re: replaceFieldMap() appears broken in arcpy</title>
      <link>https://community.esri.com/t5/python-questions/replacefieldmap-appears-broken-in-arcpy/m-p/315863#M24577</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;arcpy.env.qualifiedFieldNames = 0 wil suppress the table name in the field name. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Still no way of being to specify output field alias after a join.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Jul 2011 09:15:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/replacefieldmap-appears-broken-in-arcpy/m-p/315863#M24577</guid>
      <dc:creator>SusanJones</dc:creator>
      <dc:date>2011-07-19T09:15:19Z</dc:date>
    </item>
    <item>
      <title>Re: replaceFieldMap() appears broken in arcpy</title>
      <link>https://community.esri.com/t5/python-questions/replacefieldmap-appears-broken-in-arcpy/m-p/315864#M24578</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Susan,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This might not be exactly what you are looking for but I wrote a little python script for joining a table to a feature class.&amp;nbsp; The output preserves the input table attribute names instead of the table name being appended to each attribute name or the sequential _1, _2, _3, etc. being added using the standard ESRI join.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;In this script I perserve the original field names from the input table.&amp;nbsp; I don't do anything with aliases.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In the script tool interface I have added an option to either preserve all table attributes in the output, regardless if they match an attribute name in the input GIS dataset, or to drop the table fields that match the input GIS dataset.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In the case where you choose to keep all, the table field names that match existing input GIS dataset field names will have an &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;&lt;STRONG&gt;_tab&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN&gt; added to the attribute name to distinguish it from the existing input GIS dataset field names, this may result in the output table field names being truncated.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have also included the standard option to keep all records or to just include the records that match.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Currently the script only supports input table types of dbf and excel.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Input GIS datasets supported are .shp, file geodatabase, and SDE feature classes.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Output is determined by the input GIS dataset type.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Input .shp and SDE feature classes output as .shp and input file geodatabases output as file geodatabase.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The attached .zip file includes the python script and a toolbox with the associated script tool.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you have any questions just reply to this thread.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Joel&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Jul 2011 02:42:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/replacefieldmap-appears-broken-in-arcpy/m-p/315864#M24578</guid>
      <dc:creator>JoelCalhoun</dc:creator>
      <dc:date>2011-07-20T02:42:24Z</dc:date>
    </item>
    <item>
      <title>Re: replaceFieldMap() appears broken in arcpy</title>
      <link>https://community.esri.com/t5/python-questions/replacefieldmap-appears-broken-in-arcpy/m-p/315865#M24579</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;dear Joel&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I think you have just answered my problem. I will take a look at the field mappings in the morning when I am more refreshed. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Earlier I came across the nimbus bug, after spending quite a few days wrestling with local support. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;man, You are good. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;susan&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Jul 2011 09:35:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/replacefieldmap-appears-broken-in-arcpy/m-p/315865#M24579</guid>
      <dc:creator>SusanJones</dc:creator>
      <dc:date>2011-07-20T09:35:48Z</dc:date>
    </item>
    <item>
      <title>Re: replaceFieldMap() appears broken in arcpy</title>
      <link>https://community.esri.com/t5/python-questions/replacefieldmap-appears-broken-in-arcpy/m-p/315866#M24580</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Joel and others,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;A very big thank you to this. Working with text strings is a little (lot) scary but atleast it solves the problem of the replaceFieldMap()&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is an example of what works, to solving &lt;/SPAN&gt;&lt;STRONG&gt;NIM047605&lt;/STRONG&gt;&lt;SPAN&gt;. (indentation is a bit out so I will also upload the python script separately).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;---start&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#the Way TO Get Around Field Mapping From NIM047605&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;fieldMappings = arcpy.FieldMappings()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;fieldMappings.addTable("TableView")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#use exportToString() To Dump Contents Into An ASCII File&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;strFieldMaps = fieldMappings.exportToString()&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#each FieldMap Is Separated By A semi colon&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;lstFieldMaps = string.strip(strFieldMaps,";")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#loop Through The FieldMaps&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;newfm = ""&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for fm in lstFieldMaps:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; #get The AliasName, The First Occurance In lstFm&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; lstFm = string.strip(fm, " ")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; aliasName = lstFm[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; newAliasName = aliasName + "_Alias"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; #assign The Alias&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; fm = string.replace(fm,aliasName + " ",newAliasName + " ")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; #add To The New FieldMap&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; newfm = newfm + ";"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#make The New FieldMap&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;fieldMappings.removeAll()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;fieldMappings.loadFromString(newfm)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#convert To Table WIth The New FieldMappings&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.TableToTable_conversion("TableView", "c:\\Temp\\new.gdb","newTable","",fieldMappings)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;---end&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Susan&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Jul 2011 22:34:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/replacefieldmap-appears-broken-in-arcpy/m-p/315866#M24580</guid>
      <dc:creator>SusanJones</dc:creator>
      <dc:date>2011-07-20T22:34:36Z</dc:date>
    </item>
    <item>
      <title>Re: replaceFieldMap() appears broken in arcpy</title>
      <link>https://community.esri.com/t5/python-questions/replacefieldmap-appears-broken-in-arcpy/m-p/315867#M24581</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Yes, I agree, exporting the field map to a string, parsing it, and passing it back in is a little scary but at least it works. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Anyway, I'm glad I could help.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Joel&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Jul 2011 14:58:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/replacefieldmap-appears-broken-in-arcpy/m-p/315867#M24581</guid>
      <dc:creator>JoelCalhoun</dc:creator>
      <dc:date>2011-07-21T14:58:54Z</dc:date>
    </item>
    <item>
      <title>Re: replaceFieldMap() appears broken in arcpy</title>
      <link>https://community.esri.com/t5/python-questions/replacefieldmap-appears-broken-in-arcpy/m-p/315868#M24582</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Dear All:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Attached is the python script with all it's formatting to make it easier to follow and demonstrate.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Do a search on "NIM04" to get to the fieldMappings part in the arcpy script. .&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Susan&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;the replaceFieldMap() Bug is located here in this piece of code&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;--begin&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; arcpy.AddMessage("***drop Existing Fields and Fields Not in the List")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; outFieldList = getOutFieldList(application)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; fieldMappings = arcpy.FieldMappings()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; fieldMappings.addTable("TableView")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; index = 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; while index &amp;lt; fieldMappings.fieldCount:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; #get Field Map, fm&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; fm = fieldMappings.getFieldMap(index)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; fld = fm.outputField&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; fldName = checkField(string.upper(fld.name))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; fld.name = fldName&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; fm.outputField = fld&lt;/SPAN&gt;&lt;BR /&gt;&lt;STRONG&gt; fieldMappings.replaceFieldMap(index,fm)&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt; arcpy.AddMessage("***" + fld.name)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; #next Field Map&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; index += 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; test = fieldMappings.exportToString()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; lstTest = string.split(test,";")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; for ts in lstTest:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; arcpy.AddMessage(ts)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; #tableToTable Fails&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; arcpy.TableToTable_conversion("TableView",outWsp,application,"",fieldMappings)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;-- end&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Jul 2011 22:21:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/replacefieldmap-appears-broken-in-arcpy/m-p/315868#M24582</guid>
      <dc:creator>SusanJones</dc:creator>
      <dc:date>2011-07-21T22:21:18Z</dc:date>
    </item>
  </channel>
</rss>

