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 would like to automatically export ArcGIS models to python scripts (and graphics for the model diagram).

In order to apply version control to ArcGIS Models my current workflow is to: a) build and refine the model, b) export to script and graphics, c) commit to source code control. Rinse, lather, repeat.

Step (b) is a brainless pointy clicky exercise with too much friction which c/should be automated. How?

share|improve this question
1  
I'm a little confused by your comments... You say above you want to "apply version control to the models" by exporting to Python. You follow that below stating that using Python Toolboxes won't work because "this breaks collaboration with people who aren't comfortable with python" and "from that point forward I'm on the hook for making even minor changes to the model." Once you have exported your models to Python, you cannot go back to a model, so aren't you still on the hook for making edits to exported Python? –  RyanDalton Apr 1 at 22:20
    
@RyanDalton, I don't make edits to the exported python (in this scenario). I just export, replace the existing file, and commit with appropriate comment. The revision control system is just used for recording history, diffing, and revert if necessary (no branching or merging). –  matt wilkie Apr 3 at 17:43

1 Answer 1

Yikes. This all sounds really painful for many reasons, not the least of which being that the ModelBuilder to Python exporter is quite flawed. I hope you commit the .tbx as well since if you actually need to revert back to a working model that's going to be the only option that is actually guaranteed to work.

It may be easier to bite the bullet and just move everything over to Python properly.

As far as I can tell there is no API method exposed to export a model to Python, but if you really wanted to you could probably automate the UI with macro software like AutoHotkey.

Alternatively, if you don't care about the exported model actually being executable and only informational, you might be able to use ArcObjects to do something with the IMdModel and related interfaces, e.g. dump all elements and processes to a text file.

Is there really any benefit to what you're currently doing though?

share|improve this answer
    
yes the .tbx is being committed as well as the exported .py. I have experimented with using python toolboxes instead, which are entirely textual and thus friendly to version control. However this breaks collaboration with people who aren't comfortable with python (90% of my org), which means from that point forward I'm on the hook for making even minor changes to the model. It also takes longer to get to the same point, for example one can drag and drop the Results panel after an interactive session to a model. With a .pyt it's pretty much a design and build from scratch. –  matt wilkie Apr 1 at 21:02
    
I see that as more of a documentation and training problem. If they don't have any incentive to learn they never will. Better to teach a man to fish and all. You could point them here as a starting point: What are some resources for learning ArcPy? –  blah238 Apr 1 at 21:09
    
For many of my co-workers it's more like leading a horse to water ;-) They're not GIS people, they're people who use GIS to get their real job done. They'll use and change models but won't touch a command prompt or plain text file. It's just too alien to their experience and skillset. In any case, I'll likely go the AHK route. Thanks. –  matt wilkie Apr 1 at 21:27

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.