|
POST
|
I understand how to write the function of a value list I think, but then how do you set it up to be a input paramter like I did "path = arcpy.GetParameterAsText(0)" ? I am new to programming, it may be a simple question.
... View more
05-23-2013
10:13 AM
|
0
|
0
|
1287
|
|
POST
|
I made a script for toolbox that works fine for exporting PDFs of all MXDs in a folder to another folder. I don't have any settings optional. I cannot choose options other than PDF. How do I make a drop down in ArcToolbox so someone can choose the export type, like PDF, JPEG, etc? This is my export to PDF script for my toolbox:
#Export standard maps to PDFs
#Written using ArcGIS 10 and Python 2.6.5
import arcpy, os
#Read input parameter from user.
path = arcpy.GetParameterAsText(0)
#Write MXD names in folder to txt log file.
writeLog=open(path+"\FileListLog.txt","w")
for fileName in os.listdir(path):
fullPath = os.path.join(path, fileName)
if os.path.isfile(fullPath):
basename, extension = os.path.splitext(fullPath)
if extension == ".mxd":
writeLog.write(fullPath+"\n")
mxd = arcpy.mapping.MapDocument(fullPath)
print fileName + "\n"
del mxd
print "Done"
writeLog.close()
exportPath =arcpy.GetParameterAsText(1)
MXDread=open(path+"\FileListLog.txt","r")
for line in MXDread:
#Strip newline from line.
line=line.rstrip('\n')
if os.path.isfile(line):
basename, extension = os.path.splitext(line)
newName=basename.split('\\')[-1]
if extension.lower() == ".mxd":
print "Basename:" +newName
mxd = arcpy.mapping.MapDocument(line)
newPDF=exportPath+"\\"+newName+".pdf"
print newPDF
arcpy.mapping.ExportToPDF(mxd,newPDF)
print line + "Export Done"
MXDread.close()
item=path+"\FileListLog.txt"
os.remove(item)
del mxd
... View more
05-22-2013
10:03 AM
|
0
|
4
|
1411
|
|
POST
|
The way our system runs is that we have a general username and password server that is out for all our users to see. Then we have another server that we do all our work on and it replicates over to the general user server. The private server people would need to put their own username and passwords in but that is for our GIS staff so we know what to change.
... View more
03-15-2013
05:20 AM
|
0
|
0
|
1453
|
|
POST
|
So excited! I got it to work! This is the full script, I cannot post my work's data path's up here so I changed them out, if they look a little funny.... #Data Replacement, by: rangermry
#3/13/2012
#Script to replace data sources in a MXD
#Written using Python 2.6.5 and the ArcGIS Desktop 10.0 ArcPy Mapping Module.
#This script makes a new SDE connection file on the user's C Drive and then replaces the old server's paths in the MXD with the new
#connection file.
#Import Python Libraries
import arcpy, os
#Set Your Variables Up Here!
# Must add prefix r (stands for raw) and put path in quotes.
targetMXD = r"\\servername\mxdpath\.mxd"
userName = "rangermry"
# Set variables for creating new SDE Connection
folderName = "C:/Documents and Settings/" + userName + "/Application Data/ESRI/Desktop10.0/ArcCatalog"
fileName = "Connection to Server.sde"
serverName = "SERV1"
serviceName = "5151"
databaseName = "gis"
authType = "DATABASE_AUTH"
username = "local"
password = "local"
saveUserInfo = "SAVE_USERNAME"
versionName = "SDE.DEFAULT"
saveVersionInfo = "SAVE_VERSION"
#Process: Use the CreateArcSDEConnectionFile function
rcpy.CreateArcSDEConnectionFile_management(folderName, fileName, serverName, serviceName, databaseName, authType, username, password, saveUserInfo, versionName, saveVersionInfo)
mxd = arcpy.mapping.MapDocument(targetMXD)
for df in arcpy.mapping.ListDataFrames(mxd):
for lyr in arcpy.mapping.ListLayers(mxd):
if lyr.supports("SERVICEPROPERTIES"):
servProp=lyr.serviceProperties
#Replace old dataset name with new dataset name and replace
if (lyr.serviceProperties["ServiceType"]=="SDE") and (lyr.serviceProperties["Service"]== "5153"):
dataSet=lyr.dataSource
list=dataSet.split('\\')
newDataSet=str(list[2])
currentName=newDataSet.split('.')[0]
newDataSet=newDataSet.replace(currentName,username)
newDataSetName=newDataSet.split('.')[0]
sdeFile="Database Connections\\"+fileName
lyr.replaceDataSource(sdeFile,"SDE_Workspace",lyr.name,"")
arcpy.RefreshTOC()
arcpy.RefreshActiveView()
mxd.save()
del mxd
... View more
03-15-2013
04:57 AM
|
0
|
0
|
1453
|
|
POST
|
My error is that my MXD changes the path of the SDE layer to this in the Layer Properties, Source Tab, Data Source: Data Type: SDE Feature Class Feature Class: puts feature dataset here Location: puts folder of mxd + sde connection path here Feature Dataset: feature dataset name Feature Type: Simple Geometry Type: Polygon What I need to do is change the SDE path and the feature datasets first word which is the name of the SDE database. I only need a certain SDE database so I do not want to just change all in a MXD, that is why I was going layer by layer.
... View more
03-15-2013
03:59 AM
|
0
|
0
|
1453
|
|
POST
|
I try this code and then my path changes to the path of the mxd plus the sde connection. I am not sure I am going in the right direction anyways? I am trying to change all my SDE files that point to one server to another with the same feature datasets and names. Please Help.
#Set Your Variables Up Here!
# Must add prefix r (stands for raw) and put path in quotes.
targetMXD = r"\\filepathhere.mxd"
userName = "me"
# Set variables for creating new SDE Connection
folderName = "C:/Documents and Settings/" + userName + "/Application Data/ESRI/Desktop10.0/ArcCatalog"
fileName = "Connection to NewSDETest.sde"
serverName = "SP56"
serviceName = "5151"
databaseName = "gis"
authType = "DATABASE_AUTH"
username = "look"
password = "look"
saveUserInfo = "SAVE_USERNAME"
versionName = "SDE.DEFAULT"
saveVersionInfo = "SAVE_VERSION"
#Process: Use the CreateArcSDEConnectionFile function
mxd = arcpy.mapping.MapDocument(targetMXD)
for df in arcpy.mapping.ListDataFrames(mxd):
for lyr in arcpy.mapping.ListLayers(mxd):
if lyr.supports("SERVICEPROPERTIES"):
servProp=lyr.serviceProperties
sdeFile= '"'+folderName+'/'+fileName+'"'
if (lyr.serviceProperties["ServiceType"]=="SDE") and (lyr.serviceProperties["Service"]== "5153"):
dataSet=lyr.dataSource
list=dataSet.split('\\')
newDataSet=str(list[2])
currentName=newDataSet.split('.')[0]
newDataSet.replace(currentName,userName)
lyr.replaceDataSource(sdeFile,"SDE_Workspace",newDataSet,"")
print lyr.dataSource
arcpy.RefreshTOC()
arcpy.RefreshActiveView()
mxd.save()
del mxd
... View more
03-14-2013
12:02 PM
|
0
|
5
|
6635
|
|
POST
|
I have the path to the layer, I can cat the object arcpy.mapping... in front of all of them for each. Does addLayer have to be referenced to a single variable or can it be referenced to a path name?
... View more
11-13-2012
03:05 AM
|
0
|
0
|
1099
|
|
POST
|
I am setting up a file to format a map template. I am stuck at the Add Layer section. I have a dictionary which is layer name:layer path. I want to grab all the layer paths and add them as layers to the map template. How can I fix my code? TemplateLayers=(r"\\...\TemplateLayers.txt")
lyrDict={}
with open (TemplateLayers) as f:
for line in f:
(key,val)=line.split(",")
lyrDict[(key)]=val
f.close()
print lyrDict
#Step 2: Pull the layers into the MXD at the bottom of the data frame from the dictionary.
for val in lyrDict.values():
arcpy.mapping.AddLayer("",(val),"Bottom") I get: Runtime error <type 'exceptions.AssertionError'>: When I print my dictionary it looks like this: {'Roads':'\\\\filepath\\filename.lyr',etc....}
... View more
11-09-2012
10:32 AM
|
0
|
3
|
1246
|
|
POST
|
Nevermind, I did not need to do all that sits above. I changed to this... TemplateLayers=(r"\\C\etc\file.txt") lyrDict={} with open (TemplateLayers) as f: for line in f: (key,val)=line.split(",") lyrList[(key)]=val f.close() print lyrDict
... View more
11-09-2012
10:07 AM
|
0
|
0
|
839
|
|
POST
|
I want make a dictionary from a text file of: layer name,layer file location and then loop through is making variables called the layer name and assigning them arcpy.mapping.Layer(r"layer file location"). I am new to Python, how do I put in the variable name where the layer file location is supposed to be correctly and can I do that? Here is my code I have so far... #Pull in a dictionary from reading text file. #Note:Have a text file ready named file.txt that contains lines of: layer name,layer file location. #Assign the text file a variable name TemplateLayers=r("'\\C:\etc\file.text") #Make the dictionary. lyrList={} #Assign the values in the text file to the dictionary. for line in TemplateLayers: k,v=line.strip().split(',') lyrList[k,strip()]=v.strip() f.close() #Make the variables from the layer name and assign them a file layer. for k, v in lyrList.items(): k=arcpy.mapping.Layer(r ----where I am stuck!)
... View more
11-09-2012
09:01 AM
|
0
|
1
|
1086
|
|
POST
|
The below works great on MXDs nested directly in a folder, but how do you walk through all the files in folders in the folder? import arcpy, os folderPath = r"myfolderpathhere" for filename in os.listdir(folderPath): fullpath = os.path.join(folderPath, filename) if os.path.isfile(fullpath): basename, extension = os.path.splitext(fullpath) if extension.lower() == ".mxd": mxd = arcpy.mapping.MapDocument(fullpath) mxd.findAndReplaceWorkspacePaths(r"mybeginningoldfoldeepath", r"mybeginningnewfolderpath") mxd.save() del mxd
... View more
06-22-2012
11:45 AM
|
0
|
2
|
934
|
|
POST
|
The issue is I do not have them labeled to all be of the same line. I could use an offset but the issue is I could have all am and pm offset in the same direction or just offset the am but I am not sure which is which. I want to I guess add an attribute so that a to b and b to c all have a similar attribute. There are nodes that have an identifier which is a unique number that is what a or b or c is. I need a way to link the lines together like a is going to b line and b is going to c line have to be put together somehow. I have a series of lines with to/from but no route, I guess I need a route made.
... View more
04-09-2012
10:18 AM
|
0
|
0
|
851
|
|
POST
|
I have a dataset of am and pm road links. By road links I mean lines that are individual objects with an A and B node like this road line is point a to point b, the next line is point b to point c. Then, the nodes reverse for pm and go c to b, b to a and etc... I need to have them show up offset from their locations due to at the map scale I need they show up one on top of the other. They do not have a shared attribute like road name to connect them. How can I get them to represent themselves apart from each other? I do not have a matching road layer to the location of these road lines as the road lines I am using are an output of a travel model that are off from the actual road, I have nothing connecting the actual road to the travel model. I am aware of the dissconnect issues with the travel model company and am dealing with those. I have network analyst extension available if I need that. I am looking for a simple solution because it is purely a display issue at this point.
... View more
04-09-2012
09:09 AM
|
0
|
2
|
1757
|
|
POST
|
Myself and a co-worker have lost the use of trace tool. This seems to be an error that ESRI people do not seem to post about, huh?
... View more
08-24-2011
08:35 AM
|
0
|
0
|
8444
|
|
POST
|
I have been using the trace tool in ArcEditor for over 4 years, all the sudden it does not want to work for me! I am in ArcMap 10, this has never happened to me. I reset my registry, then I reinstalled and all the while I still get the error. I do not get the error in a shapefile, another geodatabase or anything. I just tested it and found out it does not happen in another MXD, however, if I copy the MXD I still get the problem. The problem is all my complicated utility mapping settings are in this MXD, is there a way to fix this problem so I do not have to make a new MXD and/or save the new editing templates?
... View more
08-22-2011
11:21 AM
|
0
|
1
|
640
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 12-18-2015 04:46 AM | |
| 2 | 12-18-2015 06:15 AM |
| Online Status |
Offline
|
| Date Last Visited |
11-11-2020
02:24 AM
|