Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

Building a Tool with Python Examples

$
0
0
Part A
Code:

import arcpy, os, sys, string

try:

    inData = arcpy.GetParameterAsText(0)
    outData = arcpy.GetParameterAsText(1)
    bufferDistance = arcpy.GetParameterAsText(2)

# Run the Buffer tool
    arcpy.Buffer_analysis(inData, outData, bufferDistance)

#parameters for clip feature
    inFC = arcpy.GetParameterAsText(3)
    clipFC = arcpy.GetParameterAsText(4)
    outFC = arcpy.GetParameterAsText(5)

#Run the Clip Tool
    arcpy.Clip_analysis(inFC, clipFC, outFC)

except:
    print arcpy.GetMessages()


# Create envrionmental variables
arcpy.env.overwriteOutput = True
arcpy.env.workspace = r""
input = "Impacted_Areas"
lyr = "Impacted_Areas"

arcpy.MakeFeatureLayer_management(input, lyr)

# Write messages to a Text File
outFile = open("D:\","w")

fcSearch = arcpy.da.SearchCursor(lyr, ["NAME"])
for fcRow in fcSearch:
    exp = '"NAME" = ' + "'" + str(fcRow[0]) + "'"
    # Process: Select Layer by Attribute...
    arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", exp)
    # Process: Select Layer by Location...
    arcpy.SelectLayerByLocation_management(lyr, "BOUNDARY_TOUCHES", lyr, "", "NEW_SELECTION")

    # Build another search cursor to grab the NAME values out of lyr...
    txtSearch = arcpy.da.SearchCursor(lyr, ["NAME"])
    outFile.write("Name:  " + str(fcRow[0]) + "\n")
    for txtRow in txtSearch:
        zval = str(txtRow[0])
        outFile.write(zval + "\n")


outFile.close()    # This closes the text file

Part B

Code:

import arcpy

# Set the workspace for the ListFeatureClass function
arcpy.env.workspace = ".dgb"

fieldList = arcpy.ListFeatureClasses()
print fieldList
   
arcpy.MakeFeatureLayer_management (str(fieldList))
lyr.saveACopy (r"D:\")
   
import arcpy.mapping as mapping
   
#Export Map Document as PDF
mxd = mapping.MapDocument("D:\1.mxd")

mapping.ExportToPDF(mxd,r".pdf")
                         
# Write messages to a Text File
outFile = open("D:.text","w")
outFile.close()    # This closes the text file


Viewing all articles
Browse latest Browse all 2485

Trending Articles