AnsweredAssumed Answered

How export files pdf into multiple folders with the same name?

Question asked by vqb on Mar 8, 2017
Latest reply on Mar 9, 2017 by iamurray

I am not an expert on Python scripting but I undertand a few concepts about it.


I made a script that export multiple individual mxd and pdf with a specific same name, also on my script, I can make multiple folders with the same name from mxd, but I dont know how put all the files on the same folders made.


Is it possible export all the files mxd, pdf which has the same name into folders with the same name?



This my script:


import arcpy, os
import arcpy
from arcpy import env


wsp = r"D:\SedesolVQB\Proyectos\proyecto_PythonEjercicio\PracticasPython.mdb"
Shp = 'Estados'
pageNameField = "CVE_ENT" #<----this is the main field comun to save on folders, mxs and pdf


mxdSalida = r"D:\SedesolVQB\Proyectos\proyecto_PythonEjercicio\Mapas finales"
mxdOrigen = r"D:\SedesolVQB\Proyectos\proyecto_PythonEjercicio\Mxd\Practicas.mxd" #<---This is the maind mxd


#To Make diferent folder from pageNameField
with arcpy.da.SearchCursor(Shp,(pageNameField)) as cursor:
for folder, in cursor:
os.makedirs(os.path.join(mxdSalida, str(folder))) 


#Export to pdf file from each mxd and save mxd indivuals
for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
mxd.dataDrivenPages.currentPageID = pageNum
pageName = mxd.dataDrivenPages.pageRow.getValue(pageNameField)

arcpy.mapping.ExportToPDF(mxd, os.path.join(mxdSalida, str(pageName) + ".pdf"))
mxdNombre = os.path.join(os.path.join(mxdSalida, str(pageName)),str(pageName)+".mxd")


print u"Exportando página {0} de {1}".format(str(mxd.dataDrivenPages.currentPageID), str(mxd.dataDrivenPages.pageCount))
print u"Guardando una copia de:{0}".format(str(pageName))




The result is something like this:


D:\SedesolVQB\Proyectos\proyecto_PythonEjercicio\Mapas finales\01\01.mxd\\---> 01.pdf (Is shown outside)

D:\SedesolVQB\Proyectos\proyecto_PythonEjercicio\Mapas finales\02\02.mxd\\---> 02.pdf (Is shown outside)

D:\SedesolVQB\Proyectos\proyecto_PythonEjercicio\Mapas finales\03\03.mxd\\---> 03.pdf (Is shown outside)


However, the file pdf remains outside from the folders, what I need all the files mxd and pdf into de the folders whit the same name.