1

I have a script in a custom toolbox which sums the values in a given field. After the user indicates which field (currently I have them typing it in but would love to know how to get the ArcToolbox to generate a dropdown after an input is identified) the script returns the value in a win32gui box.

Using win32gui means I have to install win32com package on the users machines. Is there another easier solution to return the value of sum-ing the values in a field..preferably if the dialogue box lets you copy the text with the mouse?

I am using ArcGIS Desktop 9.3.

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked May 17, 2011 at 13:44

3 Answers 3

3

this behavior is built into the script tools. What you have to do is

  1. go into the script tool property page
  2. select your 'field' parameter
  3. set the 'obtained from' property to your table parameter

This tells the tool dialog that the choice list for the field parameter should be obtained from the table. THere's a number of parameter type combinations which have this 'choice list' behavior build in, it's documented here : http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Setting_script_tool_parameters/00150000000n000000/

Edit: oh and for the 2nd part of the question (returning the value), Dan's approach is good. Another is to have you script tool could have an parameter of datatype double and type derived, direction output. Then the value is an 'output' of the tool. Users will get it in the Result window, and be able to use it in an automated ModelBuilder/scripts.

Edit: This method works in both 9.3 and ArcGIS 10.

Brian
4,2394 gold badges36 silver badges53 bronze badges
answered May 17, 2011 at 14:32
1
  • EDIT: Dan answered the question but this also answered the field question which I have been wanting (half-hearted searching for) for a while. Thanks. Commented May 20, 2011 at 19:28
2

I am not sure why you have ruled out using AddMessage within your toolbox script to return the sum. You just need to remember that AddMessage requires strings as input and concatenation uses the + plus operator. If your script is written in Python then the salient line in ArcMap 10 would be arcpy.AddMessage("Sum: " + str(yoursumvariable))

To use this in ArcGIS 9.3, use gp.AddMessage instead of arcpy.AddMessage. gp is the geoprocessor object created at the beginning of the script using "gp = arcgisscripting.create(9.3)"

And for future reference, 9.2 users can use "gp = arcgisscripting.create()"

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
answered May 17, 2011 at 14:12
0

If you feel comfortable with it you can make customizations to the Tool Validator Class. ESRI help for that is here: http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00150000000t000000.htm

Also if memory serves (it's been a while since I've done it myself) as you set your interface up in the script properties you can set parameter up as a Field Mapping and in the bottom grid set its Obtained by property to the parameter name of your input Feature. This is BY FAR the easier of the two options.

answered May 17, 2011 at 14:09

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.