Obtaining a useful report from ArcMap can be a long and complicated process that needs a script in order to be executed properly. Using the script from this article, simple reports can easily made from any set of features that you select!
This is another VBA module that will take a list of features that you currently have selected and export a semicolon-delimited list of the following attributes of each feature:
You’ll find the results waiting for you in a text file once you run the report. Ready to give it a try? Let’s get the module up and running.
The code for this module is below. Copy and paste it into the module and save it, but continue reading for configuration information.
Private Const FIELDNAME As String = "SubtypeCode"
Private Const FILENAME As String = "C:\Temp\featureAttributeExport.txt"
Public Sub GetFeatureAttributes()
Dim fso As Scripting.FileSystemObject
Set fso = New Scripting.FileSystemObject
Dim writer As TextStream
Set writer = fso.CreateTextFile(FILENAME, True)
writer.WriteLine "FEATURECLASS;OBJECTID;" & FIELDNAME
Dim mxdoc As IMxDocument
Set mxdoc = ThisDocument
Dim map As IMap
Set map = mxDoc.FocusMap
Dim eSel As IEnumFeature
Set eSel = map.FeatureSelection
Dim eSetup As IEnumFeatureSetup
Set eSetup = eSel
eSetup.AllFields = True
Dim f As IFeature
Set f = eSel.Next
While Not f Is Nothing
writer.WriteLine f.Class.AliasName & ";" & f.OID & ";" & f.Value(f.Fields.FindField(FIELDNAME))
Set f = eSel.Next
Debug.Print "Results written to " & FILENAME
Before you go off and run the script as-is, be sure to configure the values first. The first two lines define constants called FIELDNAME and FILENAME. Change the values inside the parentheses to customize the script to your liking:
FIELDNAME corresponds to the name of the database field that you want to export in addition to the OID and the feature class name. If you’re unsure of the exact name, right-click a feature layer and choose Properties, then go to the Fields tab to see exact field names.
Importantly, if you’re reporting on data from more than one feature class, be sure that the field name applies to every class in your selection! If this is not the case, the script will throw an error or you’ll see blank data. Unless you’re using a consistently-named field such as a feature's subtype code, you should try to only select one layer at a time to run this script. A quick way to accomplish this is to right click a layer, and choose Selection → Make This The Only Selectable Layer.
FILENAME corresponds to the exact location the script will place the file when you run it. This can be left at its default value if desired. Look at this value to see exactly where to look for your text file. Please note that this script will overwrite the text file from any previous run, so if you are running multiple exports, be sure to save the text file elsewhere after each run.
After you tweak these two settings to your liking, you can run the script! Switch over to ArcMap and use the Select Tool to grab the features you want. Then switch back over to the Visual Basic Editor and press the play button.
That’s it! Your shiny new export will be located in the configurable directory location at the top of the script.