Skip to content

Instantly share code, notes, and snippets.

@mfunk
Last active December 4, 2020 23:18
Show Gist options
  • Select an option

  • Save mfunk/ba834e7439c14bf7748b to your computer and use it in GitHub Desktop.

Select an option

Save mfunk/ba834e7439c14bf7748b to your computer and use it in GitHub Desktop.

Revisions

  1. mfunk revised this gist Apr 6, 2016. 1 changed file with 14 additions and 13 deletions.
    27 changes: 14 additions & 13 deletions GeoprocessingScriptToolTemplate.py
    Original file line number Diff line number Diff line change
    @@ -14,20 +14,21 @@
    See the License for the specific language governing permissions and
    limitations under the License.
    ------------------------------------------------------------------------------
    ==================================================
    .py
    --------------------------------------------------
    requirments: ArcGIS X.X, Python 2.7 or Python 3.4
    author: ArcGIS Solutions
    contact: ArcGISTeam<Solution>@esri.com
    company: Esri
    ==================================================
    description: <Description>
    ==================================================
    history:
    <date> - <initals> - <modifications>
    ==================================================
    '''
    # ==================================================
    # .py
    # --------------------------------------------------
    # requirments: ArcGIS X.X, Python 2.7 or Python 3.4
    # author: ArcGIS Solutions
    # contact: ArcGISTeam<Solution>@esri.com
    # company: Esri
    # ==================================================
    # description: <Description>
    # ==================================================
    # history:
    # <date> - <initals> - <modifications>
    # ==================================================

    # IMPORTS ==========================================
    import os
  2. mfunk revised this gist Apr 6, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion GeoprocessingScriptToolTemplate.py
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    # coding: utf-8
    '''
    ------------------------------------------------------------------------------
    Copyright 2015 Esri
    Copyright 2016 Esri
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
  3. mfunk revised this gist Apr 6, 2016. 1 changed file with 16 additions and 15 deletions.
    31 changes: 16 additions & 15 deletions GeoprocessingScriptToolTemplate.py
    Original file line number Diff line number Diff line change
    @@ -1,19 +1,20 @@
    # coding: utf-8
    #------------------------------------------------------------------------------
    # Copyright 2015 Esri
    # Licensed under the Apache License, Version 2.0 (the "License");
    # you may not use this file except in compliance with the License.
    # You may obtain a copy of the License at
    #
    # http://www.apache.org/licenses/LICENSE-2.0
    #
    # Unless required by applicable law or agreed to in writing, software
    # distributed under the License is distributed on an "AS IS" BASIS,
    # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    # See the License for the specific language governing permissions and
    # limitations under the License.
    #------------------------------------------------------------------------------

    '''
    ------------------------------------------------------------------------------
    Copyright 2015 Esri
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
    http://www.apache.org/licenses/LICENSE-2.0
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
    ------------------------------------------------------------------------------
    '''
    # ==================================================
    # .py
    # --------------------------------------------------
  4. mfunk created this gist Oct 16, 2015.
    92 changes: 92 additions & 0 deletions GeoprocessingScriptToolTemplate.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,92 @@
    # coding: utf-8
    #------------------------------------------------------------------------------
    # Copyright 2015 Esri
    # Licensed under the Apache License, Version 2.0 (the "License");
    # you may not use this file except in compliance with the License.
    # You may obtain a copy of the License at
    #
    # http://www.apache.org/licenses/LICENSE-2.0
    #
    # Unless required by applicable law or agreed to in writing, software
    # distributed under the License is distributed on an "AS IS" BASIS,
    # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    # See the License for the specific language governing permissions and
    # limitations under the License.
    #------------------------------------------------------------------------------

    # ==================================================
    # .py
    # --------------------------------------------------
    # requirments: ArcGIS X.X, Python 2.7 or Python 3.4
    # author: ArcGIS Solutions
    # contact: ArcGISTeam<Solution>@esri.com
    # company: Esri
    # ==================================================
    # description: <Description>
    # ==================================================
    # history:
    # <date> - <initals> - <modifications>
    # ==================================================

    # IMPORTS ==========================================
    import os
    import sys
    import traceback
    import arcpy
    from arcpy import env

    # LOCALS ===========================================
    deleteme = [] # intermediate datasets to be deleted
    debug = True # extra messaging during development

    # FUNCTIONS ========================================



    def main():
    try:
    # get/set environment
    env.overwriteOutput = True


    # Set output



    except arcpy.ExecuteError:
    # Get the tool error messages
    msgs = arcpy.GetMessages()
    arcpy.AddError(msgs)
    print(msgs)

    except:
    # Get the traceback object
    tb = sys.exc_info()[2]
    tbinfo = traceback.format_tb(tb)[0]

    # Concatenate information together concerning the error into a message string
    pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1])
    msgs = "ArcPy ERRORS:\n" + arcpy.GetMessages() + "\n"

    # Return python error messages for use in script tool or Python Window
    arcpy.AddError(pymsg)
    arcpy.AddError(msgs)

    # Print Python error messages for use in Python / Python Window
    print(pymsg + "\n")
    print(msgs)

    finally:
    if debug == False and len(deleteme) > 0:
    # cleanup intermediate datasets
    if debug == True: arcpy.AddMessage("Removing intermediate datasets...")
    for i in deleteme:
    if debug == True: arcpy.AddMessage("Removing: " + str(i))
    arcpy.Delete_management(i)
    if debug == True: arcpy.AddMessage("Done")



    # MAIN =============================================
    if __name__ == "__main__":
    main()