Move Extent Locator Display python error

المشرف العام

Administrator
طاقم الإدارة
I am trying to use ESRIs generated python code to move around my Extent Data Frame based on location of my Main Line shapefile, as to not have the Data Frame over top of the main line when developing a data driven page set up.

When attempting I receive this error:

: Failed to execute. Parameters are not valid.ERROR 000725: Output Feature Class: Dataset in_memory\tempFC already exists.Failed to execute (CopyFeatures).Failed to execute (MoveLocatorMap).ESRI's Code below:

import arcpy, os, sys#Python functiondef findLocation(corner, mainDF, locatorDF, polyLayer):#The following funtion creates a polygon feature for each of the 4 corners of the#main data frame. The X,Y coordinates are calculated using the main data frame's#extent as well as the proportional distances along the main data frame's extent. For#example, in the figure below, the X value is simply the data frame's XMax value. But#the Y value is the YMax value minus the proportional distance of the locator data#frames height compared to the main data frame's height. We know the total Y distance#(YMax - YMin) and we know the height of each data frame (elementHeight) so we can#multiply the Y delta by the percent of the locator data frame to the main dataframe#to get:# Y = mainDF.extent.YMax - ((mainDF.extent.YMax - mainDF.extent.YMin) * (locatorDF.elementHeight / mainDF.elementHeight))# +----+----------+----+# | | | |# +----+ +----+ = 1, then there is a conflict and the next location will be tested.polyCursor = arcpy.SearchCursor(polyLayer)polyRow = polyCursor.next()count = 0while polyRow: count = count + 1 polyRow = polyCursor.next()#Clear the selectionarcpy.SelectLayerByAttribute_management(polyLayer, "CLEAR_SELECTION") #Delete the temporary shapefile.arcpy.Delete_management(r"in_memory\tempFC")#Return the count value to main part of script to determine placement of locator map.return count#*******************************#MAIN SCRIPT STARTS HERE#*******************************#read input parametermxdPath = os.path.join(sys.path[0], "LigSWIndex.mxd")#Reference map documentmxd = arcpy.mapping.MapDocument(mxdPath)#reference data framesmainDF = arcpy.mapping.ListDataFrames(mxd, "MainDF")[0]locatorDF = arcpy.mapping.ListDataFrames(mxd, "LocatorDF")[0]#create PDF and check to see if it already existsfinalPDF = os.path.join(sys.path[0], "ligonier_stormwater.pdf")if os.path.exists(finalPDF): os.remove(finalPDF)outPDF = arcpy.mapping.PDFDocumentCreate(finalPDF)#Loop through each Data Driven Page#for pageNum in range(1, 10): # Loop through just 10 records for faster testingfor pageNum in range(1, mxd.dataDrivenPages.pageCount + 1): mxd.dataDrivenPages.currentPageID = pageNum print "Page " + str(pageNum) + " of " + str(mxd.dataDrivenPages.pageCount) arcpy.AddMessage("Page " + str(pageNum) + " of " + str (mxd.dataDrivenPages.pageCount))#Reference the index layer that uses DDP query definitionfor layer in arcpy.mapping.ListLayers(mxd, "", mainDF): if layer.name == "Main Line": polyLayer = layer#Place locator data frame - priority location is: SW, SE, NW, NE. If all conflict,#the default is the SW corner.if findLocation("SW", mainDF, locatorDF, polyLayer) == 0: locatorDF.elementPositionX = 1 locatorDF.elementPositionY = 1 txtSW.text = "SW = True"elif findLocation("SE", mainDF, locatorDF, polyLayer) == 0: locatorDF.elementPositionX = 5.5 locatorDF.elementPositionY = 1 txtSE.text = "SE = True"elif findLocation("NW", mainDF, locatorDF, polyLayer) == 0: locatorDF.elementPositionX = 1 locatorDF.elementPositionY = 6 txtNW.text = "NW = True"elif findLocation("NE", mainDF, locatorDF, polyLayer) == 0: locatorDF.elementPositionX = 5.5 locatorDF.elementPositionY = 6 txtNE.text = "NE = TRUE"else: locatorDF.elementPositionX = 1 locatorDF.elementPositionY = 1 txtSW.text = "NW - DEFAULT"tempPDF = os.path.join(sys.path[0], "temp.pdf")arcpy.mapping.ExportToPDF(mxd, tempPDF)outPDF.appendPages(tempPDF)os.remove(tempPDF)outPDF.saveAndClose()os.startfile(finalPDF)del mxd

أكثر...
 
أعلى