I am trying to create a geoprocessing tool using ModelBuilder that will create 3 folders with geodatabases inside for the current ArcGIS Pro project I am in.
I saw you can use inline variable substitution to call the scratch geodatabase and the scratch folder, but can you write to your current project folder?
I plan to assign this tool to a custom ribbon so I can use it in new projects.
If anything, I can create a variable called "Workspace" and use it as a model parameter every time I run the tool. I would then need to navigate to the current project's project folder to run the rest of the tool. I was just wondering if I could do that automatically without Python.
Best Answer
Note that this solution does work, but it does not use variable substitution and it does use two lines of Python (but all within a model-builder model). It's quite simple...
Suggested Solution
Add a 'Calculate Value' utility tool to the model with the following parameters:
Expression:
os.path.dirname(arcpy.env.scratchWorkspace)
Code Block:
import os
Data Type: Folder
(For readability, rename the output item to
Project Folder
or similar).You can then use this (eg, 'Project Folder') output item of the 'Calculate Value) as the input of other model tools where you need the project folder as input (eg, as the 'Output Location' of another tool). I tested it with the 'Create Folder' tool and it worked to create a new folder within the project folder.
Explanation
In ArcGIS Pro, the scratch and current workspaces default to the default project database. The directory of the default project database is the project directory. So this uses Python to get the directory in which the scratch database resides, ie, the project directory.
Caveat
This will fail if you have your
scratchWorkspace
set to anything other than the default. If this is the case, useworkspace
instead - unless that is also set to something other than the default, in which case, this solution won't work at all.