Select to view content in your preferred language

Updating arcpy.management.SetMosaicDatasetProperties works within ArcGIS Pro but not in a Standalone script

249
4
08-21-2024 03:52 AM
Danfranco
Emerging Contributor

 

 

import arcpy
from pprint import pprint

# Path to mosaic dataset - This is an SDE connection
mosaic_dataset = r"\\UNC_path\mosaic_dataset_name"

# Set the maximum number of rasters per mosaic
max_rasters = 42

# Update the mosaic dataset properties
arcpy.management.SetMosaicDatasetProperties(
    in_mosaic_dataset=mosaic_dataset,
    max_num_per_mosaic=max_rasters
)
pprint(arcpy.GetAllMessages(), width=120)
print(f"Updated the maximum number of rasters per mosaic to {max_rasters} for {mosaic_dataset}.")

 

 

Here above is a very simple script, that runs perfectly within the Python window of ArcGIS Pro (v3.3.1), and updates the mosaic properties as expected.

However, I run the exact same script, and it runs with no errors, but doesn't update the number from the default of 20 to 42.

Any ideas?

Tags (2)
0 Kudos
4 Replies
DanPatterson
MVP Esteemed Contributor

Set Mosaic Dataset Properties (Data Management)—ArcGIS Pro | Documentation

The only difference in the code example that I see in the link is that they established arcpy.env.workspace rather than specify a file path, perhaps setting the workspace rather than your unc path is worth a try


... sort of retired...
0 Kudos
Danfranco
Emerging Contributor

Yeah I guess I omitted this from the actual script above, but I use a variable to associate the path to the SDE to set the arcpy.env.workspace.

Will give this a try though, thanks!

0 Kudos
Danfranco
Emerging Contributor

Tried, this again, no Error, just doesn't update

[[2, 0, 'Start Time: 21 August 2024 12:28:48'],
[3, 0, 'Succeeded at 21 August 2024 12:29:11 (Elapsed Time: 22.48 seconds)']]

This is all the message output I actually get from using the 

pprint(arcpy.GetAllMessages(), width=120)

 

0 Kudos
DuncanHornby
MVP Notable Contributor

I was able to replicate the issue, your code ran in the Python console but not in the IDE VSCode. After digging a little (i.e. reading the help file) I noted that the input is a Mosaic Layer object but you supply a full path string. So tweaking the code to this, it all worked outside arcpro.

import arcpy
from pprint import pprint

# Path to mosaic dataset - This is an SDE connection
mosaic_dataset = r"C:\Scratch\fGDB_Scratch.gdb\mosDTM"

# Set the maximum number of rasters per mosaic
max_rasters = 42

arcpy.MakeMosaicLayer_management(mosaic_dataset, "myMos")

# Update the mosaic dataset properties
arcpy.management.SetMosaicDatasetProperties(in_mosaic_dataset="myMos", max_num_per_mosaic=max_rasters)

pprint(arcpy.GetAllMessages(), width=120)
print(f"Updated the maximum number of rasters per mosaic to {max_rasters} for {mosaic_dataset}.")
0 Kudos