2

My script works fine, but I am not able to export .pdf file from a report generated. This is my code:

import arcpy

inputFC = arcpy.GetParameterAsText(0)
outputFC = arcpy.GetParameterAsText(1)
matricula = arcpy.GetParameterAsText(2)

query = """ "MATRICULA" LIKE '%s'""" %matricula 

arcpy.env.workspace = "C:/Prueba/arcpy"
arcpy.MakeFeatureLayer_management(inputFC,"Tramos_LAT_layer")
arcpy.SelectLayerByAttribute_management("Tramos_LAT_layer","NEW_SELECTION",query)
arcpy.CopyFeatures_management("Tramos_LAT_layer",outputFC)

# Following I try to export report from outputFC

# RLF
plantilla = "PLANTILLA_INFORMES.rlf"

# PDF
pdf = "zz_salida_report.pdf"

# Exportamos Report
arcpy.mapping.ExportReport(outputFC,plantilla,pdf)

I also tested another option, I created a layer file, but it didn´t work either:

lyr = arcpy.mapping.Layer(outputFC)

arcpy.mapping.ExportReport(lyr,plantilla,pdf)

I have checked all post about this issue, although I don't understand why my script doesn't work.

  • Have you tried using full paths to point to PLANTILLA_INFORMES.rlf and also for the output zz_salida_report.pdf? The documented examples all use fully qualified paths - resources.arcgis.com/en/help/main/10.2/index.html#//… – Clubdebambos Feb 23 '17 at 13:08
  • The documentation also says it must reference a Layer or TableView object. A Layer object can either be a reference to a .lyr file or a layer in a map document. The outputFC should be in an mxd and a reference made to it. See the examples in the link above – Clubdebambos Feb 23 '17 at 13:25
  • Thank you so much. You are right, I have used full paths to point to "file".rlf and "file".pdf and it works !! I really appreciate your help. – Antonio J. Rguez Garrido Feb 23 '17 at 16:15
  • However, I still don't understand why didn't work it, because I used a workspace (arcpy.env.workspace = "C:/Prueba/arcpy"). Thanks – Antonio J. Rguez Garrido Feb 23 '17 at 16:19
  • Excellent, I have added it as an answer if you can give it a green tick of approval. I tried to find info for workspace and the tool but couldn't find any. It was only when I saw the examples with full paths that I thought that workspace might not work for the input and output of the tool – Clubdebambos Feb 23 '17 at 16:24
2

The documented examples for ExportReport use full paths for the report_layout_file and output_file parameters (2nd and 3rd parameters)

Change the code to reflect this

# RLF
plantilla = "full_path/PLANTILLA_INFORMES.rlf"

# PDF
pdf = "full_path/zz_salida_report.pdf"
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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