3

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.

1 Answer 1

6

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.

1
  • 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. May 7, 2014 at 0:36

Your Answer

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

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