0

I would like to create a new shapefile based on input.

My input is DATE parameter. This is my code for input parameter:

param = arcpy.Parameter(
displayName="TARIKH",
name="date_feature",
datatype="Date",
parameterType="Required",
direction="Input")

and then the value in this parameter will be analysed using this code:

  out_path = "C:/Last"
geometry_type = "POLYGON"
out_name = #DATEINPUT
result = arcpy.CreateFeatureclass_management(out_path, out_name,geometry_type)

The main point is, I don't know how to input all this code into toolbox code.

#

This is the full code which I don't know where to put and what to insert into an .pyt toolbox

import arcpy
arcpy.env.overwriteOutput = True

class Toolbox(object):
    def __init__(self):
        """Define the toolbox (the name of the toolbox is the name of the
        .pyt file)."""
        self.label = "Toolbox"
        self.alias = ""

        # List of tool classes associated with this toolbox
        self.tools = [Tool]


class Tool(object):
    def __init__(self):
        """Define the tool (tool name is the name of the class)."""
        self.label = "Tool"
        self.description = ""
        self.canRunInBackground = False

    def getParameterInfo(self):

        """Define parameter definitions"""
        param = arcpy.Parameter(
        displayName="TARIKH",
        name="date_feature",
        datatype="Date",
        parameterType="Required",
        direction="Input")
        #date_features.filter.list = ["Point","Polyline","Polygon"]

        #params = [date_features]
        return 

    def isLicensed(self):
        """Set whether tool is licensed to execute."""
        return True

    def updateParameters(self, parameters):
        """Modify the values and properties of parameters before internal
        validation is performed.  This method is called whenever a parameter
        has been changed."""

        self.param[0] = date_feature

        print "Your new shapefile sucessfull created"
        out_path = "C:/Last"
        geometry_type = "POLYGON"
        out_name = date_features
        result = arcpy.CreateFeatureclass_management(out_path, out_name,geometry_type)

        return 

    def updateMessages(self, parameters):
        """Modify the messages created by internal validation for each tool
        parameter.  This method is called after internal validation."""
        return

    def execute(self, parameters, messages):
        """The source code of the tool."""
        return
  • Welcome to GIS SE! As a new user be sure to take the Tour – TsvGis Aug 14 '15 at 4:45
  • Would you be able to use the edit button beneath your question to revise it with a few more details, please? Are you trying to write a Python toolbox (*.pyt) or something else? How does a date input relate to creating a shapefile? – PolyGeo Aug 14 '15 at 4:47
  • yes , im try to write python toolbox, i just want to the user just insert a date for creating a newshapefile and the name of the shapefile is based on date insert. for example 14/08/2015 the shapefile name will be 14082015.shp – Syavmil Aug 14 '15 at 6:40
  • Please include those additional details into your question. What happens when you try to open and run your tool as it stands? To help I think we will need to see the code for a whole *.pyt file (Python toolbox) from you - just make sure that it defines only the one tool that you need help with in it. – PolyGeo Aug 14 '15 at 6:50
  • the input working well, but idk where the variable go. – Syavmil Aug 14 '15 at 7:26
2

Short answer is move what you had in updateParameters down to execute. What would otherwise be a standalone python script goes there. Fixed some other issues in your code as well, this should be functional (keep everything before getParameterInfo like you had it):

    def getParameterInfo(self):
        param = arcpy.Parameter(
        displayName="TARIKH",
        name="date_feature",
        datatype="Date",
        parameterType="Required",
        direction="Input")

        params = [param] #makes a list of your parameters

        return params #returns your list for future use

    def isLicensed(self):
        return True
    def updateParameters(self, parameters):
        return 
    def updateMessages(self, parameters):
        return

    def execute(self, params, messages): #notice that params is listed

        date_feature = params[0].valueAsText #gets the first value from your list as text
        out_name = date_feature.replace("/", "") #removes slash formating from string
        out_path = "C:/Last"
        geometry_type = "POLYGON"

        arcpy.CreateFeatureclass_management(out_path, out_name, geometry_type)
        arcpy.AddMessage("Your new shapefile sucessfully created")

        return

Other resources for learning .pyt: ESRI has a free webinar and documentation that you may find helpful.

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.