|
POST
|
Here is an example: import arcpy
from arcpy import env
from arcpy import mapping
env.workspace = r"C:\temp\python"
mxd = mapping.MapDocument(r"C:\temp\python\Airports.mxd")
for df in mapping.ListDataFrames(mxd, "*"):
lyr = mapping.Layer(r"C:\temp\python\Airports.lyr")
addLayer = mapping.AddLayer(df, lyr)
mxd.save()
del mxd
... View more
07-29-2011
12:23 PM
|
0
|
0
|
967
|
|
POST
|
You will just need to specify the path to mxd rather than "CURRENT": mxd = arcpy.mapping.MapDocument(r"C:\data\Philadelphia.mxd") After your code, be sure to save your mxd with: mxd.save()
... View more
07-29-2011
11:52 AM
|
0
|
0
|
967
|
|
POST
|
If a user is accessing a version there should be a state lock. You can query the version table for the version that is locked: SQL> select state_id from sde.versions where name = 'Child_Version'
1864 Then you can query the state locks table to get to the sde_id of the user: SQL> select sde_id from sde.state_locks where state_id = '1864'
4371 Next, you can query the process information table to get the user's name: SQL> select owner from sde.process_information where sde_id = '4371'
VECTOR You can request this user to disconnect, or you can use the 'sdemon -o kill' command to kill this specific user: C:\> sdemon -o kill -t 4371 -i sde:oracle11g
... View more
07-29-2011
09:57 AM
|
0
|
0
|
2222
|
|
POST
|
What error messages are you receiving? You can add the try...except block to you code to retrieve the error messages. Ex: try:
arcpy.DeleteRows_management(GIS_NMBCC)
except arcpy.ExecuteError:
print arcpy.GetMessages()
... View more
07-29-2011
08:51 AM
|
0
|
0
|
681
|
|
POST
|
Let's try recreating the MXD. Open the corrupted MXD and select all the layers within the Table of Contents > right-click on one of the selected layers > Copy. Next, start a new MXD and right-click on the data frame > Paste Layers. Save this MXD with a new name and try exporting to a PDF using your script. Do you still receive the same error?
... View more
07-29-2011
02:51 AM
|
0
|
0
|
2390
|
|
POST
|
Does your data within your MXDs resides within an SDE geodatabase? If so, can you try this script on an MXD that contains data from a File or Personal geodatabase?
... View more
07-28-2011
10:42 AM
|
0
|
0
|
2390
|
|
POST
|
You can download the MFC71.dll here. Save this file to your 'C:\Windows\SysWOW64' and then try installing python again.
... View more
07-28-2011
07:10 AM
|
0
|
0
|
997
|
|
POST
|
You can use a wildcard to select the layers, for example by specify the database name. Below is an example: lstMXDs = glob.glob(env.workspace + "\\" + "*.mxd")
for mxd in lstMXDs:
mxd = mapping.MapDocument(mxd)
for df in mapping.ListDataFrames(mxd, ""):
lstLayers = mapping.ListLayers(mxd, "*", df)
for lyr in lstLayers:
if "vector" in lyr.dataSource:
print lyr.dataSource
lyr.replaceDataSource("arcsde_DIRECT.sde", "SDE_WORKSPACE", "")
print "Successfuly updated data sources"
else:
print lyr.dataSource
lyr.replaceDataSource("RASTER.sde", "SDE_WORKSPACE", "")
print "Successfully updated data sources"
mxd.save()
del mxd I'm using the wildcard "vector" to find all data sources in my VECTOR database and replacing the datasource to my SDE direct connection. If the layer is not in my VECTOR database, I replace it with a new connection to my RASTER database.
... View more
07-28-2011
04:09 AM
|
0
|
0
|
1238
|
|
POST
|
You will not have to add quotes to the 'mxds' variable. I believe because you are looping through a list that is comprised of strings, and therefore python knows the variable 'mxds' is already a string. Example, you could simply write: for mxds in mxdLst:
print mxds + " is a map document" You would not have to write: for mxds in mxdLst:
print str(mxds) + " is a map document" In your code, try: inMxd = arcpy.mapping.MapDocument(mxds) #Make current mxd in loop the mapdocument
... View more
07-27-2011
12:21 PM
|
0
|
0
|
2390
|
|
POST
|
If you want the map document to update use "CURRENT" for the mxd. Ex: mxd = arcpy.mapping.MapDocument("CURRENT") Then add at the bottom of your code: arcpy.RefreshTOC()
arcpy.RefreshActiveView() ListLayers always returns a Python list object even if only one layer is returned. In order to return a Layer object, an index value must be used on the list (e.g., lyr = arcpy.mapping.ListLayers(mxd)[0]). More information can be found here.
... View more
07-27-2011
11:22 AM
|
0
|
0
|
928
|
|
POST
|
Try the following: mxd = arcpy.mapping.MapDocument(r"j:\mxdfiles\mxdname.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
updateLayer = arcpy.mapping.ListLayers(mxd, "TestFC", df)[0]
sourceLayer = arcpy.mapping.Layer(r"j:\test\test.lyr")
arcpy.mapping.UpdateLayer(df, updateLayer, sourceLayer)
mxd.save() I believe the problem is that you are not defining the data frame correctly.
... View more
07-27-2011
10:07 AM
|
0
|
0
|
928
|
|
POST
|
Try the following code: import arcpy, glob, os
#Place script in same folder as MXDs to get 'current working directory'
baseF = os.getcwd()
print baseF
#Set local variables
mxdLst = glob.glob(baseF + '\\' + '*.mxd')
mxdCnt = len(mxdLst)
#Print how many mxd's found
print '\n' + 'Found ' + str(mxdCnt) + ' mxds for PDF exporting...'
print 'Directory: ' + str(baseF) + '\n'
#Loop to process each mxd into a PDF
for mxds in mxdLst:
PDFr = mxds.replace('mxd', 'pdf') #Replace 'mxd' extension with 'pdf'
print 'Exporting ' + str(mxds) + ' to:' + '\n' + str(baseF) + '\\' + str(PDFr) #Print current mxd exporting and output pdf name...
inMxd = arcpy.mapping.MapDocument(mxds) #Make current mxd in loop the mapdocument
arcpy.mapping.ExportToPDF(inMxd, PDFr) #Export mapdocument to pdf
print 'Done exporting: ' + str(PDFr)
del mxds I specified 'baseF = os.getcwd()' first and then added the baseF variable to the glob module, 'mxdLst = glob.glob(baseF + '\\' + '*.mxd')'.
... View more
07-27-2011
08:40 AM
|
0
|
0
|
2390
|
|
POST
|
Would you be able to copy/paste in your python code? Be sure to wrap CODE tags around your python code to maintain the correct format/indentations.
... View more
07-27-2011
08:23 AM
|
0
|
0
|
928
|
|
POST
|
I would post this question on the Python forum. You will be able to receive more intuitive help from that forum.
... View more
07-25-2011
01:15 PM
|
0
|
0
|
1814
|
|
POST
|
To create the FOR loop you would need to do this in IDLE or pythonwin. Once you have the script created, you can import the script to your Toolbox and execute it from ArcMap/ArcCatalog.
... View more
07-25-2011
12:30 PM
|
0
|
0
|
1814
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 3 weeks ago | |
| 1 | 12-01-2025 05:58 AM | |
| 1 | 11-21-2025 03:55 AM | |
| 1 | 11-14-2025 09:01 AM | |
| 1 | 11-13-2025 12:28 PM |
| Online Status |
Offline
|
| Date Last Visited |
yesterday
|