POST
|
Hi all, thank you for the helpful suggestions. Interestingly, setting the symbology in the parameter dialog of the tool properties did not solve the problem. However, I found that "SetParamter" was able to solve the problem. In the toolbox properties, the 5th parameter (so index 4) was set as a "Raster Dataset." At the end of the script, I just added the quick line below to set this parameter equal to my "lyr" variable after the symbology was applied to "lyr." arcpy.SetParameter(4,lyr)
Thanks again.
... View more
11-13-2019
08:50 AM
|
2
|
0
|
1325
|
POST
|
Hey Jake, thanks for the response. Good idea to check it through the console, didn't think of that. Unfortunately, it doesn't appear to be a version issue. I ran that on 2.4.1 through the console and the symbology did not revert. So it would seem to me the issue is not with the script itself, but with the behavior of how the output is handled when the script is imported into a toolbox and run that way. I will try it on 2.4.2 when it is approved by our IT for installation.
... View more
11-07-2019
10:35 AM
|
0
|
2
|
1325
|
POST
|
I'm trying to put together a custom version of a cut-fill tool that ends with adding the symbolized raster to a map in pro, if there is an active map. If I watch the table of contents while the script is running, the raster is added to the map and the symbology (classified, three classes based on VOLUME field) is successfully applied. However, between when the script finishes and the tool overall finishes, the symbology reverts to what would be the default symbology for the raster (stretch based on Value field). I tried setting arcpy.env.addOutputsToMap = False thinking that a tool's default behavior to add the output back to the map may be messing up the symbology, but that didn't change anything. #Note that outCF is the output raster defined earlier in the script.
#Add symbolized raster to map
#First, define the symbology based on a lyrx file--3 classes, breaking at 0
Temp_Symbology = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'Symbology_Template.lyrx') #Gets the path of the script file because the lyrx file is in the same folder
#Create variables referring to active map and dataframe
p = arcpy.mp.ArcGISProject("CURRENT")
#Look if there's an active map. If there isn't, i.e. m == None, then just skip the symbology.
m = p.activeMap
if m != None:
#Add layer to top of active dataframe.
lyr = m.addDataFromPath(outCF)
#arcpy.AddMessage("Layer name: %s" %lyr)
#Apply symbology from a layer file.
arcpy.ApplySymbologyFromLayer_management(lyr, Temp_Symbology)
#Calculate whole process run time in minutes
processEnd = (time.time() - processStart)/60
arcpy.AddMessage("Script took %s minutes to complete" %processEnd)
I've seen some other discussion here about a bug with the apply symbology from layer gp tool not working in python scripts in, but I don't think that's the case here because it is applied then reverts. I also tried a different approach for adding and symbolize the raster in case BUG-000108497 is still affecting things in version 2.4.1 which I'm running. lf = arcpy.mp.LayerFile(Temp_Symbology)
m.addLayer(lf,"TOP")
m.updateConnectionProperties(Temp_Symbology,outCF) The result looks as follows. When the last line of my script--the printing message with a total run time--executes the symbology from the layer has been applied. Moments later, when the tool dialog prints that it has successfully completed, the symbology of the output has changed back to a stretch. Thanks for your help!
... View more
11-07-2019
06:48 AM
|
0
|
5
|
1552
|
POST
|
Hi Nick, I think I'm having this same issue, but it's a little difficult to interpret your solution without seeing the the metadata file. Were you just clarifying that you should use tags 6&7 in the field map instead of 90&91? I tried entering pitch and roll as both sets individually, but still getting this same error message. Any other suggestions? Working on Pro V2.2.0 Thanks
... View more
08-28-2018
11:49 AM
|
0
|
1
|
1453
|
Title | Kudos | Posted |
---|---|---|
2 | 11-13-2019 08:50 AM |
Online Status |
Offline
|
Date Last Visited |
12-20-2023
04:57 PM
|