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.

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Feb 23, 2017 at 12:45
5
  • 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#//… Commented Feb 23, 2017 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 Commented Feb 23, 2017 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. Commented Feb 23, 2017 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 Commented Feb 23, 2017 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 Commented Feb 23, 2017 at 16:24

1 Answer 1

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"
answered Feb 23, 2017 at 16:21

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.