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?

closed as off-topic by PolyGeo Dec 14 '15 at 10:08

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions seeking help to debug/write/improve code must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Providing a clear problem statement and evidence of a code attempt will help others to help you. See: How to create a Minimal, Complete, and Verifiable example." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 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 8 '15 at 0:21
  • You may find this Q&A on the difference between a layer and a dataset to be useful reading: gis.stackexchange.com/questions/26336/… – PolyGeo Nov 8 '15 at 0:27
  • 2
    Instead of selecting by attribute, use a where clause in makefeaturelayer resources.arcgis.com/EN/HELP/MAIN/10.2/index.html#//… – user2856 Nov 8 '15 at 2:35
  • Thank you @BenSNadler for taking out time and suggesting the solution, the solution you have mentioned has solved my problem. – Gurminder Bharani Nov 9 '15 at 9: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 9 '15 at 23:53
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

Not the answer you're looking for? Browse other questions tagged or ask your own question.