My model is meant to create mosaic datasets within a gdb. I am using the "For" function, and setting it to 6. The output correctly creates 6 mosaic datasets, each with the prefix T.

I would like these to have a different name, grabbing the name of the gdb and then _# (so G_057329641020_01_1, G_057329641020_01_2, etc.). How can I add the renaming function?

enter image description here

2 Answers 2


There is a 2 step process you could do to get the output name "filegdbname_mosaic_dataset_number" i.e. "G_057329641020_01_1"

Step 1: Use the Parse Path model only tool to get the file gdb name. Make sure to set "Name" as the Parse type.

enter image description here

Step 2: You have already partially done this step, in that you have used the "For" iterator to generate a numberical value as the outputof the iterator. (I have renamed the tool output below from "Value" to "Iteration" to avoid confusion with the above image)

enter image description here

As the output name for your mosaic dataset, you can now use inline variable substition to create the output name.

Using my 2 images above, my output name would be %Value%_%Iteration% This would give me output names of:






I think I get what you are asking. If you are looking to add the name of a GDB automatically, you must want to loop over a bunch of them, otherwise you'd just manually place the name of the GDB in the file name....

I can only think in code now, try opening IDLE and run the following:

import arcpy, os

location = r'c:\temp'

#Create Mosaic Dataset Parameters:
in_workspace = r'c:\temp\x.gdb'
coordinates = 'NAD_1983_UTM_Zone_11N'
num_bands = ''
pixel_type = ''
product_definition = ''
product_band_definitions = ''

number_of_loops = 6

for (dirpath, _, filenames) in os.walk(location):
    if dirpath.endswith('.gdb'):
        x = len(dirpath.split('\\'))
        dataset_name = (dirpath.split('\\')[x-1]).replace('.gdb','')
    while number_of_loops > 0:
        arcpy.CreateMosaicDataset_management(in_workspace, dataset_name + str(number_of_loops), coordinates, num_bands, pixel_type, product_definition, product_band_definitions)
        number_of_loops -= 1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.