|
POST
|
That works. It makes sense that the script tool didn't know the map. Thanks for pointing that out. Nowhere did I come across .activeMap in the help pages.
... View more
09-21-2021
06:51 AM
|
0
|
1
|
3934
|
|
POST
|
Dan, Didn't realize that was there. It's checked on, anyway.
... View more
09-20-2021
02:12 PM
|
0
|
0
|
3985
|
|
POST
|
Hello, I replied to this post where the user had the same issue I'm experiencing. Since it was a Pro question I decided to repost here in Python. The problem I'm facing involves my custom script tool not adding a feature class to an open Pro project. I'm using Pro 2.8. Working from a notebook, this successfully adds a feature class to the map. import arcpy, os
data = r'path\to\BaseLayer_Processed_Elementary_08302021_clip'
arcpy.env.addOutputsToMap = True
try:
arcpy.management.MakeFeatureLayer(data, data)
except:
print(arcpy.GetMessages()) But, according to the docs the above only creates a temp layer in the map. So, unless you save the map or export the layer to a feature class it won't be saved. So, I tried the below script: import arcpy, os
data = r'path\to\BaseLayer_Processed_Elementary_08302021_clip'
arcpy.env.addOutputsToMap = True
try:
# Write the selected features to a new featureclass
arcpy.CopyFeatures_management(data, os.path.basename(data))
except:
print(arcpy.GetMessages()) Both scripts work to add a feature class to the map. However, when I convert to a script tool to run within pro it runs successfully, but nothing is added to the map. Tool version of the script: import arcpy, os
#input feature class from model. It will be added to the map.
data = arcpy.GetParameterAsText(0)
arcpy.env.addOutputsToMap = True
arcpy.AddMessage(f'adding to map: {data}')
try:
#Copies features from the input feature class or layer to a new feature class.
arcpy.CopyFeatures_management(data, os.path.basename(data))
except:
arcpy.AddMessage(arcpy.GetMessage()) Tool interface:
... View more
09-20-2021
12:47 PM
|
0
|
6
|
4070
|
|
POST
|
Hello, Any success with this? As of Pro 2.8 I'm having the same issue. Working from a notebook, this successfully adds a feature class to the map. import arcpy, os
data = r'path\to\BaseLayer_Processed_Elementary_08302021_clip'
arcpy.env.addOutputsToMap = True
try:
arcpy.management.MakeFeatureLayer(data, data)
except:
print(arcpy.GetMessages()) But, according to the docs the above only creates a temp layer in the map. So, unless you save the map or export the layer to a feature class it won't be saved. So, I tried the below script: import arcpy, os
data = r'path\to\BaseLayer_Processed_Elementary_08302021_clip'
arcpy.env.addOutputsToMap = True
try:
# Write the selected features to a new featureclass
arcpy.CopyFeatures_management(data, os.path.basename(data))
except:
print(arcpy.GetMessages()) Both scripts work to add a feature class to the map. However, when I convert to a script tool to run within pro it runs successfully, but nothing is added to the map. Tool version of the script: import arcpy, os
#input feature class from model. It will be added to the map.
data = arcpy.GetParameterAsText(0)
arcpy.env.addOutputsToMap = True
arcpy.AddMessage(f'adding to map: {data}')
try:
#Copies features from the input feature class or layer to a new feature class.
arcpy.CopyFeatures_management(data, os.path.basename(data))
except:
arcpy.AddMessage(arcpy.GetMessage()) Tool interface:
... View more
09-20-2021
12:37 PM
|
0
|
0
|
6432
|
|
DOC
|
@HannesZiegler It isn't possible to use a *.ipynb file in a script tool, correct? The only options I see are *.bat, *.com, *.exe, *.py and *.r. Will this be implemented at some point?
... View more
09-16-2021
11:08 AM
|
0
|
0
|
4502
|
|
POST
|
I've also tried the script as a standalone. No cigar.
... View more
09-02-2021
01:37 PM
|
0
|
1
|
2140
|
|
POST
|
"CURRENT" and "current" seem to be interchangeable I've found. However, if I reset the layers' symbology, and then run the script it works fine. But, I won't be resetting the symbology every time just so I can run the script, of course. By "reset" I mean physically changing the symbology: Graduated Colors --> Unique Values --> back to Graduated Colors. For some reason, it doesn't like that the symbology is already set as Graduated Colors.
... View more
09-02-2021
01:18 PM
|
0
|
2
|
2142
|
|
POST
|
Using the below script, I'm not able to change a layers symbology if it is already set. For example, I have three layers with 4 break values and labels each. The intention of the script is to change a break value and label. If I run the script on the layers as they exist currently, the script runs successfully, but the changes aren't made and I get an error of sorts in the Symbology pane. Three graduated colors layers before running script. I change a break value from 55.3 to 56.3, and it's corresponding label. Then I run the script. import arcpy, os, sys
# Reference a project, map, and layer using arcpy.mp
p = arcpy.mp.ArcGISProject('current')
m = p.listMaps()[0]
lyr = m.listLayers()
for l in lyr[1:4]:
sym = l.symbology
if hasattr(sym, 'renderer'):
if sym.renderer.type == 'GraduatedColorsRenderer':
sym.renderer.classificationField = 'VaccPercentageTotPop'
print(f'changing layer symbology for {l}')
#enter class break values
classBreakValues = [40, 45, 56.3, 100]
classBreakLabels = ["0% - 40%", "40.01% - 45%", "45.01% - 56.3%", "55.31% - 100%"]
# Run the renderer.breakCount function to use the classBreakValues array parameters as the values, and create a counter.
sym.renderer.breakCount = len(classBreakValues)
count = 0
#Create a loop to set the renderer
for brk in sym.renderer.classBreaks:
brk.upperBound = classBreakValues[count]
brk.label = classBreakLabels[count]
count +=1
l.symbology = sym
p.save()
###prints:
### changing layer symbology for Elementary Districts
### changing layer symbology for Secondary Districts
### changing layer symbology for Unified Districts The following is what happens. I get a warning in the Symbology pane (which doesn't tell me much). And my layers no longer have values.
... View more
09-02-2021
09:57 AM
|
0
|
4
|
2170
|
|
POST
|
The classification field has to be a number in order for the renderer to recognize it. It validated both with float and double. It will not work with text fields. I'm in contact with an ESRI analyst who is looking into why that is.
... View more
08-25-2021
01:23 PM
|
0
|
0
|
2339
|
|
POST
|
Thanks Dan. I looked at that one, but haven't got to it yet. Seems to be the right one.
... View more
08-25-2021
10:13 AM
|
0
|
0
|
2992
|
|
POST
|
Hi, I'm creating a script tool in Pro. What is the Data Type for a Pro project (*.aprx)? It would be the equivalent to the "ArcMap Document", I'd imagine. I've looked for: aprx, project, pro project
... View more
08-25-2021
08:29 AM
|
0
|
3
|
3021
|
|
POST
|
Just curious whether there were any updates to arcpy.mp that allow you to reverse the color ramp? Funny thing is, I can set, for example, Yellow to Red but not Red to Yellow. This works: sym.renderer.colorRamp = p.listColorRamps('Yellow to Red')[0] This produces an error: sym.renderer.colorRamp = p.listColorRamps('Red to Yellow')[0] ---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
In [40]:
Line 15: sym.renderer.colorRamp = p.listColorRamps('Red to Yellow')[0]
IndexError: list index out of range
---------------------------------------------------------------------------
... View more
08-24-2021
06:51 AM
|
0
|
0
|
1516
|
|
POST
|
Looking into this further, i realized this classification field I'm trying to identify is a from a joined table. If I use a field not from the joined table it works fine. The 'USER_PATIENT_ZIP' field is not from a joined table, and it validates. But, the field I want is from a joined table, and it's invalid somehow. if hasattr(sym, 'renderer'):
if sym.renderer.type == 'GraduatedColorsRenderer':
sym.renderer.classificationField = 'USER_PATIENT_ZIP'
print('Zip OK')
sym.renderer.classificationField = 'Blckgrp2020_iCareCountOfVaccinated_ALL_FirstDose_Black_PercentVa'
print('Dose OK')
### Zip OK
### ---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
In [193]:
Line 5: sym.renderer.classificationField = 'Blckgrp2020_iCareCountOfVaccinated_ALL_FirstDose_Black_PercentVa'
File C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\arcobjects\_base.py, in _set:
Line 109: return setattr(self._arc_object, attr_name, cval(val))
RuntimeError: Invalid classificationField : Blckgrp2020_iCareCountOfVaccinated_ALL_FirstDose_Black_PercentVa
---------------------------------------------------------------------------
... View more
08-23-2021
08:14 AM
|
0
|
0
|
2360
|
|
POST
|
I have this small code to change a feature layer's symbology. I'm referencing this help doc. When I try to change the break count I get a RuntimeError. And when I try to identify the classification field I don't seem to find it. Using a print statement, I identify other properties but not the field. The only thing i can think of is possibly because this field is set to a custom expression: for lyr in m.listLayers():
if lyr.isFeatureLayer:
sym = lyr.symbology
if hasattr(sym, 'renderer'):
#type of renderer
if sym.renderer.type == 'GraduatedColorsRenderer':
#sym.renderer.breakCount = 4 -RuntimeError: Invalid breakCount 4
print('break count: {}\nmethod: {}\nfield: {}'.format(sym.renderer.breakCount,
sym.renderer.classificationMethod,
sym.renderer.classificationField))
prints:
break count: 5
method: ManualInterval
field:
... View more
08-20-2021
02:22 PM
|
0
|
2
|
2394
|
|
POST
|
Thanks Dan. There's been attempts at this using Python: https://community.esri.com/t5/python-questions/set-number-formatting-in-python-in-arcgis-pro/td-p/1008360 And one Idea under consideration: https://community.esri.com/t5/arcgis-pro-ideas/copy-number-formats-across-multiple-fields-in/idi-p/1023864
... View more
08-18-2021
02:06 PM
|
0
|
1
|
2587
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 06-25-2026 12:25 PM | |
| 1 | 05-04-2026 08:45 AM | |
| 1 | 04-20-2026 01:20 PM | |
| 1 | 07-24-2025 01:27 PM | |
| 1 | 11-13-2025 08:22 AM |
| Online Status |
Offline
|
| Date Last Visited |
Friday
|