import arcpy #User defines tract number: tract=raw_input("Enter census tract number:") mxdPath="C:\\Path\\To\\Map.mxd" mxd=arcpy.mapping.MapDocument(mxdPath) #use "CURRENT" if running in ArcMap Python Window or as a tool #Get Lyr Files allLyrs=arcpy.mapping.ListLayers(mxd) for lyr in allLyrs: if lyr.name=="Target Tract": #must be one and only one layer called "Target Tract" in your mxd's TOC targetLyr=lyr #if tract number is stored as a number use this line: (and remove the other one) targetLyr.definitionQuery='"Tract_Num" = '+str(tract) #change Tract_Num to name of tract field #if tract number is stored as a string/text use this line: (and remove the other one) tractsLyr.definitionQuery='"Tract_Num" = \''+str(tract)+'\'' #change Tract_Num to name of tract field cursor=arcpy.SearchCursor(targetLyr) for row in cursor: density=row.DP0010001/row.sq_mile_1 #Get layout elements: elemList=arcpy.mapping.ListLayoutElements(mxd) #Find title element: for elem in elemList: if elem.name=="Title": #Make sure you manually set the Element Name to "Title" (see attached screenshot) titleElem=elem #Edit text: titleElem.text="Census tract: "+str(tract)+" - Density: "+str(density) #zoom to selected features df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] df.extent = targetLyr.getExtent(True) mxd.save() #remove this line if you're using "CURRENT" MapDocument arcpy.RefreshActiveView() del mxd, df, row, cursor, lyr, targetLyr, allLyrs print "executed successfully"
titleElem.text="Census tract: "+str(tract)+" - Density: "+str(density)
#Edit text: titleElem.text="Census tract: "+str(tract)+" - "Density: "+str(density) mxd.save() del titleElem, mxd
cursor=arcpy.da.SearchCursor(lyr) for row in cursor: #there should only be one row in your layer density=row.density del row,cursor mxd = arcpy.mapping.MapDocument("C:\\Path\\To\\Map.mxd") #Get layout elements: elemList=arcpy.mapping.ListLayoutElements(mxd) #Find title element: for elem in elemList: if elem.name=="Title": #Make sure you manually set the Element Name to "Title" (see attached screenshot) titleElem=elem #Edit text: titleElem.text="Census tract: "+str(tract)+" - Density: "+str(density) mxd.save() del titleElem, mxd
#user selects tract, Select by Attribute tool runs arcpy.MakeFeatureLayer_management("plano_tract", "plano_tract_lyr") arcpy.SelectLayerByAttribute_management("plano_tract_lyr", "NEW_SELECTION", "\"Tract_Number\" = "+ tract) arcpy.CopyFeatures_management("plano_tract_lyr", "plano_tract_select") #add field arcpy.AddField_management("plano_tract_select", "density", "DOUBLE") #calculate field arcpy.CalculateField_management("plano_tract_select", "density", "[DP0010001] / [sq_mile_1]", "VB", "") print "executed successfully" #zoom to selected features df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] lyr = arcpy.mapping.ListLayers(mxd, "plano_tract_select", df) [0] df.extent = lyr.getExtent(True) arcpy.RefreshActiveView() print "zoomed to layer"
import arcpy mxd = arcpy.mapping.MapDocument("C:\\Path\\To\\Map.mxd") #Get layout elements: elemList=arcpy.mapping.ListLayoutElements(mxd) #Find title element: for elem in elemList: if elem.name=="Title": #Make sure you manually set the Element Name to "Title" (see attached screenshot) titleElem=elem #Edit text: titleElem.text="This is the Title!" mxd.save() del titleElem, mxd
import arcpy fc="C:\\Path\\To\\FeatureClass.shp" cursor=arcpy.SearchCursor(fc) for row in cursor: if row.Field1=="Taret": #i'm not sure how you wanted to pick a record, but this would find where Field1 is "Target" targetInteger=row.Field2 #change 'Field2' to your integer data field break #ends for loop titleText="This is Title number: "+str(targetInteger) del row,cursor #Then add the code above to edit the title element in the mxd.
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.