Can an InMemory feature class/table be an ExportReport source?

1862
3
10-09-2013 04:23 AM
RichardFairhurst
MVP Honored Contributor
I am creating a python script where I want a geoprocess that uses the inmemory workspace to create a feature class or table to serve as the source data for an RLF report file.  The arcpy ExportReport method help says the data source has to be in a .mxd or .lyr file to work properly.  Does that mean that I cannot use an inmemory output with that function?  Is there a way to associate an inmemory output with one of those file types?

It I have to output the data to disk, is there a best practice for authoring a tool that would create an output feature class/table to an on disk workspace path that will run on multiple user installations?  Each user will have ArcGIS installed on their local machine and should have the Default.gdb in their local C: drive standard path.  Is the Default.gdb the best place to create an on disk output for this kind of tool and are there any built-in ArcGIS path variables that would assist in accessing it without building the path for each user with code?
0 Kudos
3 Replies
KimOllivier
Regular Contributor II
I despaired trying to get reports to work, the output was too complex.
So I switched to exporting to a spreadsheet using the Excel COM interface and a template.
Another radical alternative might be to export directly to a PDF using reportlab.
Reportlab has an easy module to pour data into tables and graphs.
Or maybe use matplotlib?
0 Kudos
RichardFairhurst
MVP Honored Contributor
I despaired trying to get reports to work, the output was too complex.
So I switched to exporting to a spreadsheet using the Excel COM interface and a template.
Another radical alternative might be to export directly to a PDF using reportlab.
Reportlab has an easy module to pour data into tables and graphs.
Or maybe use matplotlib?


That is very disappointing, and I know you are not someone to give up easily.  I will call tech support on this then.  I have a report design they have already helped me with and will add this to the support call.
0 Kudos
RichardFairhurst
MVP Honored Contributor
I got the answer to my question from ESRI tech support.  You can export a report from an in_memory feature class created using any standard geoprocessing tool, like Dissolve or Copy Features.  The trick is to first use the Make Feature Layer on the Feature Class and then add the layer to a virtual map before running the ExportReport method.

In the code sample below assume that PARCELS_Dissolve is defined as a real in_memory Feature Class and that PARCELS_Dissolve_Layer is a layer name string:

arcpy.MakeFeatureLayer_management(PARCELS_Dissolve, PARCELS_Dissolve_Layer)

lyr = arcpy.mapping.Layer(PARCELS_Dissolve_Layer)

arcpy.mapping.ExportReport(lyr,
                           r"C:\Mailing_Labels.rlf",
                           r"C:\Mailing_Labels.pdf",
                           "ALL")

The ExportReport only works when it is given a layer that has been added to a map.  Fortunately the arcpy.mapping.Layers method appears to be adding the layer to a virtual mxd since I never specified any actual mxd in my code.  The code can run completely from Idle.
0 Kudos