How would I automate the Define Projection tool so that I can just enter my layer each time?

I have it as a script in toolbox, but I am unsure how to set it so I can just input my layer as GetParameterAsText

Here is the script. I want to replace the "forest.shp" with a layer of my own choosing each time

 # set local variables
 inDataset = "forest.shp"
 coordinateSystem ="GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]]"

arcpy.DefineProjection_management(inDataset, coordinateSystem)
  • 2
    You could make the input to your tool a Model Parameter. Upon running the tool, it will ask for you input just like when you run it from the Toolbox. Do you know the you can run it as a "batch" as well by right clicking on the Define Projection tool.
    – MLowry
    Oct 26, 2011 at 15:25

2 Answers 2


You can do it in python by adding

inDataset   = arcpy.GetParameterAsText(0)

here is that example.


Then add as a script tool. Adding_a_script_tool

Or just set the model param as MLowry suggested. That is probably quicker and easier.


your .py file must be :

import arcpy 
   coordinateSystem ="GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]]"
   fc = arcpy.GetParameterAsText(0) #your featureclass file
   dessr = arcpy.Describe(fc)
   srr = dessr.spatialReference
   arcpy.AddMessage("Your previous projection: %s" % (srr))

   arcpy.DefineProjection_management(fc, coordinateSystem)
   arcpy.AddMessage("Your process finished...")
   arcpy.AddMessage("Cant trasformed new projection")

and then follow theJones direction....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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