POST
|
Thanks for your help. I'm wondering if from arcpy import env Might be my issue, I'll run through it again. Thanks again Jon UPDATE - Yup that was it!
... View more
12-19-2012
07:44 AM
|
0
|
0
|
251
|
POST
|
I always seem to get hung up on these simple strings. Here again I don???t quite get the syntax for use in SelectLayerByAttribute_management If I use the following with a field named ???Name??? the query works just fine iQuery = ' "Name" = \'Joe Blogs\' ' arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", iQuery) However when I try to use a variable I can never seem to get the syntax right iPerson = ???Joe Blogs??? iQuery = '"Name" = "' + aCenterMapOn + '"' arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", iQuery) Thanks
... View more
12-19-2012
07:05 AM
|
0
|
12
|
1173
|
POST
|
I have the page size set manually on my target mxd. I'm in an mxd, lets call it default.mxd which is set at size letter, I want to print a ansi C sized map and have a template for that on my HD. Template is called ansiC.mxd and is set. I run a python script that selects the ansiC.mxd and exports it to a PDF. However the page size used appers to be from Default.mxd rather than the template ansiC.mxd I just want to honor the settings in my template mxd Thanks
... View more
12-18-2012
09:52 AM
|
0
|
0
|
251
|
POST
|
I???m using a script to allow the users to select from different map templates, the templates range in paper size from Letter to ansi D. My script finds a chosen attribute and zooms the map to that location, then exports to map as a pdf. My problem is that the page/paper size doesn???t appear to change when switching to the target mxd. I notice the same behavior when using the ???switch layout??? function in the Layout toolbar. Any idea how to use the page and paper settings of my target MXD? Thanks
... View more
12-18-2012
09:10 AM
|
0
|
5
|
401
|
POST
|
Morning folks, a really basic question for you. How do i determine what my current default GDB is? I've looked through the environment variables and can't seem to find a way to pull this info. I'm trying to list domains in my GDB without entering an absolute path such as C:\my_data\default.gdb Thanks
... View more
12-17-2012
08:21 AM
|
0
|
1
|
588
|
POST
|
Thanks Jeff. I found the issue. The FC are Joined so I need complete joined field name assignments.assignment_number Jon
... View more
12-14-2012
07:43 AM
|
0
|
0
|
258
|
POST
|
I'm working through the examples in the online help, example #3 shows how to export a selection of records rather than everything. import arcpy mxd = arcpy.mapping.MapDocument(r"C:\Project\ParcelAtlas.mxd") ddp = mxd.dataDrivenPages indexLayer = ddp.indexLayer arcpy.SelectLayerByAttribute_management(indexLayer, "NEW_SELECTION", '"PageNumber" >= 1 AND "PageNumber" <= 10') for indexPage in ddp.selectedPages: ddp.currentPageID = indexPage ddp.exportToPDF(r"C:\Project\Output\Page" + str(indexPage) + ".pdf", "CURRENT") del mxd I have DDP setup on a mxd and when I run the script it always exports ALL the records. The changes I made to the script only pertain to the mxd patch, destination path and field name that is the index layer. import arcpy mxd = arcpy.mapping.MapDocument(r"C:\MapSAR\New_Incident_Z11\Map_Templates\MapSAR_ANSI_A_8x11_Letter_Landscape_DDP.mxd") ddp = mxd.dataDrivenPages indexLayer = ddp.indexLayer arcpy.SelectLayerByAttribute_management(indexLayer, "NEW_SELECTION",'"Assignment_Number" > 1 AND "Assignment_Number" < 3') for indexPage in ddp.selectedPages: ddp.currentPageID = indexPage ddp.exportToPDF(r"C:\MapSAR\New_Incident_Z11\Products\page" + str(indexPage) + ".pdf", "CURRENT") del mxd can anyone either point out what I'm doing incorrectly or even better if there's other code examples I might learn from. Thanks Jon
... View more
12-13-2012
12:20 PM
|
0
|
2
|
583
|
POST
|
This is my first foray into the ToolValidator class so this might be a very basic issue. I???d like to read in a list of values from a list and display them as selectable in the script dialog as selectable options Example: Parameters in the script tool [0] = name of mxd (required, arcmapdocument) [1] = values (required, string, multivalue, filtered) Can I assign a list such as vals = [1,2,3,4,5,6,7] self.params[1] = vals In the end I???d like this to pull data from a featureclass using a searchcursor but for now I???m trying to see if it will even take the basic list of values. Thanks
... View more
08-27-2012
09:40 AM
|
0
|
1
|
420
|
POST
|
Thanks Mike, this loop appears to work. Though I can't really tell as I can't figure out the simplest command "save" save appears to have no paramaters http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00s30000000n000000 I'm not looking to saveacopy as i want to overwrite the original file. I have set arcpy.env.overwriteOutput = true what would the syntax be for save? save() arcpy.save() mxd.arcpy.save() save(mcd) I've tried them all to no avail. Silly to be hung up on something so simple Thanks
... View more
08-23-2012
08:47 AM
|
0
|
0
|
1643
|
POST
|
Morning all, this is a followup post to the thread I have going here http://forums.arcgis.com/threads/65282-confusion-with-ListDataFrames-and-Listlayers I'm still having a tough time understanding the ListDataFrames functionality and results. In my mind what I think ListDataFrames would give me is exactly that, a listing of data frames with the mxd. However when I execute this command I get back a listing of layers. All the examples I see in the help use [0] such as df = arcpy.mapping.ListDataFrames(mxd, "Transportation")[0] When I execute a line such as the above I get back a list of layers within my first layergroup. This is probably just me not understanding python or coding very well, it's driving me a little nuts. The objective of my script below is to save a layer of base_data from the current mxd to disk. Then look at the target mxd and see if it has a layer names Base_Data, if so remove it, then import the previously saved layer and add to the bottom of the target mxd. Then of course save. import arcpy from arcpy import env # Set overwrite option arcpy.env.overwriteOutput = True # Gather user input parameters TargetFile = arcpy.GetParameterAsText(0) if TargetFile > "": arcpy.AddMessage("Target File is True") # from current open mxd, save base data layer file to disk LayerFile = "./Base_Layer" arcpy.SaveToLayerFile_management("Base_Data_Group",LayerFile,"RELATIVE") arcpy.AddMessage("Base Data Saved as "+ LayerFile) mxd = arcpy.mapping.MapDocument(TargetFile) df = arcpy.mapping.ListDataFrames(mxd) lyr_list = arcpy.mapping.ListLayers(mxd) for lyr in lyr_list: if 'Base_Data' in lyr.name: arcpy.mapping.RemoveLayer(df,lyr) arcpy.AddMessage(lyr) path = LayerFile + '.lyr' arcpy.AddMessage("adding layer") addLayer = arcpy.mapping.Layer(path) arcpy.mapping.AddLayer(df, addLayer, "BOTTOM") TargetFile.arcpy.save()
... View more
08-23-2012
08:10 AM
|
0
|
4
|
4279
|
POST
|
OK I've officially had enough for the day, at every turn I run into errors that I'm unable to resolve and it's driving me up the wall. Either I get an exceptions.Assertion error or error when trying to simply save. Here's a code snippet below.
import glob
import arcpy
from arcpy import env
# Set overwrite option
arcpy.env.overwriteOutput = True
# Gather user input parameters
TargetDir = arcpy.GetParameterAsText(0)
TargetFile = arcpy.GetParameterAsText(1)
if TargetFile > "":
arcpy.AddMessage("Target File is True")
# Save base data layer file to disk
LayerFile = "./Base_Layer"
arcpy.SaveToLayerFile_management("14 Base_Data_Group",LayerFile,"RELATIVE")
arcpy.AddMessage("Base Data Saved as "+ LayerFile)
mxd = arcpy.mapping.MapDocument(TargetFile)
df = arcpy.mapping.ListDataFrames(mxd)
lyr_list = arcpy.mapping.ListLayers(mxd)
arcpy.AddMessage("1")
for lyr in lyr_list:
if 'Base_Data' in lyr.name:
arcpy.mapping.RemoveLayer(df,lyr)
arcpy.AddMessage(lyr)
path = LayerFile + '.lyr'
arcpy.AddMessage("adding layer")
addLayer = arcpy.mapping.Layer(path)
arcpy.mapping.AddLayer(df, addLayer, "BOTTOM")
TargetFile.arcpy.save()
... View more
08-22-2012
02:59 PM
|
0
|
0
|
115
|
POST
|
Latest error, while running from within ArcMap
Running script Layers...
Target File is True
Base Data Saved as ./Base_Layer
1
<type 'exceptions.AssertionError'>:
Failed to execute (Layers).
import glob
import arcpy
from arcpy import env
# Set overwrite option
arcpy.env.overwriteOutput = True
# Gather user input parameters
TargetDir = arcpy.GetParameterAsText(0)
TargetFile = arcpy.GetParameterAsText(1)
if TargetFile > "":
arcpy.AddMessage("Target File is True")
# Save base data layer file to disk
LayerFile = "./Base_Layer"
arcpy.SaveToLayerFile_management("14 Base_Data_Group",LayerFile,"RELATIVE")
arcpy.AddMessage("Base Data Saved as "+ LayerFile)
mxd = arcpy.mapping.MapDocument(TargetFile)
df = arcpy.mapping.ListDataFrames(mxd,"14*")
lyr_list = arcpy.mapping.ListLayers(mxd)
arcpy.AddMessage("1")
for lyr in lyr_list:
if 'Base_Data' in lyr.name:
arcpy.mapping.RemoveLayer(df,lyr)
arcpy.AddMessage(lyr)
path = LayerFile + '.lyr'
arcpy.AddMessage("adding layer")
addLayer = arcpy.mapping.Layer(path)
arcpy.mapping.AddLayer(df, addLayer, "BOTTOM")
mxd.save()
elif TargetDir > "":
arcpy.AddMessage("Target Directory is true")
# Save base data layer file to disk
LayerFile = "./Base_Layer"
arcpy.SaveToLayerFile_management("14 Base_Data_Group",LayerFile,"RELATIVE")
arcpy.AddMessage("Base Data Saved as "+ LayerFile)
# Get list of files from directory
path = TargetDir +"\*.mxd"
mxds = glob.glob(path)
arcpy.AddMessage(mxds)
for row in mxds:
note = '"'+row+'"'
arcpy.AddMessage("Applying base data to mxd...")
arcpy.AddMessage(row)
mxd = arcpy.mapping.MapDocument(row)
df = arcpy.mapping.ListDataFrames(mxd)[0]
basedata = arcpy.mapping.ListLayers(mxd, "14 Base_Data", df)[0]
for i in basedata:
arcpy.AddMessage(i)
path = LayerFile + '.lyr'
addLayer = arcpy.mapping.Layer(path)
arcpy.mapping.AddLayer(df, addLayer, "BOTTOM")
mxd.save()
del mxd, addLayer
... View more
08-22-2012
01:04 PM
|
0
|
0
|
115
|
POST
|
Here's my entire code file, it probably appears rather brute force as I'm very new to python/coding and learning as I go. I have 2 user parameters, the first is a folder, so the script can iterate through each file. Kinda abandoned that until I can get a singel file working. The second is a document type which provides the target.
import glob
import arcpy
from arcpy import env
# Set overwrite option
arcpy.env.overwriteOutput = True
# Gather user input parameters
TargetDir = arcpy.GetParameterAsText(0)
TargetFile = arcpy.GetParameterAsText(1)
arcpy.AddMessage(TargetDir)
arcpy.AddMessage(TargetFile)
if TargetFile > "":
arcpy.AddMessage("Target File is True")
# Save base data layer file to disk
LayerFile = "./Base_Layer"
arcpy.SaveToLayerFile_management("14_Base_Data_Group",LayerFile,"RELATIVE")
arcpy.AddMessage("Base Data Saved as "+ LayerFile)
mxd = arcpy.mapping.MapDocument(TargetFile)
arcpy.AddMessage(mxd)
df = arcpy.mapping.ListDataFrames(mxd,"")
lyr_list = arcpy.mapping.ListLayers(mxd)
for lyr in lyr_list:
if 'Base_Data' in lyr.name:
arcpy.mapping.RemoveLayer(df,lyr)
path = LayerFile + '.lyr'
arcpy.AddMessage("1" +path)
addLayer = arcpy.mapping.Layer(path)
arcpy.AddMessage("2")
arcpy.mapping.AddLayer(df, addLayer, "BOTTOM")
mxd.save()
elif TargetDir > "":
arcpy.AddMessage("Target Directory is true")
# Save base data layer file to disk
LayerFile = "./Base_Layer"
arcpy.SaveToLayerFile_management("14 Base_Data_Group",LayerFile,"RELATIVE")
arcpy.AddMessage("Base Data Saved as "+ LayerFile)
# Get list of files from directory
path = TargetDir +"\*.mxd"
mxds = glob.glob(path)
arcpy.AddMessage(mxds)
for row in mxds:
note = '"'+row+'"'
arcpy.AddMessage("Applying base data to mxd...")
arcpy.AddMessage(row)
mxd = arcpy.mapping.MapDocument(row)
df = arcpy.mapping.ListDataFrames(mxd)[0]
basedata = arcpy.mapping.ListLayers(mxd, "14 Base_Data", df)[0]
for i in basedata:
arcpy.AddMessage(i)
path = LayerFile + '.lyr'
addLayer = arcpy.mapping.Layer(path)
arcpy.mapping.AddLayer(df, addLayer, "BOTTOM")
mxd.save()
del mxd, addLayer
... View more
08-22-2012
12:34 PM
|
0
|
0
|
842
|
POST
|
Sorry for all the posts but I keep trying.... 🙂 I found a RemoveLayer, however I now get an error when trying to save the file after processing.
>>> mxd = arcpy.mapping.MapDocument('C:\test.mxd')
>>> df = arcpy.mapping.ListDataFrames(mxd,"")[0]
>>> lyr_list = arcpy.mapping.ListLayers(mxd)
>>> for lyr in lyr_list:
if 'Base_Data' in lyr.name:
arcpy.mapping.RemoveLayer(df,lyr)
mxd.save()
error below
Traceback (most recent call last):
File "<pyshell#60>", line 4, in <module>
mxd.save()
File "C:\Program Files\ArcGIS\Desktop10.0\ArcPy\arcpy\utils.py", line 181, in fn_
return fn(*args, **kw)
File "C:\Program Files\ArcGIS\Desktop10.0\ArcPy\arcpy\_mapping.py", line 643, in save
return convertArcObjectToPythonObject(self._arc_object.save(*gp_fixargs((), True)))
IOError: MapDocObject: Unable to save. Check to make sure you have write access to the specified file and that there is enough space on the storage device to hold your document.
... View more
08-22-2012
12:16 PM
|
0
|
0
|
842
|
Title | Kudos | Posted |
---|---|---|
3 | 07-11-2013 02:09 PM | |
2 | 07-31-2012 09:51 AM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|