|
POST
|
Sorry about that, I didn't see the option to address the syntax. Even after select Python as the syntax there is not numbers for each row. The following is given me an error and it seems no what I do the script always stops at a certain process no matter if I change the process. but I just run just the #Creat SelParsA1 section in the projects python window it will run but not in the script so I am not sure what I am doing wrong. import arcpy, string, os
from importlib import reload
#Zooms to selected parcel in layout
#arcpy.env.addOutputsToMap = True
arcpy.env.overwriteOutput = True
aprx = arcpy.mp.ArcGISProject("CURRENT")
map = aprx.listMaps()[0]
lyr = map.listLayers("TAXLOTS")[0]
lyt = aprx.listLayouts()[0]
mf = lyt.listElements("MAPFRAME_ELEMENT")[0]
arcpy.env.workspace = os.path.dirname(aprx.filePath)
wp = os.path.dirname(aprx.filePath)
values = arcpy.GetParameterAsText(0)
fieldName = "DXF_TEXT"
values = values.split(";") # split values into list
values = ["'{0}'".format(v) for v in values] # add single quotes
whereClause = "{0} IN ({1})".format(fieldName, ",".join(values))
arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", whereClause)
Name = arcpy.GetParameterAsText(1)
for lyt in aprx.listLayouts():
for elm in lyt.listElements("TEXT_ELEMENT","Text"):
if elm.text == "Template":
elm.text = (Name)
#Zooms to selected parcel
ext = mf.getLayerExtent(lyr)
mf.camera.setExtent(ext)
mf.camera.scale *= 16
#Exports the selected parcels for SUBJECT_PROPERTY.
if int(arcpy.GetCount_management("TAXLOTS").getOutput(0)) > 0:
arcpy.Select_analysis("TAXLOTS", "SUBJECT_PROPERTY")
arcpy.SelectLayerByAttribute_management("TAXLOTS", "CLEAR_SELECTION")
#Update Subject Property symbology
#layer = m.listLayers('SUBJECT_PROPERTY')[0]
#arcpy.ApplySymbologyFromLayer_management(str(layer), "Symbology_SUBJECT_PROPERTY.lyrx")
del aprx, map, lyr, mf, lyt
'''
#Remove layer Subject property
aprx = arcpy.mp.ArcGISProject("CURRENT")
m = aprx.listMaps()[0]# assumes data to be added to first map listed
lyr = m.listLayers()[0]
m.removeLayer(lyr)
del aprx, m,lyr,
'''
#Udpate Subject Property datasource
aprx = arcpy.mp.ArcGISProject("CURRENT")
map = aprx.listMaps()[0]
lyt = aprx.listLayouts()[0]
lyr = map.listLayers("SUBJECT_PROPERTY")[0]
mf = lyt.listElements("MAPFRAME_ELEMENT",'*')[0]
try:
cp = lyr.connectionProperties
cp['connection_info']['database'] = wp
cp['dataset'] = 'SUBJECT_PROPERTY.shp'
lyr.updateConnectionProperties(lyr.connectionProperties, cp)
except:
pass
del aprx, map, lyt, lyr, mf
reload(arcpy)
arcpy.ClearWorkspaceCache_management()
#Creat SelParsA1
aprx = arcpy.mp.ArcGISProject("CURRENT")
map = aprx.listMaps()[0]
lyt = aprx.listLayouts()[0]
lyr = map.listLayers("SUBJECT_PROPERTY")[0]
mf = lyt.listElements("MAPFRAME_ELEMENT",'*')[0]
arcpy.env.workspace = os.path.dirname(aprx.filePath)
wp = os.path.dirname(aprx.filePath)
TAX = "TAXLOTS"
SP2 = "SUBJECT_PROPERTY"
arcpy.SelectLayerByLocation_management(TAX, "WITHIN_A_DISTANCE", SP2, "600 Feet", "NEW_SELECTION")
try:
if int(arcpy.GetCount_management("TAXLOTS").getOutput(0)) > 0:
arcpy.SelectLayerByAttribute_management("TAXLOTS", "REMOVE_FROM_SELECTION", "DXF_TEXT = ' ' OR DXF_TEXT IS NULL") #"\"DXF_TEXT\" = ' '"
arcpy.FeatureClassToFeatureClass_conversion("TAXLOTS", wp, "SelParsA1")
except:
pass
arcpy.SelectLayerByAttribute_management("TAXLOTS", "CLEAR_SELECTION")
del lyr
lyr = map.listLayers("SelParsA1")[0]
try:
cp = lyr.connectionProperties
cp['connection_info']['database'] = wp
cp['dataset'] = 'SelParsA1.shp'
lyr.updateConnectionProperties(lyr.connectionProperties, cp)
except:
pass Error: Traceback (most recent call last):
File "D:\GIS Folder\Python_ArcGISPro\NotificationMapScripts\NotificationMapScriptTest_E.py", line 86, in <module>
arcpy.SelectLayerByLocation_management(TAX, "WITHIN_A_DISTANCE", SP2, "600 Feet", "NEW_SELECTION")
File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\management.py", line 8909, in SelectLayerByLocation
raise e
File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\management.py", line 8906, in SelectLayerByLocation
retval = convertArcObjectToPythonObject(gp.SelectLayerByLocation_management(*gp_fixargs((in_layer, overlap_type, select_features, search_distance, selection_type, invert_spatial_relationship), True)))
File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\geoprocessing\_base.py", line 511, in <lambda>
return lambda *args: val(*gp_fixargs(args, True))
arcgisscripting.ExecuteError: ERROR 999999: Something unexpected caused the tool to fail. Contact Esri Technical Support (http://esriurl.com/support) to Report a Bug, and refer to the error help for potential solutions or workarounds.
The base table definition string "SUBJECT_PROPERTY" is invalid.
The database was not found.
Failed to execute (SelectLayerByLocation).
Failed to execute (NotificatonMapScript). Runs in projects python window but not not included in the script posted above import arcpy, string, os
from importlib import reload
aprx = arcpy.mp.ArcGISProject("CURRENT")
m = aprx.listMaps()[0]
lyt = aprx.listLayouts()[0]
lyr = m.listLayers("SUBJECT_PROPERTY")[0]
mf = lyt.listElements("MAPFRAME_ELEMENT",'*')[0]
arcpy.env.workspace = os.path.dirname(aprx.filePath)
wp = os.path.dirname(aprx.filePath)
TAX = "TAXLOTS"
SP2 = "SUBJECT_PROPERTY"
arcpy.SelectLayerByLocation_management(TAX, "WITHIN_A_DISTANCE", SP2, "600 Feet", "NEW_SELECTION")
try:
if int(arcpy.GetCount_management("TAXLOTS").getOutput(0)) > 0:
arcpy.SelectLayerByAttribute_management("TAXLOTS", "REMOVE_FROM_SELECTION", "DXF_TEXT = ' ' OR DXF_TEXT IS NULL") #"\"DXF_TEXT\" = ' '"
arcpy.FeatureClassToFeatureClass_conversion("TAXLOTS", wp, "SelParsA1")
except:
pass
arcpy.SelectLayerByAttribute_management("TAXLOTS", "CLEAR_SELECTION")
del lyr
... View more
12-02-2020
10:45 AM
|
0
|
0
|
1600
|
|
POST
|
It appears that the toolbox script has issues in Pro python, this same script runs fine in ArcMap. I got past the Symobology by deleting m, lyr, lyt, mt after the first process but I had to re-add them before the Symobology process. Not sure why it's holding on to these, is there a way to clear the processes in Pro? Changed the last process of ApplySymobologyFromLayer_Managment to Add field #Add field to lyr SP = "SUBJECT_PROPERTY" arcpy.AddField_management(SP,"BUFF_DIST","DOUBLE") SP is a layer that is created by the first process and is in my layout in Pro, it's not being used by any process other than it's in the current layout . I do see 4 "SUBJECT_PROPERTY.shp.*****.11336.8984.sr.lock" in the explorer. Error after trying to use Add Field with the same script; ERROR 000464: Cannot get exclusive schema lock. Either being edited or in use by another application or service. Failed to execute (AddField).
... View more
11-16-2020
03:45 PM
|
0
|
0
|
1666
|
|
POST
|
I was able to move the layer. Thanks. aprx = arcpy.mp.ArcGISProject("CURRENT") m = aprx.listMaps()[0] for lyr in m.listLayers(): print("Map: {0} Layers".format(lyr.name)) for lyr in m.listLayers(): if lyr.name == "Sections": moveLayer = lyr if lyr.name == "Taxparcels": refLayer = lyr m.moveLayer(refLayer,moveLayer,"BEFORE")
... View more
11-13-2020
12:47 PM
|
0
|
0
|
5595
|
|
POST
|
I tried to use the following but get error. import arcpy aprx = arcpy.mp.ArcGISProject("CURRENT") m = aprx.listMaps()[0] #for lyr in m.listLayers(): m.moveLayer("Taxparcels","Sections","BEFORE") Error; Traceback (most recent call last): File "<string>", line 7, in <module> File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\utils.py", line 191, in fn_ return fn(*args, **kw) File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\_mp.py", line 1802, in moveLayer return convertArcObjectToPythonObject(self._arc_object.moveLayer(*gp_fixargs((reference_layer, move_layer, insert_position), True))) ValueError: Sections
... View more
11-13-2020
11:46 AM
|
0
|
0
|
5598
|
|
POST
|
I need to move some layers in my layout and I am not seeing how to do this in Pro through python. Am I not seeing it or is there no way to do this in Pro? ArcMap df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] for lyr in arcpy.mapping.ListLayers(mxd, "" ,df): if lyr.name == "Sections": moveLayer = lyr if lyr.name == "TaxParcels": refLayer = lyr arcpy.mapping.MoveLayer(df,refLayer,moveLayer,"BEFORE")
... View more
11-13-2020
10:09 AM
|
0
|
3
|
5608
|
|
POST
|
I have a script that I am trying to move over to Pro but some process in the script don't run. The script has about 7 process, the script does not fail but it doesn't finish the last process witch applies smbologyfromlayer. For example the last process doesn't run when I run the script but if copy it into Pro's python window and hit enter it runs fine, it updates the symbology. I have tried reload(arcpy) and arcpy.ClearWorkspaceCache_management() before the arcpy.ApplySymbologyFromLayer_management process but it still doesn't work. Not sure what I am missing or not doing... import arcpy, string, os
from importlib import reload
arcpy.env.overwriteOutput = True
aprx = arcpy.mp.ArcGISProject("CURRENT")
m = aprx.listMaps()[0]
lyr = m.listLayers("TAXLOTS")[0]
lyt = aprx.listLayouts("Layout1")[0]
mf = lyt.listElements("MAPFRAME_ELEMENT")[0]
arcpy.env.workspace = os.path.dirname(aprx.filePath)
wp = os.path.dirname(aprx.filePath)
#selects PinID from TAXLOTS
values = arcpy.GetParameterAsText(0)
fieldName = "PinID"
values = values.split(";") # split values into list
values = ["'{0}'".format(v) for v in values] # add single quotes
whereClause = "{0} IN ({1})".format(fieldName, ",".join(values))
arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", whereClause)
#Udpates Text Element Template from layout
Name = arcpy.GetParameterAsText(1)
for lyt in aprx.listLayouts():
for elm in lyt.listElements("TEXT_ELEMENT","Text"):
if elm.text == "Template":
elm.text = (Name)
#Zooms to selected parcel in layout
ext = mf.getLayerExtent(lyr)
mf.camera.setExtent(ext)
mf.camera.scale *= 15
#Exports the selected parcels for SUBJECT_PROPERTY.
if int(arcpy.GetCount_management("TAXLOTS").getOutput(0)) > 0:
arcpy.Select_analysis("TAXLOTS", "SUBJECT_PROPERTY")
arcpy.SelectLayerByAttribute_management("TAXLOTS", "CLEAR_SELECTION")
#Remove layer
for m in aprx.listMaps():
print("Map: {0} Layers".format(m.name))
for lyr in m.listLayers("SUBJECT_PROPERTY"):
m.removeLayer(lyr)
#Add layer Subject_property
arcpy.env.workspace = os.path.dirname(aprx.filePath)
wp = os.path.dirname(aprx.filePath)
shp_path = wp + '\\' + "SUBJECT_PROPERTY.shp"
map = aprx.listMaps()[0] # assumes data to be added to first map listed
map.addDataFromPath(shp_path)
reload(arcpy)
arcpy.ClearWorkspaceCache_management()
#Update Subject Property symbology
#arcpy.env.workspace = os.path.dirname(aprx.filePath)
#wp = os.path.dirname(aprx.filePath)
#This arcpy.ApplySymbologyFromLayer_management doesn't update the layer symbology in the script
arcpy.ApplySymbologyFromLayer_management("SUBJECT_PROPERTY", wp + '\\'+ "Symbology_SUBJECT_PROPERTY.lyrx")
If I copy the last process into Pro python window in the same project and run it, it does update the symbology. #Update Subject Property symbology
aprx = arcpy.mp.ArcGISProject("CURRENT")
arcpy.env.workspace = os.path.dirname(aprx.filePath)
wp = os.path.dirname(aprx.filePath)
arcpy.ApplySymbologyFromLayer_management("SUBJECT_PROPERTY", wp + '\\'+ "Symbology_SUBJECT_PROPERTY.lyrx")
... View more
11-04-2020
11:21 AM
|
0
|
3
|
1690
|
|
POST
|
I had to call the text element name and in my case it was 'Text 1' not the 'Template', like below. import arcpy
Name = arcpy.GetParameterAsText(1)
aprx = arcpy.mp.ArcGISProject("CURRENT")
for lyt in aprx.listLayouts():
for elm in lyt.listElements("TEXT_ELEMENT", "Text 1"):
elm.text = Name
... View more
11-02-2020
08:24 AM
|
1
|
1
|
4874
|
|
POST
|
That part of the code works fine, the parcel ParID's are selected and it zooms to the ParID's. The text element in the layout doesn't get updated by the arcpy.GetParameterAsText. This part doesn't do anything and I don't get any error. Name = arcpy.GetParameterAsText(1)
for lyt in aprx.listLayouts():
for elm in lyt.listElements("TEXT_ELEMENT"):
if elm.text == "Template":
elm.text = Name
... View more
11-02-2020
07:59 AM
|
0
|
1
|
4874
|
|
POST
|
That part of my codes works fine, with your recommendation gives me an error. values = ["{0}".format(v) for v in vals] ERROR 000358: Invalid expression.Failed to execute (SelectLayerByAttribute).
... View more
10-30-2020
01:58 PM
|
0
|
3
|
4874
|
|
POST
|
I have a script that I am trying to move over to Pro but I am having problems with updating text the layout . The text "Template" in the layout doesn't get updated by arcpy.GetParameterAsText. I don't know why it doesn't update, I don't get any errors. import arcpy, string, os
aprx = arcpy.mp.ArcGISProject(r"C:\Temp\ArcGISProTest.aprx")
#acc_val = arcpy.GetParameterAsText(0)
project = arcpy.mp.ArcGISProject("CURRENT")
layer1 = project.listMaps()[0]
lyr = layer1.listLayers("TAXLOTS")[0]
lyt = project.listLayouts("Layout1")[0]
mf = lyt.listElements('MAPFRAME_ELEMENT','*')[0]
arcpy.env.workspace = os.path.dirname(project.filePath)
wp = os.path.dirname(project.filePath)
values = arcpy.GetParameterAsText(0)
fieldName = "ParID"
values = values.split(";") # split values into list
values = ["'{0}'".format(v) for v in values] # add single quotes
whereClause = "{0} IN ({1})".format(fieldName, ",".join(values))
arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", whereClause)
Name = arcpy.GetParameterAsText(1)
for lyt in aprx.listLayouts():
for elm in lyt.listElements("TEXT_ELEMENT"):
if elm.text == "Template":
elm.text = Name
with arcpy.da.SearchCursor(lyr, ["SHAPE@","ParID"]) as cursor:
for row in cursor:
featureextent = mf.getLayerExtent(lyr)
# Set mapframe camera to featureextent
mf.camera.setExtent(featureextent)
# Reduce mapframe slightly to avoid feature clipping.
mf.camera.scale *= 1.2
#arcpy.RefreshActiveView()
... View more
10-30-2020
10:33 AM
|
0
|
7
|
4944
|
|
POST
|
Aw I didn't think of that. fc = 'featureclass'
tx = ['City1 State','City2 State','City3 State','City4 State', 'City5 State']
with arcpy.da.UpdateCursor(fc, ['field1']) as cursor:
for row in cursor:
row[0] = " ".join(row[0].split()[:-2])
cursor.updateRow(row)
del cursor I did notice that it did remove ones like 12345 StreetA St city State -->12345 StreetA St # What I wanted 0 StreetB St --> 0 # This is the issues, I would prefer if it just stayed 0 StreetB St.
... View more
10-21-2020
03:25 PM
|
0
|
2
|
1651
|
|
POST
|
How can I remove certain text/string from all the rows in a filed with out having to do multiple updatcursors? I need to remove the city and state from each row if there is no city and state just skip and keep going, some may not have any city and state . The city and stats might be different for each row. The state and city will always be at the end which would be :13. Some how I need to just work on the last 13 characters because some address use the city name. I need don't want to create another filed I just need the city and state removed from all the rows of a certain field. OID field1 field1 1 address city1 state1 address 2 address city2 State1 address 3 address city3 State1 address 4 address city2 State1 address 5 address city4 State1 address 6 address city5 State1 address 7 address city5 State1 address 8 address city1 State1 address 9 address city2 State1 address Was thinking something like this but I doesn't work. fc = 'featureclass'
tx = ['City1 State','City2 State','City3 State','City4 State', 'City5 State']
with arcpy.da.UpdateCursor(fc, ['field1']) as cursor:
for row in cursor:
if row[0][:13] in tx:
row[0] = row[0][:13]
cursor.updateRow(row)
del cursor
... View more
10-21-2020
01:41 PM
|
0
|
5
|
1786
|
|
POST
|
I wasn't getting what I needed from the code you provided but I was able to make the following work based on the code you provided. It's not as clean as yours but I am a newbie to python. Thanks. #populate F_ID3 & F_ID4
dict1 = dict()
with arcpy.da.SearchCursor(fc,['F_ID1','F_ID3','F_ID2']) as cursor:
for row in cursor:
dict1.setdefault(row[0],[]).append(str(row[2]))
with arcpy.da.UpdateCursor(fc,['F_ID1','F_ID3','F_ID4']) as cursor:
for row in cursor:
row[2] = ",".join(dict1[row[0]])
cursor.updateRow(row)
#Populate F_ID3
with arcpy.da.UpdateCursor(fc, ["F_ID1", "F_ID3"]) as cur:
cnt = Counter(row[0] for row in cur)
cur.reset()
for row in cur:
cur.updateRow([row[0], cnt.pop(row[0], None)])
... View more
10-16-2020
07:50 AM
|
0
|
0
|
940
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 08-01-2024 07:19 AM | |
| 1 | 07-26-2024 09:38 AM | |
| 1 | 01-08-2024 09:44 AM | |
| 1 | 03-07-2023 11:46 AM | |
| 1 | 11-02-2020 08:24 AM |
| Online Status |
Offline
|
| Date Last Visited |
02-12-2026
12:36 PM
|