i am building a script, most of which i found on here, that exports my data driven pages as mxds. I need it to save the mxd by a specific attribute in the shapefile and am running into an error when trying with two attributes. It works with 1 attribute but i can't combine them.

import arcpy  
a = 'L_NAME'

b = 'PAR_NUM'

c = a + b

mxd = arcpy.mapping.MapDocument(r"C:\Users\jcarl\Desktop\Presentation\P_Litwin.mxd")  
ddp = mxd.dataDrivenPages  
for pageNum in range(1, ddp.pageCount + 1):  
   ddp.currentPageID = pageNum  
   print "Saving %s.mxd" %(ddp.pageRow.getValue(c))  
   mxd.saveACopy(r"C:\Users\jcarl\Desktop\Presentation\MXD\\" + ddp.pageRow.getValue(c) + ".mxd")  
  del mxd  

like i said it works if i just use a, or b, but not together. I am trying to export as attribute (attribute).

1 Answer 1


You need to get the value from column 'L_NAME' and 'PAR_NUM' seperately. Currently your code ddp.pageRow.getValue(c) is looking for a column called 'L_NAMEPAR_NUM'. Delete the lines a = 'L_NAME', b = 'PAR_NUM', and c = a + b.

After ddp.currentPageID = pageNum, try this:

a = ddp.pageRow.getValue('L_NAME')
b = ddp.pageRow.getValue('PAR_NUM')
c = a + b

print "Saving %s.mxd" %(c)
mxd.saveACopy(r"C:\Users\jcarl\Desktop\Presentation\MXD/" + c + ".mxd")

Your Answer

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

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