Code Monkey home page Code Monkey logo

arcgis-python-toolbox-bootstrap's Introduction

Python Toolbox Template

This script is not a fully functional working script. Rather, it is a template for bootstrapping an ArcGIS Python Toolbox implementing what I outline at:

http://joelmccune.com/lessons-learned-and-ideas-for-python-toolbox-coding/

If you are planning on using PyScripter set up to author ArcGIS Python Toolboxes, this posting discusses getting PyScripter to recognize *.pyt files and how to create your own templates:

http://joelmccune.com/set-up-pyscripter-to-create-arcgis-python-toolboxes/

arcgis-python-toolbox-bootstrap's People

Contributors

knu2xs avatar maphew avatar nmpeterson avatar slootsky avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

arcgis-python-toolbox-bootstrap's Issues

Parameter order and name ambiguity

Hey Joel. Since I've asked for your help in my other issue, I'd like to also share some thoughts with you on streamlining the creation of python toolboxes. Something that has bothered my a lot when beginning to write python toolboxes were two things:

  1. The order I define my parameters the class getParameterInfo() is the same order the parameters are displayed in the tool. And this order ALSO matters in my pyt file, since I call and change the parameter values by index (e.g. parameters[0].valueAsText). This usually means that I stick to the order of the parameters as I had defined them since changing the order could break the code. In the GUI, this order is usually counter intuitive.

  2. I constantly repeat myself when naming my parameters: arcpy.Parameter() has a "name" argument, and I assign the parameter to a variable (usually with the same name) in my execute() class. With the classic approach (not using your template), there are even more repetitions.

To solve these two problems, I've recently started the following practice: I import the parameters as a dictionary within the execute() class with following code:

paramdict = {y.name : y.valueAsText for y in parameters}

In this way, I can simply call my parameters using their name as I had defined them within arcpy.Parameter() like so: paramdict["exName"]. This means that I can change the orders o my parameters without needing to change the subsequent code (solving issue 1). Also, I need to name my parameters only once (which solves issue 2).

What do you think of this approach?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.