Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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? Thanks.

EDIT: I am at 9.3..thanks.

share|improve this question
add comment

3 Answers

up vote 1 down vote accepted

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))

Edit: to use this in ArcGIS 10, 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)"

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

share|improve this answer
add comment

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.

share|improve this answer
add comment

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.

share|improve this answer
    
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. –  Justin May 20 '11 at 19:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.