1

arcpy.SelectLayerByAttribute_management() helps in selection but I am unable to create a new layer from the selection arcpy.MakeFeatureLayer_management() for generating new layer file but it gives an error:

arcpy.MakeFeatureLayer_management("C:/Users/Gurminder/Documents/study/IWMI/TestingAutomation/SnowLine/SnowPersonal.mdb/Snow_lyr")
Runtime error  Traceback (most recent call last):   File "<string>", line 1, in <module>   File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\management.py", line 5774, in MakeFeatureLayer     raise e ExecuteError: ERROR 000732: Input Features: Dataset C:/Users/Gurminder/Documents/study/IWMI/TestingAutomation/SnowLine/SnowPersonal.mdb/Snow_lyr does not exist or is not supported ERROR 000735: Output Layer: Value is required

How do i create a new layer so that i can copy the selection in the newly created layer, I have used Personal geodatabase

Is there any alternate way to do the same?

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Gurminder Bharani
  • 794
  • 3
  • 13
  • 22
  • 2
    You cannot make a layer from a selection. What you want to use is arcpy.CopyFeatures_management. This will create a new feature class with only the selected features. Write it to in_memory if you want to make it temporary – Ben S Nadler Nov 08 '15 at 00:21
  • You may find this Q&A on the difference between a layer and a dataset to be useful reading: http://gis.stackexchange.com/questions/26336/what-is-difference-between-map-layer-and-spatial-dataset-e-g-feature-class-sh – PolyGeo Nov 08 '15 at 00:27
  • 2
    Instead of selecting by attribute, use a where clause in makefeaturelayer http://resources.arcgis.com/EN/HELP/MAIN/10.2/index.html#//00170000006p000000 – user2856 Nov 08 '15 at 02:35
  • Thank you @BenSNadler for taking out time and suggesting the solution, the solution you have mentioned has solved my problem. – Gurminder Bharani Nov 09 '15 at 09:39
  • NP. My pleasure. As luke mentioned, using the selection expression in a definition query with makeFeatureLayer will do something similar, but will not work for UI selections, spatial selections or subselections. For those You would need to get the OID list of the selection and use it for the definition query – Ben S Nadler Nov 09 '15 at 23:53

1 Answers1

1

Without you including a code snippet that lead to your error it is difficult to assist, but from your error message:

arcpy.MakeFeatureLayer_management("C:/Users/Gurminder/Documents/study/IWMI/TestingAutomation/SnowLine/SnowPersonal.mdb/Snow_lyr")
Runtime error  Traceback (most recent call last):   File "<string>", line 1, in <module>   File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\management.py", line 5774, in MakeFeatureLayer     raise e ExecuteError: ERROR 000732: Input Features: Dataset C:/Users/Gurminder/Documents/study/IWMI/TestingAutomation/SnowLine/SnowPersonal.mdb/Snow_lyr does not exist or is not supported ERROR 000735: Output Layer: Value is required

there are at least two issues:

  • I suspect that C:/Users/Gurminder/Documents/study/IWMI/TestingAutomation/SnowLine/SnowPersonal.mdb/Snow_lyr does not exist - try using `print arcpy.Exists(C:/Users/Gurminder/Documents/study/IWMI/TestingAutomation/SnowLine/SnowPersonal.mdb/Snow_lyr) on the line before you try to access it to ensure that it does.
  • Make Feature Layer expects two arguments i.e. a dataset and a layer name, but you appear to have only provided the former.

However, it looks like you have abandoned this approach and followed the comment by @BenSNadler:

You cannot make a layer from a selection. What you want to use is arcpy.CopyFeatures_management. This will create a new feature class with only the selected features. Write it to in_memory if you want to make it temporary

PolyGeo
  • 65,136
  • 29
  • 109
  • 338