2

Is it possible to export the elements and constants used in a layout to a Python script? Something similar to creating a model and exporting it to Python but instead of being a model, it's a layout?

I have created a layout which contains 4 dataframes. I would like to create a python script which loops through folders and updates the layout based on the layers in each folder (each folder represent a species). I also want each iteration to export to a .png and save as a new mxd. I’m not sure exactly where to start but feel there are so many layout elements that would need to be described (symbology ramp color, symbology classification, scale and extent of each layer, etc) . . . working from a template would be helpful. The end result would be 31 different mxd and associated png.

2
  • Generally, your original mxd should be designed to act as a template.
    – phloem
    Commented Sep 27, 2014 at 3:39
  • My original mxd indeed acts as a template but I don't know how to create a python script which uses/copies some of mxd elements/constants (such as extent of layers, color ramps, etc) for subsequent mxds.
    – JoeBird
    Commented Sep 29, 2014 at 3:23

1 Answer 1

1

This is certainly very possible to do using ArcPy, but it is a multi-step process, and one that I think you should take on in bite-size chunks.

You already have a layout with four data frames so I think the next steps are to learn

  1. how to reference each of those data frames - I would use arcpy.mapping.ListDataFrames
  2. how to add a dataset of your choice to one of those data frames - I would use arcpy.mapping.AddLayer

If you need help doing that then my recommendation would be to edit your question so that it addresses just this part first and then use your "code so far" to describe where you are stuck.

3
  • I can reference data frames, add layers and place them without problems and do some loops. But I would like to export my layout to python to get the exact wording used to tell each layer to have x extent, use y color ramp (in which I changed the outline colors), use symbology classification method z and xx number of categories (i.e. can't copy symbologies because the abundance ranges are different between species). I would like to export the layout to python so I can use it to build upon to create my script.
    – JoeBird
    Commented Sep 29, 2014 at 3:14
  • 1
    @JoeBird I'm not aware of any available "Export Layout to ArcPy" script that could read a template MXD and write runnable code to configure another MXD, and to try and write one seems overkill for what you describe. I think you need to break your requirements down into a series of discrete tasks and once you know how to achieve each, then stringing them together becomes much easier. How to do each of these discrete tasks could be researched/asked separately here but answering your current question with code to do it all is too broad for our focussed Q&A format.
    – PolyGeo
    Commented Sep 29, 2014 at 3:53
  • Alright, will work on writing a discrete task i.e. one script section at the time and will ask precise questions if help is needed. Thank you though for taking the time to comment on my broad request.
    – JoeBird
    Commented Oct 1, 2014 at 3:23

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.