|
POST
|
They get into this a bit on stack overflow, but I think the issue is you are using triple quotes interchangeably with comments, where a triple quote is really a doc string. Shazam Lucas! I didn't know that triple quotes were docstrings! I always just assumed they were just multi-line comments. After reading the StackOverflow thread and then looking at the actual python documentation referenced within it makes a little more sense. It seems that if you want to use the docstring in this manner, it needs to be within the code block. I'm not sure why using docstrings interchangable with comments would cause an issue though. It doesn't seem to cause any issues within any of my other scripts.
... View more
10-16-2013
04:26 AM
|
0
|
0
|
1619
|
|
POST
|
There's no simple function to simply return a list of layers with a selection on them, but you could probably manage this by looping through the layers in the dataframe, getting the layers extent, then getting the layer's selected extent and comparing the two, and if the extents differ, then there is a selection applied to the layer and you can then append it to a list. I haven't tested this and I'm just writing this off the top of my head, but it should give you an idea of where to go with this:
mxd = arcpy.mapping.MapDocument("Current")
df = arcpy.mapping.ListDataFrames(mxd)[0]
TOCLayerList = arcpy.mapping.ListLayers(mxd, "*", df)
SelectedLayerList = []
for lyr in TOCLayerList:
lyrExtent = lyr.getExtent()
lyrSelectedExtent = lyr.getSelectedExtent()
if not lyrExtent == lyrSelectedExtent:
SelectedLayerList.append(lyr)
print SelectedLayerList
Again, I haven't tested this or played with it at all, but conceptually this is the best path I can think of to return only those layers with a selection applied. I'm not sure what the Layer method 'getSelectedExtent()' would return if there was no selection applied to a given layer, so you should toy with that as well and figure out what the return is and make a consideration for that in the logic so that you don't get any false positives. You should also note that if you plan to do this on an MXD with a large amount of layers in it, it could take a fair amount of time to complete. Hope this helps.
... View more
10-08-2013
04:32 AM
|
0
|
0
|
2170
|
|
POST
|
'params' should be a list object containing your individual parameters. So change the parameter from 'params' to param0, create a list object named params, populating 'param0' in the list and return the list. def getParameterInfo(self): """Define parameter definitions""" param0 = arcpy.Parameter( displayName="Input Features", name="in_features", datatype="DEDatasetType", parameterType="Required", direction="Input") params = [param0] return params I would have thought you could do it the way you did, but apparently if your not getting anything returned, you can't. Easy fix though, just a bit more code.
... View more
09-27-2013
05:14 AM
|
0
|
0
|
1980
|
|
POST
|
I reached out to Jason Pardy from ESRI to get the answer and am posting it here as a courtesy in case anyone else finds themself searching for a similar solution. The answer was to create a Polygon from the extent returned by the rectangle_geometry function and to use that polygon in the SBL Intersect. import pythonaddins mxd = arcpy.mapping.MapDocument("Current") df = arcpy.mapping.ListDataFrames(mxd)[0] class ShowMe_This(object): """Implementation for ShowMe.This (ComboBox)""" def __init__(self): self.items = ["Item1", "Item2", "Item3"] self.editable = False self.enabled = True self.dropdownWidth = 'XXXXXXXXXXXXXXXXXXXXXXXXXX' self.width = 'XXXXXXXXXXXXXXXXXXXXXXXXXX' def onSelChange(self, selection): global FeatureGeometry global SelFC if selection == "Item1": FeatureGeometry = "Point" SelFC = r"C:\ArcGIS\MyGeodatabase.gdb\Feature1" elif selection == "Item2": FeatureGeometry = "Polygon" SelFC = r"C:\ArcGIS\MyGeodatabase.gdb\Feature2" elif selection == "Item3": FeatureGeometry = "Polygon" SelFC = r"C:\ArcGIS\MyGeodatabase.gdb\Feature3" else: FeatureGeometry = "" SelFC = "" def refresh(self): self.refresh() class ShowMe_LikeThat(object): """Implementation for ShowMe.LikeThat (ComboBox)""" def __init__(self): self.items = ["Red", "Blue", "Orange", "Green", "Purple", "Pink", "Yellow"] self.editable = False self.enabled = True self.dropdownWidth = 'XXXXXXXXXXXXXXXXXXXXXXXXXX' self.width = 'XXXXXXXXXXXXXXXXXXXXXXXXXX' def onSelChange(self, selection): global Color Color = selection def refresh(self): self.refresh() class ShowMe_ForThis(object): """Implementation for ShowMe.ForThis (Tool)""" def __init__(self): self.enabled = True self.shape = "Rectangle" self.cursor = 3 def onRectangle(self, rectangle_geometry): SelExtent = rectangle_geometry # Get the Extent Extent = rectangle_geometry # Create a Polygon from the Extent Object ExtentPoly = arcpy.Polygon(arcpy.Array([arcpy.Point(Extent.XMin, Extent.YMin), arcpy.Point(Extent.XMin, Extent.YMax), arcpy.Point(Extent.XMax, Extent.YMax), arcpy.Point(Extent.XMax, Extent.YMin)])) # Select the Feature that intersects the Extent Polygon arcpy.management.SelectLayerByLocation(SelFC, "INTERSECT", ExtentPoly, "", "NEW_SELECTION") class ShowMe_Execute(object): """Implementation for ShowMe.Execute (Button)""" def __init__(self): self.enabled = True self.checked = False def onClick(self): # Do whatever you want to do. Technically, you could completely remove this class and just put it all in the ShowMe_ForThis class, so that your logic occurs as soon as the selections are complete.
... View more
09-26-2013
10:05 AM
|
0
|
0
|
1314
|
|
POST
|
Hi guys, I'm trying to create a Python Addin to allow a user to dynamically select a feature in the Map Display Window in ArcMap, grab the ID of that feature and populate it in a variable, then select from a second feature class the features within the second feature class which have that ID, exporting those features to a new FC and then symbolizing with a layer file and adding the result to the data frame. Here's what I have so far: import arcpy import pythonaddins mxd = arcpy.mapping.MapDocument("Current") df = arcpy.mapping.ListDataFrames(mxd)[0] class ShowMe_This(object): """Implementation for ShowMe.This (ComboBox)""" def __init__(self): self.items = ["Predictive Trade Area", "Existing Trade Area", "ReDomiciled Customers"] self.editable = False self.enabled = True self.dropdownWidth = 'XXXXXXXXXXXXXXXXXXXXXXXXXX' self.width = 'XXXXXXXXXXXXXXXXXXXXXXXXXX' def onSelChange(self, selection): global FeatureGeometry global SelFC if selection == "ReDomiciled Customers": FeatureGeometry = "Point" SelFC = r"C:\ArcGIS\SYSTEM\COF\Data\MyGeodatabase.gdb\Customers" elif selection == "Predictive Trade Area": FeatureGeometry = "Polygon" SelFC = r"C:\ArcGIS\SYSTEM\COF\Data\MyGeodatabase.gdb\PTAs" elif selection == "Existing Trade Area": FeatureGeometry = "Polygon" SelFC = r"C:\ArcGIS\SYSTEM\COF\Data\MyGeodatabase.gdb\ETAs" else: FeatureGeometry = "" SelFC = "" def onEditChange(self, text): pass def onFocus(self, focused): pass def onEnter(self): pass def refresh(self): pass class ShowMe_LikeThat(object): """Implementation for ShowMe.LikeThat (ComboBox)""" def __init__(self): self.items = ["Red", "Blue", "Orange", "Green", "Purple", "Pink", "Yellow"] self.editable = False self.enabled = True self.dropdownWidth = 'XXXXXXXXXXXXXXXXXXXXXXXXXX' self.width = 'XXXXXXXXXXXXXXXXXXXXXXXXXX' def onSelChange(self, selection): global Color Color = selection def onEditChange(self, text): pass def onFocus(self, focused): pass def onEnter(self): pass def refresh(self): pass class ShowMe_ForThis(object): """Implementation for ShowMe.ForThis (Tool)""" def __init__(self): self.enabled = True self.shape = "Rectangle" self.cursor = 3 def onRectangle(self, rectangle_geometry): global SelExtent SelExtent = rectangle_geometry class ShowMe_Execute(object): """Implementation for ShowMe.Execute (Button)""" def __init__(self): self.enabled = True self.checked = False def onClick(self): # Establish a reference to the appropriate Layer File based on the users selections LYRfile = r"C:\ArcGIS\SYSTEM\COF\Data\Layer Files\ShowMe" + "\\" + FeatureGeometry + "\\" + Color + ".lyr" print LYRfile if FeatureGeometry == "": pythonaddins.MessageBox("You must select a Feature from the 'Show Me This' drop-down menu.", "ERROR", 0) elif Color == "": pythonaddins.MessageBox("You must select a color to symbolize the feature from the 'Like That' drop-down menu.", "ERROR", 0) elif FeatureGeometry == "" and Color == "": pythonaddins.MessageBox("You must select both a Feature from the 'Show Me This' drop-down menu and a color from the 'Like This' drop-down menu.", "ERROR", 0) else: pass # How do I select the feature from 'SelFC' that falls within the extent provided by 'SelExtent'??? Problem is, I can't figure out how to use the extent generated by 'SelExtent', which is really just the 'rectangle_geometry' produced by the tool, to select the particular feature from 'SelFC' that falls within the extent. I'm thinking maybe I should use onCircle instead as that produces a polygon object I might be able to do a Select By Location with for an Intersect, but thought I would see if any of the big brains here knew better... Thanks in advance
... View more
09-24-2013
12:21 PM
|
0
|
1
|
4766
|