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'm developing an arcpy addin with ArcMap 10.2 that outputs a feature layer based on user input. How can I display attributes from this layer in a MessageBox or other reporting mechanism? I don't want to enable data driven pages, so dynamic tables don't seem to be an option. I'm sure there's an easy solution out there. Ideas?

Thanks! Katie

share|improve this question

1 Answer 1

up vote 6 down vote accepted

pythonaddins is limited in reporting and displaying attributes to users. pythonaddins is mainly a way to offer python developers a way to interact with user events. That being said the main mechanism for a developer to display messages to the user is through pythonaddins.MessageBox.

This function takes in a message formatted as a string as the first argument, a title, and a mb_type code which refers to the type of message box, i.e. OK only, Yes/No, Retry/Cancel, etc. You could feed in the attributes you would like to report in a formatted string as the first argument to pythonaddins.MessageBox() to report back to the user.

Here is a real quick (and sort of sloppy string formatting) example of feeding in an extent object and reporting this info back to the user, if you would like more code please let me know:

            rasterObject = arcpy.Raster(inRaster)
            rasterSpatialRef = rasterObject.spatialReference
            rasterExtent = arcpy.Describe(rasterObject).extent              

            hillShadeBoolean = pythonaddins.MessageBox('\t\t' + 'Top: ' + str(rasterExtent.YMax) + '\n\n' +
                                                       'Left: ' + str(rasterExtent.XMin) + '\t\t\t' +
                                                       'Right: ' + str(rasterExtent.XMax) + '\n\n' + 
                                                       '\t\t' + 'Bottom: ' + str(rasterExtent.YMin) + '\n\n' +
                                                       'Spatial Reference: ' + rasterSpatialRef.name + '\n' +
                                                       'Units: ' + rasterSpatialRef.linearUnitName + '\n\n' +
                                                       'Would you like to create a hillshade for this raster?\n',
                                                       'Raster Extent',
                                                       4)

pythonaddins is really a python module of only five functions although you are limited in what you can do it can still be quite powerful. Click here for more info from ESRI's documentation on the pythonaddins module.

share|improve this answer
    
I'll have to look at that one.. I use PyWin, mostly because it comes with a good editor with some InteliSense but partly because it has a basic message box. The pythonaddins message box looks more flexible. –  Michael Miles-Stimson May 7 at 0:36
    
Thank you! That's perfect. –  user29358 May 7 at 16:04

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.