What is the Python script for shapefile to layer conversion? I tried the following...

import arcpy  
from arcpy import env  
env.workspace="working path"  
arcpy.MakeFeatureLayer_conversion("source shapefile", "target name")
  • arcpy.MakeFeatureLayer_management("source shapefile", "target name") – Paul Jun 26 '13 at 15:24
  • ok, i tried that also... – Satya Chandra Jun 26 '13 at 15:25
  • Could you please post the code that isn't working? It's working on my end. – Paul Jun 26 '13 at 15:29
  • import arcpy from arcpy import env env.workspace="G:/gis/test" arcpy.MakeFeatureLayer_management("india.shp","indlyr") – Satya Chandra Jun 26 '13 at 15:31
  • If you are doing this outside of ArcMap, then you need to save the layer to disk – Paul Jun 26 '13 at 15:36

This should work...

import arcpy
from arcpy import env
env.workspace = "G:/gis/test"
dataset = arcpy.GetParameterAsText(0)
lyr = r'Path To output location' # e.g. r'C:\Mapping\IndiaLyr.Lyr'
arcpy.MakeFeatureLayer_management(dataset, "indlyr")
arcpy.SaveToLayerFile_management("indlyr", lyr, "ABSOLUTE")

Edited to accomodate script tool solution. You can probably get rid of the env.workspace variable as it won't be used.

Once you create the script tool from your script, right click the script tool and select properties.

Give your script tool a name...

enter image description here

Click the Parameters tab, give your input parameter a Display Name and select the data type you would like to use (if you expect to either use a shapefile, feature class, etc. use the Dataset data type)

enter image description here

Click finish. Now open your script tool by double clicking it or right clicking and selecting open. Browse or drag and drop your dataset.

enter image description here

  • 1
    +1 Quick and simple. Although env.worksapce has a spelling error. – Aaron Jun 26 '13 at 19:55
  • Now i want to make a simple tool from the above code?I tried to add this script file in tool box but i failed to set parameters?Please Explain? – Satya Chandra Jun 27 '13 at 4:57
  • What part of the help files have you read on creating tools before we replicate information you may already be familiar with? – user681 Jun 27 '13 at 17:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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