<?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 a list in arcpy.MakeFeatureLayer_management in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/add-a-list-in-arcpy-makefeaturelayer-management/m-p/1214150#M65626</link>
    <description>&lt;P&gt;yes it's a geodatabase&lt;/P&gt;</description>
    <pubDate>Tue, 20 Sep 2022 11:57:22 GMT</pubDate>
    <dc:creator>danielROUFFART1</dc:creator>
    <dc:date>2022-09-20T11:57:22Z</dc:date>
    <item>
      <title>add a list in arcpy.MakeFeatureLayer_management</title>
      <link>https://community.esri.com/t5/python-questions/add-a-list-in-arcpy-makefeaturelayer-management/m-p/1213784#M65614</link>
      <description>&lt;P&gt;Hi! i ty to make&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;output = r'C:\Temp\test.gdb\BAV1'
target = r'C:\download

fcs2 = [a, b, c, d]
# Set the workspace
arcpy.env.workspace = ready
for x in range(len(fcs2)):
    arcpy.MakeFeatureLayer_management(fcs2, output)

arcpy.SelectLayerByAttribute_management(output, 'NEW_SELECTION', "city = 'Paris'")

arcpy.CopyFeatures_management(output, target)&lt;/LI-CODE&gt;&lt;P&gt;but i've got an error message, can you help me about my script for put my list please&lt;/P&gt;</description>
      <pubDate>Mon, 19 Sep 2022 12:53:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-a-list-in-arcpy-makefeaturelayer-management/m-p/1213784#M65614</guid>
      <dc:creator>danielROUFFART1</dc:creator>
      <dc:date>2022-09-19T12:53:13Z</dc:date>
    </item>
    <item>
      <title>Re: add a list in arcpy.MakeFeatureLayer_management</title>
      <link>https://community.esri.com/t5/python-questions/add-a-list-in-arcpy-makefeaturelayer-management/m-p/1213809#M65617</link>
      <description>&lt;P&gt;so i try to make a loop with this code but i've got this error message&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;arcpy.env.workspace = ready
for i in fcs:
    arcpy.MakeFeatureLayer_management(i, output)
    print("couche temp")
    # fichier temporaire d'affinage de la selection
    arcpy.SelectLayerByAttribute_management(output, 'NEW_SELECTION', "commune = 'Perpignan'")
    fc_desc = arcpy.Describe(i)
    out_name = fc_desc.baseName + 'export'
    ditched_features_path = os.path.join(out_name,saved)
    # copie de la selection en shape
    arcpy.CopyFeatures_management(output, ditched_features_path)​&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;LI-CODE lang="python"&gt;arcgisscripting.ExecuteError: ERROR 000358: Invalid expression&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 19 Sep 2022 14:05:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-a-list-in-arcpy-makefeaturelayer-management/m-p/1213809#M65617</guid>
      <dc:creator>danielROUFFART1</dc:creator>
      <dc:date>2022-09-19T14:05:09Z</dc:date>
    </item>
    <item>
      <title>Re: add a list in arcpy.MakeFeatureLayer_management</title>
      <link>https://community.esri.com/t5/python-questions/add-a-list-in-arcpy-makefeaturelayer-management/m-p/1213814#M65618</link>
      <description>&lt;P&gt;Does the traceback of the error mention what line the error occurs on? If so, please identify the matching line in the code snippet you posted.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Sep 2022 14:23:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-a-list-in-arcpy-makefeaturelayer-management/m-p/1213814#M65618</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2022-09-19T14:23:35Z</dc:date>
    </item>
    <item>
      <title>Re: add a list in arcpy.MakeFeatureLayer_management</title>
      <link>https://community.esri.com/t5/python-questions/add-a-list-in-arcpy-makefeaturelayer-management/m-p/1213821#M65619</link>
      <description>&lt;P&gt;Also, what format is your data source?&amp;nbsp; Shape file, file geodatabase, ....&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Sep 2022 14:40:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-a-list-in-arcpy-makefeaturelayer-management/m-p/1213821#M65619</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2022-09-19T14:40:20Z</dc:date>
    </item>
    <item>
      <title>Re: add a list in arcpy.MakeFeatureLayer_management</title>
      <link>https://community.esri.com/t5/python-questions/add-a-list-in-arcpy-makefeaturelayer-management/m-p/1213833#M65620</link>
      <description>&lt;P&gt;Original line 4 is setting a variable to a list of undefined variables.&amp;nbsp; Should not be getting past that line without error unless you have defined them elsewhere.&lt;/P&gt;&lt;P&gt;If there are actually feature classes a, b c, and d in the workspace "ready" (if you have defined ready anywhere), then you would want quotes around the list items.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;fcs2 = ['a', 'b', 'c', 'd']&lt;/LI-CODE&gt;&lt;P&gt;R_&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Sep 2022 15:14:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-a-list-in-arcpy-makefeaturelayer-management/m-p/1213833#M65620</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2022-09-19T15:14:03Z</dc:date>
    </item>
    <item>
      <title>Re: add a list in arcpy.MakeFeatureLayer_management</title>
      <link>https://community.esri.com/t5/python-questions/add-a-list-in-arcpy-makefeaturelayer-management/m-p/1214150#M65626</link>
      <description>&lt;P&gt;yes it's a geodatabase&lt;/P&gt;</description>
      <pubDate>Tue, 20 Sep 2022 11:57:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-a-list-in-arcpy-makefeaturelayer-management/m-p/1214150#M65626</guid>
      <dc:creator>danielROUFFART1</dc:creator>
      <dc:date>2022-09-20T11:57:22Z</dc:date>
    </item>
    <item>
      <title>Re: add a list in arcpy.MakeFeatureLayer_management</title>
      <link>https://community.esri.com/t5/python-questions/add-a-list-in-arcpy-makefeaturelayer-management/m-p/1214153#M65627</link>
      <description>&lt;P&gt;yes it say it's here:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;arcpy.SelectLayerByAttribute_management(output, 'NEW_SELECTION', "commune = 'Perpignan'")&lt;/LI-CODE&gt;&lt;P&gt;i think it's about the sql clause, because when i try my script with one feature everything it's ok, but with a loop it's don't work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Tue, 20 Sep 2022 12:14:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-a-list-in-arcpy-makefeaturelayer-management/m-p/1214153#M65627</guid>
      <dc:creator>danielROUFFART1</dc:creator>
      <dc:date>2022-09-20T12:14:32Z</dc:date>
    </item>
    <item>
      <title>Re: add a list in arcpy.MakeFeatureLayer_management</title>
      <link>https://community.esri.com/t5/python-questions/add-a-list-in-arcpy-makefeaturelayer-management/m-p/1214154#M65628</link>
      <description>&lt;P&gt;no it's just a part of my script if you wanna see him completly it' here&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Import system modules
