|
POST
|
I would recommend using the supports() method on layer to check if it has the property "connectionProperties" for lyr in m.listLayers():
if lyr.supports("connectionProperties"):
print(lyr.connectionProperties["connection_info"])
lyr_update = lyr.connectionProperties
lyr_update['connection_info']['password']='<password>'
lyr_update['connection_info']['user']='dr'
lyr.updateConnectionProperties(lyr.connectionProperties, lyr_update)
... View more
10-03-2023
07:18 AM
|
1
|
4
|
4994
|
|
POST
|
We have pretty much the same setup for our Python scripts. They run on a server with Pro installed. I've never run into a licensing issue, but we use concurrent use licensing with the ArcGIS License Manager. The future seems bleak for the license manager though, so I am not recommending that as a solution. I too would like to know if anyone has a better solution.
... View more
09-29-2023
02:30 PM
|
0
|
0
|
4899
|
|
POST
|
What version of ArcGIS Pro are you using? Looks like the 2.9 version does not have support for the multiuser_mode parameter. Editor—ArcGIS Pro | Documentation
... View more
09-29-2023
10:02 AM
|
0
|
2
|
2846
|
|
POST
|
I think you need to save the project when you're done. Updating and fixing data sources—ArcGIS Pro | Documentation
... View more
09-28-2023
10:25 AM
|
0
|
1
|
5127
|
|
POST
|
You could also use dateutil.relativedelta for clearer looking adjustments and datetime.strftime to format the dates as strings. import datetime
from dateutil.relativedelta import relativedelta
import calendar
def calc_dates():
thisday = datetime.date.today()
lastmonth = thisday - relativedelta(months=1)
lastyear = thisday - relativedelta(years=1)
last_m_days = calendar.monthrange(lastmonth.year, lastmonth.month)[1]
startdate = datetime.datetime(lastyear.year, lastyear.month, 1)
enddate = datetime.datetime(lastmonth.year, lastmonth.month, last_m_days)
dates = (startdate.strftime('%m/%d/%Y'), enddate.strftime('%m/%d/%Y'))
return dates I also recommend a tuple as your return instead of a list so it's immutable. Just seems more semantically correct.
... View more
09-12-2023
04:06 PM
|
2
|
0
|
12273
|
|
POST
|
@RhettZufelt wrote: Agreed. However, by looking at the database name in the path, I assumed this was most likely pre python 3 and the .format works for both. R_ True! This only works in Python 3. Since @ScoutStanley mentioned Pro, I assumed Python 3.
... View more
09-12-2023
01:38 PM
|
0
|
1
|
2634
|
|
POST
|
Maybe this is what you're looking for then? You might have to save the mxd after you make the selection and before you run the script. I have not tested this, but I expect it to copy the identified fields of the one record you selected in the copy layer and paste those values into the identified fields of every selected record in the paste layer. You could also put this logic into a script tool or Python Toolbox, which would let you access the layers in the map directly without saving the mxd. import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Path\to\Map Document\your_filename.mxd")
try:
df = arcpy.mapping.ListDataFrames(mxd, "Name of DataFrame Here")[0]
copy_layer = arcpy.mapping.ListLayers(mxd, "CopyLayerName", df)[0]
copy_fields = ["columns1", "column2", "column3"]
paste_layer = arcpy.mapping.ListLayers(mxd, "PasteLayerName", df)[0]
paste_fields = ["column3", "column4", "column5"]
if len(copy_layer.getSelectionSet()) == 1 and len(paste_layer.getSelectionSet()) > 0:
copy_data = [row for row in arcpy.da.SearchCursor(copy_layer, copy_fields)][0]
with arcpy.da.UpdateCursor(paste_layer, paste_fields) as cursor:
for row in cursor:
cursor.updateRow(copy_data)
else:
raise Exception("One of the layers does not have the correct number of selected records.")
finally:
del mxd
... View more
09-12-2023
12:39 PM
|
1
|
1
|
1558
|
|
POST
|
I highly recommend levering string literals in Python with f"" PEP 498 – Literal String Interpolation | peps.python.org lyr.definitionQuery = f"DGCO.GIS_OWNER.ParcelQueue.JOINPIN = '{PIN}'"
... View more
09-12-2023
12:07 PM
|
1
|
4
|
2647
|
|
POST
|
I've only made one attempt at this though. I'd still like to see your framework. Perhaps Python Documents would be a better place for this discussion though?
... View more
09-11-2023
03:39 PM
|
0
|
0
|
3689
|
|
POST
|
I think there are ways to make a modular toolbox that reloads each time. For example, here's the main toolbox file that imports tools from separate .py files. I assume they're stored in a folder called "scripts" in the same directory as the main toolbox file. import os
import sys
# Import custom script tools.
ff_tools_rel_path = os.path.join(os.path.dirname(__file__), "scripts")
sys.path.append(ff_tools_rel_path)
import demo_tool
# Reload the custom scripts to allow ArcGIS Pro to see changes on refresh.
# This prevents having to restart ArcGIS Pro when changes are made.
from importlib import reload
reload(demo_tool)
from demo_tool import demoTool
class Toolbox(object):
def __init__(self):
"""Define the toolbox (the name of the toolbox is the name of
the .pyt file)."""
self.label = "Parent Toolbox Demo"
self.alias = "DemoToolbox"
# List of tool classes associated with this toolbox
self.tools = [
demoTool
] Here's an example of the .py file for a tool. import arcpy
import helper_library as helper
import importlib
importlib.reload(helper)
class demoTool(object):
def __init__(self):
"""Define the tool (tool name is the name of the class)."""
self.label = "Demo Tool"
self.description = ""
self.canRunInBackground = False
def getParameterInfo(self):
"""Define parameter definitions"""
params = None
return params
def isLicensed(self):
"""Set whether tool is licensed to execute."""
return True
def updateParameters(self, parameters):
"""Modify the values and properties of parameters before internal
validation is performed. This method is called whenever a parameter
has been changed."""
return
def updateMessages(self, parameters):
"""Modify the messages created by internal validation for each tool
parameter. This method is called after internal validation."""
return
def execute(self, parameters, messages):
"""The source code of the tool."""
arcpy.AddMessage(helper.exampleFunction())
return You'll notice it also imports a "helper_library" file. It's an example of having another .py file acting like a custom library for helper functions that might be shared across tools. The helper function used in the example above would be in a simple .py file too. def exampleFunction():
return "I can help!"
... View more
09-11-2023
03:37 PM
|
0
|
0
|
3690
|
|
POST
|
Without a key field, you cannot do multiple features. You would have to manually select exactly one in each table to copy the values. Otherwise, there's no way for the code to match to the correct record.
... View more
09-11-2023
10:06 AM
|
0
|
3
|
2300
|
|
POST
|
If you need to run this as a script instead of a toolbox, you can access the selected records of a layer using the getSelectionSet() method on the layer object. Layer—ArcGIS Pro | Documentation You'll use some other arcpy.mp stuff to get to the layer you want in the map you want. EDIT: Sorry, I forgot you're using ArcMap. You can still get the selection set of a layer with arcpy.mapping Layer—ArcMap | Documentation (arcgis.com)
... View more
09-11-2023
09:12 AM
|
1
|
1
|
2311
|
|
POST
|
You need a key field to relate tables like this. Agreed that ObjectID is not a good key field. Do you have a field that relates a particular record from the copy layer to the paste layer?
... View more
09-11-2023
08:59 AM
|
0
|
4
|
2314
|
|
POST
|
@JMerryline wrote: I would like to change the names of a fields in the attribute table called Station ID (to have a sequential name that I have created. Have you already coded the logic in Python to generate this sequential value?
... View more
09-08-2023
03:18 PM
|
0
|
0
|
2128
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 10-23-2025 03:53 PM | |
| 1 | 04-28-2026 07:25 AM | |
| 1 | 03-19-2026 08:59 AM | |
| 1 | 02-12-2026 01:37 PM | |
| 1 | 12-01-2025 06:19 AM |