POST
|
http://www.willcogis.org/website2014/gis/Data/1st_District_B2.zip Here's a link to the mxd. Thanks for taking a look. I checked your page and downloaded the newer version you had there. I ran it again and pictures (.JPG in my case) are still not included in the list of broken sources. You have 'raster.jpg' included in the valid extension list, but this is apparently different than a picture element (.JPG).
... View more
01-24-2017
11:11 AM
|
0
|
0
|
2485
|
POST
|
@Rebecca This is a great addin. I just tried it and It works fine for listing broken source data. But, my problem is, I need to list broken picture elements. That's something it didn't do? I've been trying to use this code (below) from Esri. But, it's not working due to the fact, I think, that the mxd it's referencing is missing the pictures (our file directory was recently changed, so the picture path is broken). It runs with no errror and 1st_District_B3.mxd is saved in the folder, but no changes are made. import arcpy
mxd = arcpy.mapping.MapDocument(r'R:\AtlasMaps\ATLAS_MAPS_17\New folder\1st_District_B2.mxd')
for elm in arcpy.mapping.ListLayoutElements(mxd, "GRAPHIC_ELEMENT", "*logo*"):
if elm.name == 'County-logo-1x1Small':
elm.sourceImage = r'P:\Images\County-logo.JPG'
print '{} changed'.format(elm.sourceImage)
mxd.saveACopy(r'R:\AtlasMaps\ATLAS_MAPS_17\New folder\1st_District_B3.mxd')
del mxd Below's a printscn of the document with the broken picture element source. It's giving you the path where the JPEG once lived. It's now in the P:\Images folder. Are you aware of a way to list and repair broken source picture elements? Thanks in advance.
... View more
01-24-2017
09:07 AM
|
0
|
17
|
2485
|
POST
|
Thanks Rebecca. Here it is. import arcpy
from arcpy import env
import os
arcpy.env.overwriteOutput = True
# set path to relvant folder
arcpy.env.workspace = Workspace = arcpy.GetParameterAsText(0)
Output = arcpy.GetParameterAsText(1)
oldText = arcpy.GetParameterAsText(2)
oldList = oldText.split(', ')
newText = arcpy.GetParameterAsText(3)
newList = newText.split(', ')
# list the mxds of the workspace folder
for mxdname in arcpy.ListFiles("*.mxd"):
print mxdname
# set the variable
mxd = arcpy.mapping.MapDocument(Workspace + "\\" + mxdname)
# replace elements that occur in the map document
for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
counter = 0
for text in oldList:
if text in elm.text:
elm.text = elm.text.replace(text, newList[counter])
print '{} changed'.format(elm.text)
counter = counter + 1
else:
counter = counter + 1
for elm in arcpy.mapping.ListLayoutElements(mxd, ""):
counter = 0
for text in oldList:
if text in mxd.title:
mxd.title = elm.text.replace(text, newList[counter])
counter = counter + 1
else:
counter = counter + 1
# move the mxd.saveACopy outside of the if loop so a copy is saved even it does not meet the condition of the if loops
mxd.saveACopy(os.path.join(Output + "\\" + mxdname))
# do not include this delete statement inside the above loop or it will delete the mxd object inside the loop. Make sure to dedent.
del mxd
... View more
01-11-2017
10:44 AM
|
1
|
0
|
303
|
POST
|
Curtis, I would have but More > Syntax highlighter isn't available on the toolbar if it's not the original post? I came across this problem before. The toolbar in the subsequent replies offers only half the tools originally available. Am I missing something?
... View more
01-11-2017
07:15 AM
|
0
|
2
|
1903
|
POST
|
I was able to finish the Tool based on split() and some extra help from an ESRI tech. Additionally, there was a 'counter' variable that was used to match the oldText with the newText. There's no limit on the amount of text, but the words from both oldText and newText have to correspond with each other in the right order. If not, the wrong element will be replaced. Thanks all for the help.
... View more
01-10-2017
08:57 AM
|
2
|
4
|
1903
|
POST
|
Would split() go inside the first if loop of the script?
... View more
01-05-2017
08:54 AM
|
0
|
1
|
1903
|
POST
|
@Darren Thanks, but won't that limit the user to only that text as the input? I was looking for a war to keep the parameters completely general so the tool can be used for any sort of updates in a map document.
... View more
01-04-2017
02:06 PM
|
0
|
1
|
1903
|
POST
|
Hi, I have a working ArcMap script tool called Update Map Elements that updates text and numbers in ArcMap documents. It has four parameters; Workspace, Output, oldText and newText. Workspace is where the input folder goes. Output is the save-to folder. OldText is the text string to be replaced by the newText text string (Red Branch changes to Blue Branch). My problem is: how can I have multiple string values? So, in the above parameters I specify the Red Branch string value to be replaced by Blue Branch. What if I wanted to have a bunch of string values--such as Red Branch, 600, Violet (oldText) and the corresponding newText values Blue Branch, 800, Green? I have a feeling I add index positions to the values within the script, but I'm not sure how. I've had a look at this though I'm not sure it's the right approach: SetParameterAsText—Help | ArcGIS for Desktop Here's the script behind the Update Map Elements tool: #set path to relevant folder
import arcpy
from arcpy import env
import os
arcpy.env.overwriteOutput = True
# set path to relvant folder
arcpy.env.workspace = Workspace = arcpy.GetParameterAsText(0)
Output = arcpy.GetParameterAsText(1)
oldText = arcpy.GetParameterAsText(2)
newText = arcpy.GetParameterAsText(3)
# list the mxds of the workspace folder
for mxdname in arcpy.ListFiles("*.mxd"):
print mxdname
# set the variable
mxd = arcpy.mapping.MapDocument(Workspace + "\\" + mxdname)
# replace '2016' that occurs in the title of document
for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
if oldText in elm.text:
elm.text = elm.text.replace(oldText, newText)
print '{} changed'.format(elm.text)
for elm in arcpy.mapping.ListLayoutElements(mxd, ""):
if oldText in mxd.title:
mxd.title = elm.text.replace(oldText, newText)
# move the mxd.saveACopy outside of the if loop so a copy is saved even it does not meet the condition of the if loops
mxd.saveACopy(os.path.join(Output + "\\" + mxdname))
# do not include this delete statement inside the above loop or it will delete the mxd object inside the loop. Make sure to dedent.
del mxd Thanks in advance.
... View more
01-03-2017
02:24 PM
|
0
|
11
|
5051
|
POST
|
Thanks Asrujit, So, generally speaking, you can't write to an SDE without administrative rights?
... View more
12-12-2016
11:52 AM
|
0
|
1
|
1213
|
POST
|
I have no control over the locks, apparently. After right clicking the feature class within the feature dataset, 'locks' is grayed out. Here are the above images made larger:
... View more
12-12-2016
11:44 AM
|
0
|
3
|
1213
|
POST
|
Sorry, my pseudocode is misleading. Let me clarify a bit more. I’m trying to copy a dataset from a local gdb to an sde. This dataset already exists in the sde—I just need to update it with the dataset from the local gdb. There’s a schema lock error. I don’t have the database open and the ‘Jared to plainfield.sde’ version used in this script is a copy of the main sde called ‘ims to Plainfield’. But, I’m not the administrator and surely there are other GIS people in the building using the sde. I’m only using the ‘Jared’ version to practice run this script, then I want to use it on the ‘ims to Plainfield.sde’.
... View more
12-12-2016
10:58 AM
|
0
|
6
|
1213
|
POST
|
Thanks Darren. I scrapped that script any tried arcpy.Copy_management. Basically, I'm trying to replace a feature dataset within an sde (here: plainfield.sde) with a dataset from a local gdb, as the features change weekly. The rewritten script below gets an error in the part of the script that attempts to copy from the local gdb (E911WeeklyUpdate.gdb\MGU_Will) to the plainfield.sde. Can you write to an sde? I haven't read anywhere that you can't.
... View more
12-12-2016
08:47 AM
|
0
|
1
|
1213
|
POST
|
Every script I've tried isn't able to copy the feature dataset in the top image to the bottom feature dataset (in an SDE). It's probably something simple, but is there a known function for this? I can't change anything in the SDE as I don't have administrative rights to it. I've tried Copy_management. But, here the in_data and out_data variables must have the same file extension to work properly. I've also tried CopyFeatures_management. Here's the syntax and error message for that: # Import modules
import os
import arcpy
# set workspace
env.workspace = r"T:\Departments\E911\Transfer Files\E911WeeklyUpdate\E911WeeklyUpdate.gdb"
#create a list of feature classes in the current workspace
fclist = arcpy.ListFeatureClasses()
#copy each feature class to a fgdb
for fc in fclist:
fcdesc = arcpy.Describe(fc)
arcpy.CopyFeatures_management(fc, os.path.join("Database Connections\
Jared to plainfield.sde\gisedit.DBO.MGU_Will", fcdesc.basename))
... View more
12-09-2016
02:24 PM
|
0
|
11
|
3502
|
POST
|
I have three consecutive scripts that 1) update features in a map, 2) zip them, then copy them to a new folder, 3) append a .txt file to the zip. But, I can't quite grasp how to run all of them in order. I ran RemoveAddLayer.py assuming I was calling the other two scripts correctly. There was an error(s) (see very bottom). ###RemoveAddLayer.py###
import arcpy
import os
from arcpy import env
#import functions
import ZipFiles
import Append2Zip
arcpy.overwriteOutput = True
env.workspace = r"Database Connections\ims to plainfield.sde\gisedit.DBO.MGU_Will"
#set path to mxd
mxd = arcpy.mapping.MapDocument(r"Z:\Jared\Data_Request.mxd")
#reference the dataframe
for df in arcpy.mapping.ListDataFrames(mxd):
print df
#reference the layers to be removed
for lyr in arcpy.mapping.ListLayers(mxd, "gisedit.DBO.Address_Points", df):
arcpy.mapping.RemoveLayer(df, lyr)
print lyr
for lyr in arcpy.mapping.ListLayers(mxd, "gisedit.DBO.Street", df):
arcpy.mapping.RemoveLayer(df, lyr)
print lyr
#reference the layers to be added
addLayer = arcpy.mapping.Layer(r"Database Connections\ims to plainfield.sde\gisedit.DBO.MGU_Will\gisedit.DBO.Address_Points")
arcpy.mapping.AddLayer(df, addLayer, "TOP")
print addLayer
addLayer = arcpy.mapping.Layer(r"Database Connections\ims to plainfield.sde\gisedit.DBO.MGU_Will\gisedit.DBO.Street")
arcpy.mapping.AddLayer(df, addLayer, "TOP")
print addLayer
#delete old files
if arcpy.Exists("WillCounty_AddressPoint"):
arcpy.Delete_management("WillCounty_AddressPoint")
if arcpy.Exists("WillCounty_Street"):
arcpy.Delete_management("WillCounty_Street")
#address points variables to be copied/saved in folder
inFeatures = "gisedit.DBO.Address_Points"
outLocation = r"Z:\Jared\Python Scripts\Data"
outFeatureClass = "WillCounty_AddressPoint"
#execute and copy/save in folder. FeatureClassToFeatureClass_conversion syntax (in_features, out_path, out_name,
#{where_clause}, {field_mapping}, {config_keyword})
arcpy.FeatureClassToFeatureClass_conversion(inFeatures, outLocation, outFeatureClass)
print "finished Address_Point.shp"
#variables to be copied/saved in folder
inFeatures = "gisedit.DBO.Street"
outLocation = r"Z:\Jared\Python Scripts\Data"
outFeatureClass = "WillCounty_Street"
#execute and copy/save in folder. FeatureClassToFeatureClass_conversion syntax (in_features, out_path, out_name,
#{where_clause}, {field_mapping}, {config_keyword})
arcpy.FeatureClassToFeatureClass_conversion(inFeatures, outLocation, outFeatureClass)
print "finished Street.shp"
del mxd
if __name__ == '__main__':
path = r"Z:\Jared\Python Scripts\Data"
out_path = r"W:\Data"
ZipShapes(path, out_path) ###ZipFiles.py
import arcpy
import os
from arcpy import env
from os import path as p
import zipfile
def ZipShapes(path, out_path):
arcpy.env.workspace = path
shapes = arcpy.ListFeatureClasses()
#iterate through list of shapefiles
for shapes in shapes:
name = p.splitext(shapes)[0]
print name
print shapes
zip_path = p.join(out_path, name + '.zip')
zip = zipfile.ZipFile(zip_path, 'w', compression=zipfile.ZIP_DEFLATED)
zip.write(p.join(path,shapes), shapes)
for f in arcpy.ListFiles('%s*' %name):
if not f.endswith('.shp'):
zip.write(p.join(path,f),f)
print 'All file written to %s' %zip_path
zip.close() ###Append2Zip.py
def append2Zip(zipfolder, path): # define function; name of function followed by any arguments in ()
print 'Appending to ' + zipfolder
zf = zipfile.ZipFile(zipfolder, mode= 'a')
try:
zf.write(path, os.path.basename(path))
finally:
zf.close()
path = r'Z:\Jared\Disclaimer - Final.txt'
zipfolders = [r'W:\Data\WillCounty_AddressPoint.zip', r'W:\Data\WillCounty_Street.zip'] #list of zip folders
for zipfolder in zipfolders: # loop through zipfolders
append2Zip(zipfolder, path) #call function above
... View more
12-01-2016
11:50 AM
|
0
|
3
|
1687
|
POST
|
Thanks Darren. The second option worked problem-free. One other thing unrelated; when running the same block of code for a different file to be appended to, do I really need to repeat the same block in it's entirety? For example, I want to appended the same (.txt) file to a different zip file, so I simply repeated it (starting on line 14). See code below:
... View more
11-30-2016
07:44 AM
|
0
|
1
|
865
|
Title | Kudos | Posted |
---|---|---|
1 | 01-11-2017 10:44 AM | |
1 | 03-18-2016 12:41 PM | |
1 | 03-29-2016 11:26 AM | |
2 | 09-27-2017 12:51 PM | |
1 | 07-05-2017 02:29 PM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|