import arcpy
import os
import shutil
import glob


# mise en place de balises
arcpy.env.overwriteOutput = True
input = r'C:\Users\user\AppData\Roaming\Esri\ArcGISPro\Favorites\TEST\
test.InvestOPERATIONS_STOCK_test'
output = r'C:\Temp\test.gdb'
Rezo = r'\\Rezo.sde'

targetPattern = r"C:\Users\**\Downloads\zipla"

Saved = glob.glob(targetPattern)
sauve = ''.join(Saved)
print (Saved)
print (sauve)
AEP = "\AEP_Régie"
joiend = [Saved,AEP]
print (joiend)

for target in joiend:
    # JOIN TARGET
    target = (''.join([''.join(Saved),AEP]))

print (target)
#######################################################################################################################
#recherche couches AEP
targetPattern=r"C:\Users\**\AppData\Roaming\Esri\ArcGISPro\Favorites"
target = glob.glob(targetPattern)
print (target)
joiend = [target,Rezo]

for ready in joiend:
    # JOIN TARGET
    ready = (''.join([''.join(target),r'\Rezo_h@geom06.sde\rezo_h.geom04.REGIE_EAU_POTABLE']))

print (ready)
ready2 = ready+"\\"
arcpy.env.workspace = ready

fcs = arcpy.ListFeatureClasses("rezo_h.AEP*")
print ("fcs")
print (fcs)


fcs2 = [ready2+ str(i) for i in fcs]



print ("fcs2")
print (fcs2)


#######################################################################################################################
# Set the workspace
arcpy.env.workspace = ready
for i in fcs2:
    arcpy.MakeFeatureLayer_management(i, output)
    print('lyr')
    # fichier temporaire d'affinage de la selection
    whereclause = "commune = 'Perpignan'"
    arcpy.SelectLayerByAttribute_management(output, 'NEW_SELECTION', whereclause)
    fc_desc = arcpy.Describe(i)
    print("fc_desc")
    print (fc_desc)
    out_name = fc_desc.baseName + '_export'
    print (out_name)

    ditched_features_path = os.path.join(out_name, sauve + "\outfile")
    # copie de la selection en shape
    arcpy.CopyFeatures_management('lyr', ditched_features_path)


#######################################################################################################################


filename = r"C:\Users\d.rouffart\Downloads\zipla"
format = "zip"
directory = os.getcwd()
shutil.make_archive(filename, format, directory)&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 20 Sep 2022 12:19:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-a-list-in-arcpy-makefeaturelayer-management/m-p/1214154#M65628</guid>
      <dc:creator>danielROUFFART1</dc:creator>
      <dc:date>2022-09-20T12:19:03Z</dc:date>
    </item>
    <item>
      <title>Re: add a list in arcpy.MakeFeatureLayer_management</title>
      <link>https://community.esri.com/t5/python-questions/add-a-list-in-arcpy-makefeaturelayer-management/m-p/1214208#M65631</link>
      <description>&lt;P&gt;Not sure if it likes&amp;nbsp;r'C:\Temp\test.gdb' as a layer name in MakeFeatureLayer.&amp;nbsp; Also, lot of issues trying to re-use the layer name in arcpy, doesn't seem to let you just delete them and reuse in a loop.&lt;/P&gt;&lt;P&gt;You might try something similar to below and append _lyr to the end of the FC as the output to make feature and input to Select.....&amp;nbsp; &amp;nbsp;This way, it will be a unique layer name for each iteration.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;    arcpy.MakeFeatureLayer_management(i, i + "_lyr")
    print('lyr')
    # fichier temporaire d'affinage de la selection
    whereclause = "commune = 'Perpignan'"
    arcpy.SelectLayerByAttribute_management(i + "_lyr", 'NEW_SELECTION', whereclause)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, seems like there is an extra step going on here.&amp;nbsp; If you put the whereclause in the MakeFeatureLayer then just use that output for the copy features you wouldn't need the Select by Attributes.&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Sep 2022 14:53:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-a-list-in-arcpy-makefeaturelayer-management/m-p/1214208#M65631</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2022-09-20T14:53:09Z</dc:date>
    </item>
    <item>
      <title>Re: add a list in arcpy.MakeFeatureLayer_management</title>
      <link>https://community.esri.com/t5/python-questions/add-a-list-in-arcpy-makefeaturelayer-management/m-p/1214509#M65645</link>
      <description>&lt;P&gt;thanks , I try your solution but i've got the same message :&lt;/P&gt;&lt;LI-CODE lang="python"&gt;Traceback (most recent call last):
  File "C:/Users/d.rouffart/Desktop/script Py/gxdh.py", line 69, in &amp;lt;module&amp;gt;
    arcpy.SelectLayerByAttribute_management(i + "_lyr", 'NEW_SELECTION', whereclause)
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 9574, in SelectLayerByAttribute
    raise e
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 9571, in SelectLayerByAttribute
    retval = convertArcObjectToPythonObject(gp.SelectLayerByAttribute_management(*gp_fixargs((in_layer_or_view, selection_type, where_clause, invert_where_clause), True)))
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 511, in &amp;lt;lambda&amp;gt;
    return lambda *args: val(*gp_fixargs(args, True))
arcgisscripting.ExecuteError: ERROR 000358: Invalid expression
Échec de l’exécution de (SelectLayerByAttribute).&lt;/LI-CODE&gt;&lt;P&gt;but when i think my expression is good&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Sep 2022 08:16:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-a-list-in-arcpy-makefeaturelayer-management/m-p/1214509#M65645</guid>
      <dc:creator>danielROUFFART1</dc:creator>
      <dc:date>2022-09-21T08:16:35Z</dc:date>
    </item>
    <item>
      <title>Re: add a list in arcpy.MakeFeatureLayer_management</title>
      <link>https://community.esri.com/t5/python-questions/add-a-list-in-arcpy-makefeaturelayer-management/m-p/1214535#M65648</link>
      <description>&lt;P&gt;You could try using the addfielddeliminators to ensure that the SQL is formatted correctly and check for the field 'commune' in each fetureclass.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;for fc in fcs2:
    flds = [f.name for f in arcpy.ListFields(fc)]
    if 'commune' in flds:
        # build the query using field deliminators 
        whereclause = f"""{arcpy.AddFieldDelimiters(fc, 'commune')} = 'Perpignan'"""
        arcpy.MakeFeatureLayer_management(fc, fc + '_lyr', whereclause)
        # continue with copying
    else:
        print (f'commune not found in {fc}')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Sep 2022 11:40:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-a-list-in-arcpy-makefeaturelayer-management/m-p/1214535#M65648</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-09-21T11:40:03Z</dc:date>
    </item>
    <item>
      <title>Re: add a list in arcpy.MakeFeatureLayer_management</title>
      <link>https://community.esri.com/t5/python-questions/add-a-list-in-arcpy-makefeaturelayer-management/m-p/1214555#M65650</link>
      <description>&lt;P&gt;ok so if i don't have a correspondence with commune field i've got an error message so i need to change my script with that no?&lt;/P&gt;&lt;LI-CODE lang="python"&gt;arcpy.env.workspace = ready
