I am trying to convert regular python script to toolbox. This is the regular code which works:
import arcpy
strOutpath = "C:\Users\name\Desktop\New Folder"
mxd = arcpy.mapping.MapDocument("CURRENT")
for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
mxd.dataDrivenPages.currentPageID = pageNum
pageorder = mxd.dataDrivenPages.pageRow.BR
pageindex = mxd.dataDrivenPages.pageRow.KARTA
pdfname = pageorder + "-" + pageindex + ".pdf"
arcpy.mapping.ExportToPDF(mxd, strOutpath + pdfname, resolution="300dpi", image_compression="Adaptive", jpeg_compression_quality="85", colorspace="RGB", picture_symbol="VECTORIZE_BITMAP")
del mxd
And this is the my example for script to input as script for toolbox:
import arcpy
strOutpath = arcpy.GetParameterAsText(0)
mxd = arcpy.GetParameterAsText(1)
for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
mxd.dataDrivenPages.currentPageID = pageNum
pageorder = arcpy.GetParameterAsText(2)
pageindex = arcpy.GetParameterAsText(3)
pdfname = pageorder + "-" + pageindex + ".pdf"
arcpy.mapping.ExportToPDF(mxd, strOutpath + pdfname, resolution="300dpi", image_compression="Adaptive", jpeg_compression_quality="85", colorspace="RGB", picture_symbol="VECTORIZE_BITMAP")
As parameters, I entered this:
strOutpath = FOLDER
mxd = ArcMap document
pageorder = field
pageindex = field
And when I try to input the values, I get empty fields. There is clearly something wrong with the second code and input variables, but I don't know what.
EDIT:
When I edit my code, based on the comment ArtWork21 gave, when only output folder and mxd are user-generated, this is the code:
import arcpy
strOutpath = arcpy.GetParameterAsText(0)
mxd = arcpy.GetParameterAsText(1)
for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
mxd.dataDrivenPages.currentPageID = pageNum
pageorder = mxd.dataDrivenPages.pageRow.BR
pageindex = mxd.dataDrivenPages.pageRow.KARTA
pdfname = pageorder + "-" + pageindex + ".pdf"
arcpy.mapping.ExportToPDF(mxd, strOutpath + '\\' + pdfname, resolution="300dpi", image_compression="Adaptive", jpeg_compression_quality="85", colorspace="RGB", picture_symbol="VECTORIZE_BITMAP")
del mxd
This is the error:
Traceback (most recent call last):
File "C:\Users\name\Desktop\script.py", line 4, in <module>
for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
AttributeError: 'unicode' object has no attribute 'dataDrivenPages'
Failed to execute (Script).
And these are my variables:
So, now I now I am just trying zo get the last one script to work, where I only enter output folder, and input mxd.