|
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
|
4934
|
|
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
|
1317
|
|
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
|
4227
|
|
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
|
4227
|
|
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
|
4227
|
|
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
|
4297
|
|
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
|
1337
|
|
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
|
1472
|
|
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
|
710
|
|
POST
|
OK, I think what is hold me up is that there are some 'Nulls' in field2.
... View more
10-09-2020
03:44 PM
|
0
|
0
|
480
|
|
POST
|
This is what I've got, I posted the wrong one at first. I get no errors but field1 row doesn't get populated with field2 is field1 row is blank. flds = ['field1','field2']
search_feats = {f[0]:f[1] for f in arcpy.da.SearchCursor(fc1,flds)}
with arcpy.da.UpdateCursor(fc1,flds) as upd_cur:
for upd_row in upd_cur:
if upd_row[1] == None:
upd_row[1] = search_feats[upd_row[0]]
upd_cur.updateRow(upd_row)
else:
pass
del upd_cur
... View more
10-09-2020
01:42 PM
|
0
|
2
|
3048
|
|
POST
|
That was my initial thought and makes sense but if Field1 is unique pass field2 and field3 to updatecursor and update field1 with field2 if filed1 is blank? I am still trying to make sense of Dictionary keys and how to loop through them.
... View more
10-09-2020
01:38 PM
|
0
|
0
|
3048
|
|
POST
|
Joe, thanks for the response. I see but after using your code and implementing my data and running the code field1 is not being populated with field2 if the fied1 rows are blank. The error I was getting was with my code was; Traceback (most recent call last): File "D:\GIS Folder Scripts\UpdateFiledBlanks.py", line 10, in <module> upd_row[0] = search_feats[upd_row[1]] #FIELD_2 KeyError: 'Final Plat'
... View more
10-09-2020
09:57 AM
|
0
|
2
|
3048
|
|
POST
|
I can do it with a basic arcpy.da.UpdateCurosr but I am trying to figure out how to use arcpy.da.UpdateCurosr with dictionary key. I am trying to populate Field1 if the row is blank but if not then continue on to the next row. I have the following but I get error, upd_row[0] = search_feats[upd_row[1]] #FIELD_2
KeyError: 'Blah Text'
>>> flds = ['Field1','Field']
search_feats = {f[0]:f[1:] for f in arcpy.da.SearchCursor(fc1, flds)}
with arcpy.da.UpdateCursor(fc1, flds) as upd_cur:
for upd_row in upd_cur:
#if upd_row[0] is None:
if upd_row[0] != None:
#if upd_row[0] in ("", ' ', None):
upd_row[0] = search_feats[upd_row[1]] #FIELD1
upd_cur.updateRow(upd_row)
del upd_cur
... View more
10-09-2020
08:32 AM
|
1
|
11
|
4071
|
| 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 |
07-14-2025
07:49 AM
|