for i in fcs:
    arcpy.MakeFeatureLayer_management(i, i + "_lyr")
    print('lyr')
    # fichier temporaire d'affinage de la selection
    for fc in fcs2:
        flds = [f.name for f in arcpy.ListFields(fc)]
        if 'nomcom' in flds:
            # build the query using field deliminators
            whereclause = f"""{arcpy.AddFieldDelimiters(fc, 'nomcom')} = 'SALEILLES'"""
            arcpy.MakeFeatureLayer_management(fc, fc + '_lyr', whereclause)
            # continue with copying
        else:
            print(f'commune not found in {fc}')
    if fc is not None:
        arcpy.SelectLayerByAttribute_management(i + "_lyr", 'NEW_SELECTION', fc)
        fc_desc = arcpy.Describe(i)
        print("fc_desc")
        print (fc_desc)
        out_name = fc_desc.baseName + '_export'
        print (out_name)
        new_name = i.replace('.','_')
        print(new_name)
        new_name2 = new_name.replace('rezo_h','')
        print(new_name2)
        ditched_features_path = os.path.join(out_name, sauve + "\_"+ new_name2)
        print (ditched_features_path)
        # copie de la selection en shape
        arcpy.env.overwriteOutput = True
        arcpy.CopyFeatures_management(i + "_lyr", ditched_features_path)
    else:
        print ("no data")&lt;/LI-CODE&gt;&lt;P&gt;but have got always this error message&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;arcgisscripting.ExecuteError: ERROR 000358: Invalid expression&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 21 Sep 2022 12:48:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-a-list-in-arcpy-makefeaturelayer-management/m-p/1214555#M65650</guid>
      <dc:creator>danielROUFFART1</dc:creator>
      <dc:date>2022-09-21T12:48:04Z</dc:date>
    </item>
    <item>
      <title>Re: add a list in arcpy.MakeFeatureLayer_management</title>
      <link>https://community.esri.com/t5/python-questions/add-a-list-in-arcpy-makefeaturelayer-management/m-p/1214625#M65651</link>
      <description>&lt;P&gt;If your fields change between featureclasses, and the sql needs to change between each featureclass, you can use if/elif to create your sql.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;arcpy.env.overwriteOutput = True #&amp;lt;- move to top of script since it only needs to be set once


for fc in fcs2:
    # fichier temporaire d'affinage de la selection
    flds = [f.name for f in arcpy.ListFields(fc)]
    # create empty whereclause variable
    whereclause = None

    if 'commune' in flds:
        whereclause = f"""{arcpy.AddFieldDelimiters(fc, 'commune')} = 'Perpignan'"""

    elif 'nomcom' in flds:
        # build the query using field deliminators
        whereclause = f"""{arcpy.AddFieldDelimiters(fc, 'nomcom')} = 'SALEILLES'"""

    else:
        print(f'commune not found in {fc}')

    if whereclause:
        # describe first to get the name
        fc_desc = arcpy.Describe(fc)
        print("fc_desc")
        print (fc_desc)
        # create the temp layer with selection
        tmpLyr = arcpy.MakeFeatureLayer_management(fc, fc_desc.name + '_lyr', whereclause)
        out_name = fc_desc.baseName + '_export'
        print (out_name)
        new_name = fc_desc.name.replace('.','_').replace('rezo_h','')
        print(new_name)
        ditched_features_path = os.path.join(out_name, sauve + "\_"+ new_name)
        print (ditched_features_path)
        # copie de la selection en shape
        arcpy.CopyFeatures_management(tmpLyr, ditched_features_path)
    else:
        print ("no data")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Sep 2022 14:37:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-a-list-in-arcpy-makefeaturelayer-management/m-p/1214625#M65651</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-09-21T14:37:34Z</dc:date>
    </item>
    <item>
      <title>Re: add a list in arcpy.MakeFeatureLayer_management</title>
      <link>https://community.esri.com/t5/python-questions/add-a-list-in-arcpy-makefeaturelayer-management/m-p/1214930#M65657</link>
      <description>&lt;P&gt;thanks for your help!&lt;/P&gt;</description>
      <pubDate>Thu, 22 Sep 2022 06:16:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-a-list-in-arcpy-makefeaturelayer-management/m-p/1214930#M65657</guid>
      <dc:creator>danielROUFFART1</dc:creator>
      <dc:date>2022-09-22T06:16:56Z</dc:date>
    </item>
  </channel>
</rss>

