|
POST
|
Line 4 was missing a quotation. Should be like the following. whereclause = """{} = '{}'""".format(arcpy.AddFieldDelimiters(InputFeatureClass,InputField),InputValue) It works now, thanks. I need the last part of the tool to work which I have the following python, so I can have a Boolean tool parameter to edit. Familiar with arcpy editing ? # Set Editing
workspace = r'C:\xyz'
edit = arcpy.da.Editor(workspace)
edit.startEditing(False, True)
edit.startOperation()
edit = arcpy.GetParameterAsText(3)
... View more
02-16-2017
06:40 AM
|
0
|
0
|
585
|
|
POST
|
Interesting, I used arcpy.AddMessage(whereclause) and get the following results. I am assuming that it successfully received the Inputvalue., but can't select the feature. Executing: QueryMxdFeatureClass "SWR Layers\Manholes" FACILITYID 5564 Start Time: Tue Feb 07 09:19:10 2017 Running script QueryMxdFeatureClass... "FACILITYID" = 5564 Failed script QueryMxdFeatureClass...
... View more
02-07-2017
09:24 AM
|
0
|
4
|
2105
|
|
POST
|
I placed the full path and still no luck. Here is the following error message. Traceback (most recent call last): File "C:\Users\...Scripts\QueryMxdFeatureClass.py", line 18, in <module> arcpy.SelectLayerByAttribute_management(InputFeatureClass, "NEW_SELECTION", whereclause) File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\management.py", line 6688, in SelectLayerByAttribute raise e ExecuteError: ERROR 000358: Invalid expression Failed to execute (SelectLayerByAttribute). Failed to execute (QueryMxdFeatureClass). Failed at Tue Feb 07 09:06:24 2017 (Elapsed Time: 0.47 seconds)
... View more
02-07-2017
09:10 AM
|
0
|
6
|
2105
|
|
POST
|
I have the following yet it is not working. Something still wrong with the expression. Does it matter whether it is a .sde feature class .or file geodatabase feature ? #Import Modules
import os,arcpy
#Set to current mxd and dataframe
mxd = arcpy.mapping.MapDocument ('CURRENT')
df = arcpy.mapping.ListDataFrames(mxd,"Layers")[0]
# Set the tool parameters
InputFeatureClass = arcpy.GetParameterAsText(0)
InputField = arcpy.GetParameterAsText(1)
InputValue = arcpy.GetParameterAsText(2)
# SQL expression used in selecting a feature
whereclause = """{} = {}""".format(arcpy.AddFieldDelimiters(InputFeatureClass,InputField),InputValue)
#Select feature by facilityid (InputValue)
arcpy.SelectLayerByAttribute_management(InputFeatureClass, "NEW_SELECTION", whereclause)
df.zoomToSelectedFeatures()
arcpy.RefreshActiveView()
... View more
02-07-2017
08:14 AM
|
0
|
8
|
2105
|
|
POST
|
Thanks. What messages would I want to troubleshoot my syntax ?
... View more
02-07-2017
07:27 AM
|
0
|
0
|
2105
|
|
POST
|
Oh didn't catch that. I changed it. I am unable to use print statements to test it out since I am running it as a tool which doesn't return print statements. whereclause = """{} = {}""".format(arcpy.AddFieldDelimiters(InputFeatureClass,InputField),InputValue)
... View more
02-06-2017
04:03 PM
|
0
|
2
|
3443
|
|
POST
|
I get the following message, don't know what is wrong. Executing: QueryMxdFeatureClass "SWR Layers\Manholes" FACILITYID 5564 Start Time: Mon Feb 06 15:41:32 2017 Running script QueryMxdFeatureClass... Failed script QueryMxdFeatureClass... SyntaxError: invalid syntax (QueryMxdFeatureClass.py, line 19) Failed to execute (QueryMxdFeatureClass). Failed at Mon Feb 06 15:41:33 2017 (Elapsed Time: 0.67 seconds) Here is my updated syntax #Import Modules
import os,arcpy
mxd = arcpy.mapping.MapDocument ('CURRENT')
df = arcpy.mapping.ListDataFrames(mxd,"Layers")[0]
# Set the parameters
InputFeatureClass = arcpy.GetParameterAsText(0)
InputField = arcpy.GetParameterAsText(1)
InputValue = arcpy.GetParameterAsText(2)
whereclause = """{} = {}""".format(arcpy.AddFieldDelimiters(InputFeatureClass,InputField,InputValue)
arcpy.SelectLayerByAttribute_management(InputFeatureClass, "NEW_SELECTION", whereclause)
df.zoomToSelectedFeatures()
arcpy.RefreshActiveView()
... View more
02-06-2017
03:45 PM
|
0
|
14
|
3443
|
|
POST
|
Does it need 'FACILITYID' since it is referenced in InputValue ? I tried this line and still having difficulty.
... View more
02-06-2017
03:22 PM
|
0
|
16
|
3443
|
|
POST
|
Thank you for the quick responses. I will work on this, at first glance, I need brackets and/or add field delimiter, etc. I am taking away from this that my sql clause needs work.
... View more
02-06-2017
01:39 PM
|
0
|
18
|
3443
|
|
POST
|
Any ideas why I am having problems by trying to have user input a string value for a feature, then have the feature selected. #Import Modules
import os,arcpy
mxd = arcpy.mapping.MapDocument ('CURRENT')
df = arcpy.mapping.ListDataFrames(mxd,"Layers")[0]
#os.chdir(r'C:\Users\dunderwood\Documents\MY_TEMPLATES\WASTEWATER_EDIT_TEMPLATE')
# Set the parameters
InputFeatureClass = arcpy.GetParameterAsText(0)
InputField = arcpy.GetParameterAsText(1)
InputValue = arcpy.GetParameterAsText(2)
whereClause = FACILITYID == InputValue"
arcpy.SelectLayerByAttribute_management(InputFeatureClass, "NEW_SELECTION", whereClause)
df.zoomToSelectedFeatures()
arcpy.RefreshActiveView()
... View more
02-06-2017
01:22 PM
|
1
|
21
|
8877
|
|
POST
|
Interesting, I went ahead and changed it to the following. "999" is the coded value for "unknown" My retired line labels are still showing. elif [DIAMETER] == "999" and shapeDict[oid] > 50:
return "Size ?" + '\x22' + " " + [MATERIAL]
... View more
12-07-2016
03:45 PM
|
0
|
0
|
547
|
|
POST
|
. I am successful in the flowing label expression to not show retired pipe lines. lyrName = " Main Lines Plan Label"
shapeDict = {}
with arcpy.da.SearchCursor(lyrName, ("OID@","SHAPE@LENGTH")) as cursor:
for row in cursor:
shapeDict[row[0]] = row[1]
def FindLabel([OBJECTID],[PLAN], [AGENCY], [GIS_STATUS] ):
oid = int([OBJECTID])
if [AGENCY] == "ABANDON":
return None
elif [GIS_STATUS] == "Retired":
return None
elif [PLAN] in (None, " ") and shapeDict[oid] > 50 :
return "Plan ?"
elif shapeDict[oid] > 50:
return [PLAN] However, I am having trouble with not displaying labels for pipelines that have been attributed as retired for another layer. Any ideas why? lyrName = "Main Lines Diameter & Material Label"
shapeDict = {}
with arcpy.da.SearchCursor(lyrName, ("OID@","SHAPE@LENGTH")) as cursor:
for row in cursor:
shapeDict[row[0]] = row[1]
def FindLabel ( [OBJECTID], [DIAMETER], [MATERIAL], [AGENCY], [GIS_STATUS] ):
oid = int([OBJECTID])
if [GIS_STATUS] == "Retired":
return None
elif [DIAMETER] in "999" and shapeDict[oid] > 50:
return "Size ?" + '\x22' + " " + [MATERIAL]
elif [DIAMETER] in (None, " ") and shapeDict[oid] > 50:
return "Size ?" + '\x22' + " " + [MATERIAL]
else:
return [DIAMETER] + '\x22' + " " + [MATERIAL]
... View more
12-07-2016
02:31 PM
|
0
|
2
|
2875
|
|
POST
|
I am using data driven pages in which I want a text element only shown in the identified page. However, when I change pages the text element is still visible. import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
# The text element is a textbox
elm = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "closeup")[0]
currentpage = mxd.dataDrivenPages.currentPageID
# (PAGE NAME 220 Also Known As (PAGE NUMBER 193) Must refer to PAGE NUMBER when scripting.
if currentpage == 193:
elm.visible = True
elif currentpage != 193:
elm.visible = False
arcpy.RefreshActiveView()
... View more
11-30-2016
08:41 AM
|
0
|
0
|
1096
|
|
POST
|
I went ahead with not adding an additional field. I am not concerned with performance issues. I arrived at the following at it does exactly what I wanted, thanks for everyone's input. ## The following label expression function is used to display labels for the main water lines. Specifically, labeling water lines that have not been assigned Plan info, with “Plan ?” Also, any water lines that are attributed as ABANDON will not display a label. Lastly, all other water lines will be labeled/displayed as is. Note: Displayed labels only if water main lines are greater than 50 feet. lyrName = " Main Lines Plan Label"
shapeDict = {}
with arcpy.da.SearchCursor(lyrName, ("OID@","SHAPE@LENGTH")) as cursor:
for row in cursor:
shapeDict[row[0]] = row[1]
def FindLabel([OBJECTID],[PLAN], [AGENCY]):
oid = int([OBJECTID])
if [AGENCY] == "ABANDON":
return None
elif [PLAN] in (None, " ") and shapeDict[oid] > 50 :
return "Plan ?"
elif shapeDict[oid] > 50 :
return [PLAN] I have the following as well but that last line is giving me problems. If I use else without the > 50 condition, it is fine. ## The following label expression function is used to display labels for the main water lines. Any water lines that are attributed as ABANDON will not display a label. Any water lines that are attributed as unknown(999) will be labeled as “Size ?” Also, water lines that are attributed as NULL (None) will be labeled as “Size ?” Lastly, all other water lines will be labeled/displayed as is. Note: Displayed labels only if water main lines are greater than 50 feet. Note: '\x22' Python syntax is used to allow for double quotes in the label expression to represent inches. lyrName = "Main Lines Diameter & Material Label"
shapeDict = {}
with arcpy.da.SearchCursor(lyrName, ("OID@","SHAPE@LENGTH")) as cursor:
for row in cursor:
shapeDict[row[0]] = row[1]
def FindLabel ( [OBJECTID], [DIAMETER], [MATERIAL], [AGENCY] ):
oid = int([OBJECTID])
if [AGENCY] == "ABANDON":
return None
elif [DIAMETER] in "999" and shapeDict[oid] > 50:
return "Size ?" + '\x22' + " " + [MATERIAL]
elif [DIAMETER] in (None, " ") and shapeDict[oid] > 50:
return "Size ?" + '\x22' + " " + [MATERIAL]
elif shapeDict[oid] > 50:
return [DIAMETER] + '\x22' + " " + [MATERIAL]
... View more
11-17-2016
02:20 PM
|
2
|
1
|
2875
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 11-03-2016 06:52 AM | |
| 1 | 05-10-2016 10:27 AM | |
| 1 | 02-06-2017 01:22 PM | |
| 1 | 05-01-2018 07:23 AM | |
| 1 | 03-03-2017 02:46 PM |
| Online Status |
Offline
|
| Date Last Visited |
11-11-2020
02:24 AM
|