Changing working paths in model tools?

2976
6
02-04-2016 06:41 AM
MattFegley
New Contributor III

Methods of arcpy.mapping can be used to update workspace paths in MXDs, and I have done. Can a similar technique be used to update paths within modelbuilder models/tools? I'm learning (hacking my way through) modelbuilder (and python for that matter) and probably should have set some environment parameters...or something...but of course I did not.

Specifically, I have some tools pointing at feature classes in specific file GBDs. I copied the entire project directory and named it something else. Used arcpy.mapping to update paths in the new (copied) MXD, but all the model(s) tools are still pointing to the original directory.

Any thoughts on this would be appreciated.

Thanks.

0 Kudos
6 Replies
DanPatterson_Retired
MVP Esteemed Contributor

did you see the help topic on relative paths...Setting general model properties—Help | ArcGIS for Desktop

and your data etc etc have to be relative to the model not off in a folder to the side

0 Kudos
MattFegley
New Contributor III

Thanks Dan I will take a look

0 Kudos
RebeccaStrauch__GISP
MVP Esteemed Contributor

My guess is you just aren't getting it to save.  Although not model builder, I do have a python addin that might work for you, or at least you can change the .addin in the filename to .zip and look at the python scripts.  How I approached the problem is to run the script to give a report of the broken links...edit the output excel or .csv file...make sure to same the file to .csv and us it for input to fix the path names.  When possible, I copy the mxd's to a new folder to test or to run, then replace the old.  It may be more complicated than you need, but you can check it out here Python addin for data inventory and “broken-link” repair.    I have additions that I will even tually make to the programs, but right now I'm off on other projects and it works for us.

0 Kudos
MattFegley
New Contributor III

thanks will check it out

0 Kudos
WesMiller
Regular Contributor III

If in your original model you navigated to the feature classes you may have to go through each tool and point them to the maps feature layers,I think this is the direction i would take. But you could also set a workspace variable and use in line variables for each of your paths. Or you could export your model to a python script and use a find replace to change your paths.

0 Kudos
MattFegley
New Contributor III

thanks Wes. It seems for tools that already exist in the models, I will have to go back and edit each one.

The export -> find/replace is interesting if I can figure out how to do that.

in future perhaps I will plan and use relative paths to avoid this kind of thing...