POST
|
No, see this documentation: ArcGIS Help 10.1 Go down to the examples and you'll see that, just like in the normal ToolValidator class for script tools (i.e. not in a Python toolbox), the updateParameters() method does not return any objects.
... View more
04-03-2015
07:41 AM
|
1
|
1
|
417
|
POST
|
You don't need the parentheses around the if condition... does removing those change the outcome?
... View more
04-02-2015
03:54 PM
|
0
|
0
|
417
|
POST
|
Yes, os.path.join is great, and here's just one more option: mypath = r"C:\{0}\{1}.mxd".format(myfolder, myfilename)
... View more
04-02-2015
03:42 PM
|
1
|
0
|
779
|
POST
|
This is a great thread, had a lot of info I was wondering about. I have a further question though. There were a couple of small differences in the way tool parameters were implemented between 10.0 and 10.1/10.2, specifically the way multivalue parameters were handled using the GetParameter... method. (Used to be they were acquired as valuetables, which was a little cumbersome.) I have a toolbox I wrote for 10.0 which I just upgraded to work with 10.1/10.2. I assume that all of the code itself will be compatible, but are there any small differences (like the multivalue parameter) between how scripts and tools will work in 10.1/10.2 and 10.3?
... View more
10-02-2014
09:39 AM
|
0
|
0
|
683
|
POST
|
Do you copy and paste this code into the console, or run it from somewhere else? See my post below; it'll be a good thing for me to add to my python package...
... View more
09-15-2014
12:42 PM
|
0
|
1
|
549
|
POST
|
This is all great info, and I especially like the delete everything in memory function. I thought I'd throw my own two cents in also... I began to deal with deleting feature classes like this a while ago by creating my own little python module. It's super useful to have a some functions that you can call anytime from anywhere, because I need to do this "delete if exists" thing all the time (plus a lot of other stock operations that I'm tired of retyping). Just make a folder in your python site-packages directory (something like C:\Python2x\Lib\site-packages, or, more likely, C:\Python2x\ArcGIS10.x\Lib\site-packages) called mypack, and then in that folder create a text file called __init__.py. You can define all the functions you want in there, and to access them from any console or script just say "from mymod import functionname". For what we're talking about here, I just have this in the __init__.py file: import arcpy def TakeOutTrash(dataset): if arcpy.Exists(dataset): arcpy.management.Delete(dataset) so in the console, making a feature layer could look like: from mypack import TakeOutTrash fl = "fl" TakeOutTrash(fl) # this is important if you are iterating or running the script many times arcpy.management.MakeFeatureLayer(r"path",fl) ##do some stuff with feature layer TakeOutTrash(fl) That function could be modified to accept a list of datasets too, I just haven't done that yet.
... View more
09-15-2014
12:32 PM
|
0
|
0
|
549
|
POST
|
Personally, I always use one of the following methods and don't have any trouble anymore 1. put an r in front of the path and it will be interpreted literally. path = r"C:\Temp1" 2. os.path.join() is great also, especially for constructing dynamic paths because you can pass variables as arguments. Also good if cross platform considerations are an issue path = os.path.join("C:","Temp1") 3. also good for dynamic paths, because you can through variables in for the directory names: path = r"{0}\{1}".format("C:","Temp1") 4. finally, it's not very concise, but you can always use os.sep path = "C:" +os.sep+"Temp1" Hope this is helpful!
... View more
08-14-2014
09:58 AM
|
3
|
1
|
562
|
POST
|
Hi Peter, I don't have experience with adding toolboxes in that way, but it seems like it's saying that arcpy is a None (null) value, or NoneType object. Where a layer object has attributes like .visible or .isGroupLayer, a NoneType object does not have an attribute .AddLayerToMXD_jtools. So it seems like there's something weird with the way you're referring to arcpy... Maybe in part of the script that's not shown? Try printing arcpy, or help(arcpy) just before you call that custom function to see what happens. Hope this is helpful...
... View more
08-12-2014
07:57 AM
|
0
|
0
|
325
|
POST
|
You could just take the cmboDistance variable and multiply it by 5280 in the function. For example: cmboDistanceFEET = float(cmboDistance)*5280 ...... arcpy.Buffer_analysis(ptGeometry, "buffer",cmboDistanceFEET) Feeding the buffer tool the same units as the point spatial reference (ft) seems like good practice anyway. If you have trouble with the math conversion, or want to put text (like 1/4, 1/2, 3/4, etc.) in the combobox, you can always use a dictionary to link those values to real numbers in feet. For example: def buildWebPage(x, y, cmboDistance): val_dict = {"1/4":5280*.25, "1/2":5280*.5, "3/4":5280*.75} arcpy.Buffer_analysis(ptGeometry, "buffer",val_dict[cmboDistance])
... View more
08-12-2014
07:10 AM
|
1
|
1
|
237
|
POST
|
Hi Chris, if you're running this from the python console you'll have to use
print layer.name
#etc
instead of
arcpy.AddMessage(layer.name)
#etc
... View more
06-26-2014
07:04 AM
|
0
|
0
|
604
|
POST
|
Hello, Regarding the [0]: this is the index number for the first item of the list. If I have a list
example_list = ["item 1","item 2","item 3","item 4"]
then example_list[0] = "item 1", and example_list[1] = "item 2". What you're seeing in your script is the creation of a list of data frame objects (all of the data frames named "Layers", as you noted) and then the index [0] which sets the df variable as the first (and most likely only) item in the list. EDIT: Here's a more succinct way to illustrate the list concept:
mxd = arcpy.mapping.MapDocument("current")
list_of_data_frames = arcpy.mapping.ListDataFrames(mxd, "Layers")
first_df = list_of_data_frames [0]
layers = arcpy.mapping.ListLayers(mxd, "*", first_df)
Again, most likely, Layers is the only data frame in the list, but even if it is a one-item list you must retrieve the data frame as a data frame, not as a one-item list of data frames. You're having trouble with the code because you are using the layer.name property (name in the TOC), and testing whether it equals the data source path for the layer, which is what you have in the list. If you use the layer.dataSource property, it should work.
for layer in layers:
if layer.dataSource in names:
layer.visible = False
(I would recommend changing the name of the list to something like "paths" instead of "names", just for clarity's sake.) Good practice for troubleshooting stuff like this is to add messages to the script output. Something like:
for layer in layers:
arcpy.AddMessage(layer) #this should be a geoprocessing layer object
arcpy.AddMessage(layer.name) #this should be the name in the TOC
arcpy.AddMessage(layer.dataSource) #this should be the path
if layer.dataSource in names:
layer.visible = False
... View more
06-26-2014
06:28 AM
|
0
|
0
|
604
|
POST
|
May be worth trying mxd.findAndReplaceWorkspacePaths (find_workspace_path, replace_workspace_path, {validate}) . Then you wouldn't have to loop through the layers either. Also, for your walking code, you could save a couple of steps and use the string.endswith() method.
#Loop through each MXD in the folder and writes path to a list
for root, dirs, files in os.walk(targetDir):
for filename in files:
if filename.endswith(".mxd")
#append to list
... View more
06-18-2014
08:15 AM
|
0
|
0
|
419
|
POST
|
Just to point out, if you only need to do this a couple of times you could just use the Select by Attribute tool from the Selection menu.
... View more
06-17-2014
06:17 AM
|
0
|
0
|
196
|
POST
|
Hi Suzanne, it would be good if you could repost with your code formatted as code. When you're posting, click the pound sign above the text box to get the tags for code, and then format your code inside of those tags.
... View more
06-13-2014
01:32 PM
|
0
|
0
|
550
|
POST
|
Create a Spatial Join to an in-memory output and then use the TargetFID of that output to join back to the polygon ObjectID. TargetFID 1 of the Spatial Join will match ObjectID 1 of the polygons. Ok cool, that sounds like a good method. I like it. I've mostly dealt with situations where I only want to transfer values if certain spatial and attribute criteria match (not what we're talking about here), which didn't seem like a good use for spatial joins. However, now I'm thinking that there may be a good way to incorporate a method similar to this.
... View more
06-12-2014
08:24 AM
|
0
|
0
|
1643
|
Title | Kudos | Posted |
---|---|---|
1 | 04-03-2015 07:41 AM | |
1 | 04-02-2015 03:42 PM | |
3 | 08-14-2014 09:58 AM | |
1 | 08-12-2014 07:10 AM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|