Python script to automate Save as layer file...

Discussion created by jmjira on Sep 16, 2011
Latest reply on Sep 16, 2011 by achapkowski-esristaff
Hello all. Searched the forums, but could not find any issues that addressed my problem.

I would like to create a python script to limit a feature class (or layer) with a definition query and save it as a layer file, similar to if you wrote a definition query for a layer and then right clicked in the TOC and used the "Save As Layer File...".

I have done this in python using SelectLayerByAttribute_management (to limit the layer using a query) and SaveToLayerFile_management (to save to a layer file). This works, however the layer file uses a selection set to define the features and not a definition query to define the features. There is big difference, if features are added to the feature class, they will not be displayed with the layer file, because it is based on a selection, not a query.

I'll be thankful for any help or comments.