Batch saving MXDs to group layer files using ArcPy?

Batch saving MXDs to group layer files using ArcPy?

We are searching data for your request:

Forums and discussions:
Manuals and reference books:
Data from registers:
Wait the end of the search in all databases.
Upon completion, a link will appear to access the found materials.

Does anyone have / know of a script that converts all the MXD's in a folder to individual group layer files ?

It needs to use the MXD name as the group layer file name.

I actually just needed to do this too. I posted an ArcGIS toolbox but the code is:

import os import arcpy import inspect import glob import uuid import inspect codeDir = os.path.dirname(inspect.getfile(inspect.currentframe())) EmptyGroupLayerFile = codeDir+"/EmptyGroup.lyr" inArg1 = sys.argv[1] inArg2 = sys.argv[2] def printit(inMessage): arcpy.AddMessage(inMessage) def makeLyrFromMXD(inMXD, outLyr): if not (os.path.exists(inMXD)): printit( "ERROR: {} does not exist".format(inMXD)) return False if not (os.path.exists(EmptyGroupLayerFile)): printit( "ERROR: {} does not exist".format(EmptyGroupLayerFile)) return False if (os.path.exists(outLyr)): printit( "Skipping: {} already exists".format(outLyr)) return True printit( "Making Layer file: {0}".format(outLyr)) mxd = arcpy.mapping.MapDocument(inMXD) ###Right now, just doing the first Dataframe, this could be modified df = arcpy.mapping.ListDataFrames(mxd)[0] theUUID = str(uuid.uuid1()) iGroupLayerRaw = arcpy.mapping.Layer(EmptyGroupLayerFile) = theUUID arcpy.mapping.AddLayer(df,iGroupLayerRaw,"TOP") groupBaseName = os.path.basename(outLyr).split(".")[0] for lyr in arcpy.mapping.ListLayers(df): if not ( == theUUID): if (lyr.isGroupLayer): print "Adding Group: " arcpy.mapping.AddLayerToGroup (df, iGroupLayer, lyr, "Bottom") elif (lyr.longName == arcpy.mapping.AddLayerToGroup (df, iGroupLayer, lyr, "Bottom") else: iGroupLayer = lyr = groupBaseName arcpy.SaveToLayerFile_management(iGroupLayer, outLyr) return os.path.exists(outLyr) def doMultiple(inDir,outDir): for iMxd in glob.glob(inDir+"/*.mxd"): lyrFile = outDir+"/"+os.path.basename(iMxd).lower().replace(".mxd",".lyr") makeLyrFromMXD(iMxd, lyrFile) if(not os.path.exists(EmptyGroupLayerFile)): printit("Error: {} is missing, can not run.".format(EmptyGroupLayerFile)) else: if (os.path.isdir(inArg1) and (os.path.isdir(inArg2))): doMultiple(inArg1,inArg2) elif (os.path.isfile(inArg1)): if (os.path.exists(inArg2)): printit("Error: {} already exists".format(inArg2)) else: makeLyrFromMXD(inArg1,inArg2) else: printit("Unable to understand input parameters")

Arcgis.features module¶

The arcgis.features module contains types and functions for working with features and feature layers in the GIS.

Entities located in space with a geometrical representation (such as points, lines or polygons) and a set of properties can be represented as features. The arcgis.features module is used for working with feature data, feature layers and collections of feature layers in the GIS. It also contains the spatial analysis functions which operate against feature data.

In the GIS, entities located in space with a set of properties can be represented as features. Features are stored as feature classes, which represent a set of features located using a single spatial type (point, line, polygon) and a common set of properties. This is the geographic extension of the classic tabular or relational representation for entities - a set of entities is modelled as rows in a table. Tables represent entity classes with uniform properties. In addition to working with entities with location as features, the system can also work with non-spatial entities as rows in tables. The system can also model relationships between entities using properties which act as primary and foreign keys. A collection of feature classes and tables, with the associated relationships among the entities, is a feature layer collection. FeatureLayerCollections are one of the dataset types contained in a Datastore. Finally, features are not simply entities in a dataset. Features have a visual representation and user experience - on a map, in a 3D scene, as entities with a property sheet or popups.

Watch the video: Convert ArcGIS file types .lyr.mxd to QGIS with SLYR. burdGIS


  1. Gare

    I accept it with pleasure. In my opinion, this is an interesting question, I will take part in the discussion. Together we can come to the right answer.

  2. Abraham

    And, exactly you, what will you give your loved ones for the New Year? I read the polls, in America every third American will not give anything or even celebrate the New Year.

  3. Jason

    I think mistakes are made. Let us try to discuss this. Write to me in PM.

  4. Cunningham

    You are not right. I am assured. I can prove it. Write to me in PM, we will talk.

Write a message