POST
|
Randy, I tried your codes and they did not work for me. Thanks. Error: Traceback (most recent call last): File "C:\Working\Python\python_script\copy_test_1.py", line 9, in <module> for lyr in arcpy.mapping.ListLayers(mxd, layerName)[0]: File "c:\program files (x86)\arcgis\desktop10.6\arcpy\arcpy\arcobjects\mixins.py", line 401, in __iter__ self.layers AttributeError: LayerObject: Get attribute layers does not exist
... View more
09-21-2018
12:32 PM
|
0
|
1
|
1006
|
POST
|
# Import arcpy module
import arcpy,sys, os
arcpy.env.overwriteOutput = True
arcpy.env.workspace = r"C:\GIS\MyGeodatabase.mdb"
mxd = arcpy.mapping.MapDocument("CURRENT")
layerName = 'Street'
lyr = arcpy.mapping.ListLayers(mxd, layerName)[0]
fc = arcpy.GetParameterAsText(0)
Street = "Street"
street_CopySelected = "street_CopySelected"
df = arcpy.mapping.ListDataFrames(mxd)[0]
for lyr in arcpy.mapping.ListLayers(mxd,"",df): #loop layers
if lyr.name == "Street":
arcpy.AddMessage("name: " + lyr.longName)
layerName = lyr.longName
Street = lyr.longName
selCount = len(lyr.getSelectionSet())
arcpy.AddMessage("{1} features selected.".format(fc, selCount))
try:
# Process: Copy Features
arcpy.CopyFeatures_management(Street, street_CopySelected, "", "0", "0", "0")
del df
except Exception as e:
print e.args[0]
... View more
09-21-2018
11:17 AM
|
0
|
1
|
2596
|
POST
|
Thanks for the tip! When I drag my Street layer out of TopLayerGroup, the codes work just fine. I begin to suspect if group layer is supported by ESRI for doing most of data management tools?
... View more
09-21-2018
11:15 AM
|
0
|
0
|
1006
|
POST
|
09-21-2018
11:12 AM
|
0
|
0
|
2596
|
POST
|
TopLayerGroup\Street I replaced Street = lyr.longName and it still does not work. It gives my the selection count but not doing the copy features. Thanks. My code looks like this: df = arcpy.mapping.ListDataFrames(mxd)[0] for lyr in arcpy.mapping.ListLayers(mxd,"",df): #loop layers if lyr.name == "Street": Street= lyr.longName selCount = 0 selCount = len(lyr.getSelectionSet()) arcpy.AddMessage("{1} features selected.".format(fc, selCount)) try: # Process: Copy Features arcpy.CopyFeatures_management(lyr.Street, street_CopySelected, "", "0", "0", "0") del df except Exception as e: print e.args[0]
... View more
09-21-2018
10:27 AM
|
0
|
6
|
2596
|
POST
|
It just doesn't find that layerName so the script did nothing. Thanks.
... View more
09-21-2018
09:25 AM
|
0
|
8
|
2596
|
POST
|
Hi I created a model builder and scripted it out to python. My issue is it only works if the layer is outside of group layer. How can I modify it to works in both inside and outside of group layer? Thank you very much for your help. import arcpy,sys, os arcpy.env.overwriteOutput = True arcpy.env.workspace = r"C:\GIS\MyGeodatabase.gdb" mxd = arcpy.mapping.MapDocument("CURRENT") layerName = 'street' lyr = arcpy.mapping.ListLayers(mxd, layerName)[0] fc = arcpy.GetParameterAsText(0) Street = "Street" selCount = 0 if lyr.getSelectionSet(): # If there are selected features selCount = len(lyr.getSelectionSet()) arcpy.AddMessage("{0} has {1} features selected.".format(fc, selCount)) try: # Process: Copy Features arcpy.CopyFeatures_management(Street , street_CopySelected, "", "0", "0", "0")
... View more
09-21-2018
08:16 AM
|
0
|
15
|
4844
|
POST
|
Hi I use "Copy Features" tool to make a layer from selection. It's crucial that I check for a selection first or it will copy the whole layer. Please help me with that. Thank you!
... View more
08-31-2018
04:19 PM
|
0
|
2
|
1314
|
POST
|
Thank you for all your help. I chose the easiest route for me which is using the built in parameters but all suggestions are very helpful. I might try them later.
... View more
08-31-2018
01:44 PM
|
1
|
0
|
4292
|
POST
|
Thank you so much. From your example, I created 2 parameters, 1 folder datatype for path and 1 string datatype for filename. It works!
... View more
08-31-2018
01:43 PM
|
0
|
0
|
4292
|
POST
|
Thanks Joshua. I was hoping for a more simple approach to my issue. Most of the time I just use model builder and script out to python. The code I put here is just the last step of my workflow not the whole thing so I do not think I'm able to write all that in addin. I've not learned to code in python yet. I tried to use the output parameter but it didn't work.
... View more
08-31-2018
10:37 AM
|
0
|
1
|
4292
|
POST
|
Hi I have arcpy scripts to run in arcmap. Last step is "Table to Excel Conversion" Instead of having the excel file name and location hard-coded I'd like to get the user's input for those. Your help is greatly appreciated! # sftMap.py # Created on: 2018-08-31 10:42:32.00000 # (generated by ArcGIS/ModelBuilder) # Description: # --------------------------------------------------------------------------- # Import arcpy module import arcpy arcpy.env.overwriteOutput = True # Local variables: SiteNum_AcreCal = "C:\\...\\scratch\\parcel_Select_SpatialJoin_TableToExcel.xls" parcel_Select_SpatialJoin_Ta_xls = "C:\\...\\ArcGIS\\parcel_Select_SpatialJoin_Ta.xls" # Process: Table To Excel arcpy.TableToExcel_conversion(ParcelSiteNum, SiteNum_AcreCal, "NAME", "CODE")
... View more
08-31-2018
09:27 AM
|
0
|
8
|
6357
|
DOC
|
Thanks Jake. It's CURRENT_TIMESTAMP. My brilliant co-worker figured it out!
... View more
02-15-2018
07:01 AM
|
0
|
0
|
4640
|
DOC
|
You are right. My query (EditDate = Current_Date) did not work in rest service directory "Unable to perform query. Please check your parameters". If I put EditDate ='02-14-2018' it works. What I want is today date not a fixed date. I've tried from now, date to current_date. None works. Any idea? Thanks.
... View more
02-14-2018
01:31 PM
|
0
|
0
|
4640
|
DOC
|
Hi Jake, Your tool works fine for me when I use Where Clause with text fields. However when I use Where Clause with date field: EditDate=Current_Date, it gives me error message: URL is incorrect. Or, Service is secure, please enter username and password. Any idea how I could fix this ? My layer is a feature service layer from AGOL. EditDate and Editor are 2 fields that automatically added when you turn on "Keep track of who created and last updated features". Thank you so much for your help.
... View more
02-14-2018
12:37 PM
|
0
|
0
|
4640
|
Title | Kudos | Posted |
---|---|---|
1 | 08-21-2020 05:42 AM | |
1 | 09-28-2021 05:11 AM | |
1 | 09-17-2021 10:17 AM | |
1 | 05-19-2020 04:39 AM | |
1 | 09-21-2018 02:06 PM |
Online Status |
Offline
|
Date Last Visited |
01-19-2022
01:25 PM
|