Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am just getting started with ModelBuilder and I would like to create a folder in the same folder where the respective mxd is located. The tool have to be usable in different projects, so setting Current Workspace to a specific folder doesn't do the trick.

Is there any chance to get access to a path of the Home folder which would be the same in any given project?

share|improve this question

2 Answers 2

I don't think you'll be able to create a folder directly from Model Builder, but you can write a script that does it and call it from within Model Builder, as discussed in Integrating Scripts within a Model.

Here would be an example script that creates a folder in the directory of the current mxd:

from os.path import split, join, splitext, exists
from os import makedirs

#Get path to currently opened mxd.
filepath = arcpy.mapping.MapDocument('current').filePath

#Split directory from path name.
maindir, mxd = split(filepath)

#Path to new folder, which is named after mxd (minus the .mxd).
folder = join(maindir, splitext(mxd)[0])

#Create folder if it doesn't exist
if not exists(folder):
    makedirs(folder)
share|improve this answer
1  
The code above can be placed in a Calculate value model only tool and this can be part of your model. It's output could be a Boolean indicating a successful creation of a folder which is then a precondition to the rest of the model. –  Hornbydd Aug 11 '13 at 22:59
    
Thank you very much for your help. I tried it already, but it seems that there is a problem with the different Python versions I have installed. After I figured that out I will tell you if it worked. –  ThomasV Aug 12 '13 at 9:07

You can do this using model builder. Use the Create Folder and Parse Path tools. Set the Parse Type in the Parse Path tool to PATH. Connect Value as a precondition to Create Folder. In the Folder location variable, type in %Value%

enter image description here

share|improve this answer
    
The problem with your solution is, that the user has to set the path/mxd by himself and so has to browse through the file system. That's something I am trying to avoid. –  ThomasV Aug 15 '13 at 13:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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