I am trying to export data driven pages using Arcpy butmxd.dataDrivenPages.pageCount return 0.
Here what i am doing... first I am replacing the data source of the layer then refreshing the data driven pages and after that using for loop trying to export data driven pages in jpeg.
Here what I am trying..
<SPAN class="" style="color: var(--blue-800); border: 0px; font-weight: inherit; font-size: 13px;"><SPAN style="background-color: #e4e6e8;">lyr.replaceDataSource(path_of_data_source, "SHAPEFILE_WORKSPACE", "data_source_name")
</SPAN>mxd.dataDrivenPages.refresh()
for</SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;"> pageNum </SPAN><SPAN class="" style="color: var(--blue-800); border: 0px; font-weight: inherit; font-size: 13px;">in</SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;"> range</SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;">(</SPAN><SPAN class="" style="color: var(--red-800); border: 0px; font-weight: inherit; font-size: 13px;">1</SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;">,</SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;">mxd</SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;">.</SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;">dataDrivenPages</SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;">.</SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;">pageCount </SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;">+</SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;"> </SPAN><SPAN class="" style="color: var(--red-800); border: 0px; font-weight: inherit; font-size: 13px;">1</SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;">):</SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;"> arcpy</SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;">.</SPAN><SPAN class="" style="color: #2b91af; border: 0px; font-weight: inherit; font-size: 13px;">AddMessage</SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;">(</SPAN><SPAN class="" style="color: var(--red-800); border: 0px; font-weight: inherit; font-size: 13px;">"Image "</SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;">+</SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;"> str</SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;">(</SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;">pageNum</SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;">))</SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;"> mxd</SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;">.</SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;">dataDrivenPages</SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;">.</SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;">currentPageID </SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;">=</SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;"> pageNum arcpy</SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;">.</SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;">mapping</SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;">.</SPAN><SPAN class="" style="color: #2b91af; border: 0px; font-weight: inherit; font-size: 13px;">ExportToJPEG</SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;">(</SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;">mxd</SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;">,</SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;"> directory_env </SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;">+</SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;"> </SPAN><SPAN class="" style="color: var(--red-800); border: 0px; font-weight: inherit; font-size: 13px;">"\Output_Images/"</SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;"> </SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;">+</SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;"> str</SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;">(</SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;">pageNum</SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;">)</SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;"> </SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;">+</SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;"> </SPAN><SPAN class="" style="color: var(--red-800); border: 0px; font-weight: inherit; font-size: 13px;">".jpeg"</SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;">,</SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;"> resolution </SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;">=</SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;"> </SPAN><SPAN class="" style="color: var(--red-800); border: 0px; font-weight: inherit; font-size: 13px;">300</SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;">)</SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;"></SPAN><SPAN class="" style="color: var(--blue-800); border: 0px; font-weight: inherit; font-size: 13px;">del</SPAN><SPAN class="" style="color: var(--black-750); border: 0px; font-weight: inherit; font-size: 13px;"> mxd</SPAN>