<?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: loop through MXDs for change of name and type (Shp to GDB) in one layer only in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/loop-through-mxds-for-change-of-name-and-type-shp/m-p/1491050#M70807</link>
    <description>&lt;P&gt;Your indentation looks off, and I added iteration over data frames.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Assuming a DataFrame is defined or selected in the map document
    for df in arcpy.mapping.ListDataFrames(mxdNext):
        for lyr in arcpy.mapping.ListLayers(mxdNext, "old_shapefile", df):
            if lyr.supports("DATASOURCE"):
                if lyr.dataSource == r"C:\Test\Old_Shapefile.shp":
                    lyr.replaceDataSource(r"C:\Production_Data\Test\Final Data.gbd", "FILEGDB_WORKSPACE", "New_Name")
                    lyr.name = "New_Name"
                    print(lyr.name)&lt;/LI-CODE&gt;</description>
    <pubDate>Wed, 12 Jun 2024 21:36:55 GMT</pubDate>
    <dc:creator>TonyAlmeida</dc:creator>
    <dc:date>2024-06-12T21:36:55Z</dc:date>
    <item>
      <title>loop through MXDs for change of name and type (Shp to GDB) in one layer only</title>
      <link>https://community.esri.com/t5/python-questions/loop-through-mxds-for-change-of-name-and-type-shp/m-p/1490911#M70800</link>
      <description>&lt;P&gt;I thought I had this working before with your help but I was mistaken. I have continued to tweak and here is where I am. When I run it in VB I get the error:&amp;nbsp; "EOL while scanning string literal"&lt;/P&gt;&lt;P&gt;In all the forums and documents I see I can't seem to find a shapefile to a completely new location/GBD. I wonder if I need to break this change up so that maybe I change name&amp;nbsp; (to new GBD file name) then change source - IDK. Here is the code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;import arcpy
from arcpy import env



# Set the workspace for the folder containing MXDs
arcpy.env.workspace = r"C:\Test2"
mxdList = arcpy.ListFiles("*.mxd")

# Iterate through all MXDs in the workspace
for mxd in mxdList:
    mxdpath = env.workspace + "\\" + mxd
    print (mxd + "Is being processed")
    
    mxdNext = arcpy.mapping.MapDocument(mxdpath)



    for lyr in arcpy.mapping.ListLayers(mxdNext, "old_shapefile", df):
        if lyr.supports("DATASOURCE"):
            if lyr.dataSource == r"C:\Test\Old_Shapefile.shp":
              lyr.replaceDataSource(r"C:\Test\Old_Shapefile.shp", "SHAPEFILE_WORKSPACE",
              r"C:\Production_Data\Test\Final Data.gbd","FILEGDB_WORKSPACE", "New_Name")
             lyr.name == "New_Name":
        print("lyr.name")      

  
    mxdNext.save()
    arcpy.RefreshTOC()
    del mxd&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jun 2024 19:30:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-through-mxds-for-change-of-name-and-type-shp/m-p/1490911#M70800</guid>
      <dc:creator>kaww02</dc:creator>
      <dc:date>2024-06-12T19:30:55Z</dc:date>
    </item>
    <item>
      <title>Re: loop through MXDs for change of name and type (Shp to GDB) in one layer only</title>
      <link>https://community.esri.com/t5/python-questions/loop-through-mxds-for-change-of-name-and-type-shp/m-p/1490943#M70801</link>
      <description>&lt;P&gt;On line 23, you have&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;r"C:\Production_Data\Test\Final Data.gbd"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you change it to&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;r"C:\Production_Data\Test\Final Data.gdb"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;does that fix the issue?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If not, please also let us know the line that the error is occurring on.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, actually more to the point:&lt;/P&gt;&lt;P&gt;Add an "if" to the beginning of line 24 and indent line 25 twice.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jun 2024 19:39:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-through-mxds-for-change-of-name-and-type-shp/m-p/1490943#M70801</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2024-06-12T19:39:36Z</dc:date>
    </item>
    <item>
      <title>Re: loop through MXDs for change of name and type (Shp to GDB) in one layer only</title>
      <link>https://community.esri.com/t5/python-questions/loop-through-mxds-for-change-of-name-and-type-shp/m-p/1491026#M70806</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/458875"&gt;@AlfredBaldenweck&lt;/a&gt;&amp;nbsp; I made those changes but still the same error.&lt;/P&gt;&lt;P&gt;The error seems to reference line 21&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jun 2024 21:26:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-through-mxds-for-change-of-name-and-type-shp/m-p/1491026#M70806</guid>
      <dc:creator>kaww02</dc:creator>
      <dc:date>2024-06-12T21:26:15Z</dc:date>
    </item>
    <item>
      <title>Re: loop through MXDs for change of name and type (Shp to GDB) in one layer only</title>
      <link>https://community.esri.com/t5/python-questions/loop-through-mxds-for-change-of-name-and-type-shp/m-p/1491050#M70807</link>
      <description>&lt;P&gt;Your indentation looks off, and I added iteration over data frames.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Assuming a DataFrame is defined or selected in the map document
    for df in arcpy.mapping.ListDataFrames(mxdNext):
        for lyr in arcpy.mapping.ListLayers(mxdNext, "old_shapefile", df):
            if lyr.supports("DATASOURCE"):
                if lyr.dataSource == r"C:\Test\Old_Shapefile.shp":
                    lyr.replaceDataSource(r"C:\Production_Data\Test\Final Data.gbd", "FILEGDB_WORKSPACE", "New_Name")
                    lyr.name = "New_Name"
                    print(lyr.name)&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 12 Jun 2024 21:36:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-through-mxds-for-change-of-name-and-type-shp/m-p/1491050#M70807</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2024-06-12T21:36:55Z</dc:date>
    </item>
  </channel>
</rss>

