TransWikia.com

Unable to Update Map Element

Geographic Information Systems Asked by Bryan Alcazar on June 7, 2021

I’m trying to update my text elements, but after running script no changes occur and no error are triggered. Running suggested code triggered an error.

I need to update my title and date text box.

I used the suggested script and receive:

Runtime error 
Traceback (most recent call last):
File "<string>", line 72, in <module>
ImportError: No module named mapping

Here’s what I have so far:

# Import arcpy module
import arcpy

#Work Env
arcpy.env.workspace = "F:APPDATAGISMAPSProjectsPlanningRequestsBryan2018PlanningTeresita_careTest_File"

# Script arguments
Parcels = arcpy.GetParameterAsText(0)

Selection_type = arcpy.GetParameterAsText(1)
if Selection_type == '#' or not Selection_type:
    Selection_type = "NEW_SELECTION" # provide a default value if unspecified

Distance__value_or_field_ = arcpy.GetParameterAsText(2)
if Distance__value_or_field_ == '#' or not Distance__value_or_field_:
    Distance__value_or_field_ = "300 Feet" # provide a default value if unspecified

Distance__value_or_field___2_ = arcpy.GetParameterAsText(3)
if Distance__value_or_field___2_ == '#' or not Distance__value_or_field___2_:
    Distance__value_or_field___2_ = "500 Feet" # provide a default value if unspecified

Expression = arcpy.GetParameterAsText(4)
if Expression == '#' or not Expression:
    Expression = ""AIN" = '7050005016'" # provide a default value if unspecified

v300ft_shp = arcpy.GetParameterAsText(5)

v500ft_shp = arcpy.GetParameterAsText(6)

# Local variables:
#Parcel_Address = Parcels

#If layer already exist overwrite
arcpy.env.overwriteOutput=True

#Create Parcels layer
arcpy.MakeFeatureLayer_management("F:/APPDATA/GISMAPS/Projects/Planning/Requests/Bryan/2018/Planning/Teresita_care/Test_File/Parcels.shp","Parcels.lyr")


# Process: Select Layer By Attribute
arcpy.SelectLayerByAttribute_management("Parcels.lyr", Selection_type, Expression)

# identify the current map document

mxd = arcpy.mapping.MapDocument('CURRENT')

# identify the data frame
df = arcpy.mapping.ListDataFrames(mxd)[0]

# use the zoom to selected features method of the data frame to update the extent
df.zoomToSelectedFeatures ()

#Set Scale
df.scale = 3860

# Process: Buffer
arcpy.Buffer_analysis("Parcels.lyr", "F:/APPDATA/GISMAPS/Projects/Planning/Requests/Bryan/2018/Planning/Teresita_care/Test_File/samv300ft_shp", Distance__value_or_field_, "FULL", "ROUND", "NONE", "", "PLANAR")

#Import Symbology layer to buffer
arcpy.ApplySymbologyFromLayer_management ("samv300ft_shp", "F:/APPDATA/GISMAPS/Projects/Planning/Requests/Bryan/2018/Planning/Teresita_care/Test_File/Symbol_300ft.lyr")

# Process: Buffer (2)
arcpy.Buffer_analysis("Parcels.lyr", "F:/APPDATA/GISMAPS/Projects/Planning/Requests/Bryan/2018/Planning/Teresita_care/Test_File/samv500ft_shp", Distance__value_or_field___2_, "FULL", "ROUND", "NONE", "", "PLANAR")

#Import Symbology layer to buffer
arcpy.ApplySymbologyFromLayer_management ("samv500ft_shp", "F:/APPDATA/GISMAPS/Projects/Planning/Requests/Bryan/2018/Planning/Teresita_care/Test_File/Symbol_300ft.lyr")


import arcpy
import os
import sys
import mapping as m

# Folder containing MXD's 
folder = r'F:APPDATAGISMAPSProjectsPlanningRequestsBryan2018PlanningTeresita_careTest_FileTest_Script.mxd' 
arcpy.env.workspace = folder   

# Find and Replace text element 
find_elm = 'TEXT_ELEMENT' 
replace_elm = 'Text you want to replace find_elm'  
# Find all .mxd files in folder 
# replaces text element in mxd if it exists
for mapDoc in arcpy.ListFiles('*.mxd'):
    mxd = arcpy.mapping.MapDocument(os.path.join(folder, mapDoc))
    for elm in arcpy.mapping.ListLayoutElements(mxd, 'TEXT_ELEMENT'):
        if elm.text == find_elm:
            elm.text = replace_elm
            print 'Replaced {0} in {1}'.format(find_elm, mapDoc)
    mxd.save()
    del mxd  

One Answer

You may try something like the below code, please note its not tested:

import arcpy, os from arcpy 
import mapping as m  
# Folder containing MXD's 
folder = r'C:pathto_yourmapdocuments' 
arcpy.env.workspace = folder   

# Find and Replace text element 
find_elm = 'Text you want to find' 
replace_elm = 'Text you want to replace find_elm'  
# Find all .mxd files in folder 
# replaces text element in mxd if it exists
for mapDoc in arcpy.ListFiles('*.mxd'):
    mxd = arcpy.mapping.MapDocument(os.path.join(folder, mapDoc))
    for elm in arcpy.mapping.ListLayoutElements(mxd, 'TEXT_ELEMENT'):
        if elm.text == find_elm:
            elm.text = replace_elm
            print 'Replaced {0} in {1}'.format(find_elm, mapDoc)
    mxd.save()
    del mxd  

You can also use a wild card in the http://resources.arcgis.com/en/help/main/10.1/index.html#/ListLayoutElements/00s30000003w000000/]ListLayoutElements[/url

Answered by Manish Patel on June 7, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP