Пример #1
0
import arcpy.mapping as mapping
mxd = mapping.MapDocument("CURRENT")
for tableView in mapping.ListTableViews(mxd):
    print tableView.name
    

    sys.exit(
        "Unable to find a DataFrame named mainDF.  Please make sure default dataframe is named 'mainDF'."
    )
locatorDF = None
if len(MAP.ListDataFrames(MXD, "LocatorDF")) > 0:
    locatorDF = MAP.ListDataFrames(MXD, "LocatorDF")[0]
sectDF = None
if len(MAP.ListDataFrames(MXD, "SectionsDF")) > 0:
    sectDF = MAP.ListDataFrames(MXD, "SectionsDF")[0]
qSectDF = None
if len(MAP.ListDataFrames(MXD, "QSectionsDF")) > 0:
    qSectDF = MAP.ListDataFrames(MXD, "QSectionsDF")[0]

#REFERENCE PAGELAYOUT TABLE
pageLayoutRow = None
if len(MAP.ListTableViews(MXD, OrmapLayers.PAGELAYOUT_TABLE, mainDF)) > 0:
    pageLayoutTable = MAP.ListTableViews(MXD, OrmapLayers.PAGELAYOUT_TABLE,
                                         mainDF)[0]
    pageLayoutCursor = arcpy.SearchCursor(pageLayoutTable.name,
                                          "MapNumber = '" + MapNumber + "'")
    pageLayoutRow = pageLayoutCursor.next()
else:
    sys.exit(
        "Unable to find PageLayoutTable table.  Please check your TOC and config file."
    )

#REFERENCE CANCELLED NUMBERS TABLE
cancelledRow = None
if len(MAP.ListTableViews(MXD, OrmapLayers.CANCELLEDNUMBERS_TABLE,
                          mainDF)) > 0:
    cancelledTable = MAP.ListTableViews(MXD,
#IMPORT PARAMETERS
MapNumber = arcpy.GetParameterAsText(0)

#REFERENCE MAP DOCUMENT
MXD = MAP.MapDocument("CURRENT")

#COLLECT DATAFRAME INFORMATION
if len(MAP.ListDataFrames(MXD, "MainDF"))>0:
    mainDF = MAP.ListDataFrames(MXD, "MainDF")[0]
else:
    sys.exit("Unable to find a DataFrame named mainDF.  Please make sure default dataframe is named 'mainDF'.")

#REFERENCE CUSTOM DEFINITION QUERIES TABLE
defQueryRow = None
if len(MAP.ListTableViews(MXD, OrmapLayers.CUSTOMDEFINITIONQUERIES_TABLE, mainDF))>0:
    defQueryTable = MAP.ListTableViews(MXD, OrmapLayers.CUSTOMDEFINITIONQUERIES_TABLE, mainDF)[0]
    defQueryCursor = arcpy.SearchCursor(defQueryTable.name, "MapNumber = '" + MapNumber + "'") #--CUSTOM
    defQueryRow = defQueryCursor.next()    
else:
    sys.exit("Unable to find the Custom Definition Queries table.  Please check your TOC and config file.")  


#GET QUERY DEFINITIONS FOR EACH LAYER INTO A STRING
defQueryString = ""
for lyr in MAP.ListLayers(MXD, "", mainDF):
    if lyr.supports("DATASETNAME") and lyr.definitionQuery!="":
        defQueryString += ";" if len(defQueryString) > 0 else ""
        defQueryString += lyr.name + ":" + lyr.definitionQuery

#DETERMINE WHETHER TO INSERT OR UPDATE PAGELAYOUT ROW.
Пример #4
0
MapNumber = arcpy.GetParameterAsText(0)

#REFERENCE MAP DOCUMENT
MXD = MAP.MapDocument("CURRENT")

#COLLECT DATAFRAME INFORMATION
if len(MAP.ListDataFrames(MXD, "MainDF")) > 0:
    mainDF = MAP.ListDataFrames(MXD, "MainDF")[0]
else:
    sys.exit(
        "Unable to find a DataFrame named mainDF.  Please make sure default dataframe is named 'mainDF'."
    )

#REFERENCE PAGELAYOUT TABLE
pageLayoutRow = None
if len(MAP.ListTableViews(MXD, OrmapLayers.PAGELAYOUT_TABLE, mainDF)) > 0:
    pageLayoutTable = MAP.ListTableViews(MXD, OrmapLayers.PAGELAYOUT_TABLE,
                                         mainDF)[0]
    pageLayoutCursor = arcpy.SearchCursor(pageLayoutTable.name,
                                          "MapNumber = '" + MapNumber + "'")
    pageLayoutRow = pageLayoutCursor.next()
else:
    sys.exit(
        "Unable to find PageLayoutTable table.  Please check your TOC and config file."
    )

#DETERMINE WHETHER TO INSERT OR UPDATE PAGELAYOUT ROW.
if pageLayoutRow == None:
    theCursor = arcpy.InsertCursor(pageLayoutTable.name)
    theRow = theCursor.newRow()
else:
Пример #5
0
def crawlmxds(folder):
    """
    Given a directory search for mxd files. Every file with extension ".mxd" will 
    be opened in order to list layers with broken data links. If user input matches
    any features listed, it then replaces the workspace of broken layers.

    Parameters
    ----------
    folder: string, directory to map documents

    Returns
    -------
    result: relinked feature data sources.
    """

    for root, dirs, files in os.walk(folderPath):
        for f in files:
            # Crawl folder for files with .mxd extention
            if f.lower().endswith(".mxd"):

                # Return MXD names and pathways
                mxdName = os.path.splitext(f)[0]
                mxdPath = os.path.join(root, f)
                print '\nChecking MXD titled: ' + mxdName

                # Return MXD properties
                mxd = mapping.MapDocument(mxdPath)
                # Return tables in MXDs
                tables = mapping.ListTableViews(mxd)

                # Return and loop broken layer list in MXD
                try:
                    brokenlayers = mapping.ListBrokenDataSources(mxd)
                    for brokenlayer in brokenlayers:
                        layername = brokenlayer.name
                        print '     Broken Layer: ' + layername
                    if original_feature in brokenlayers:
                        matchedname = original_feature.name
                        print '     Replacing broken layer workspace: ' + matchedname
                        # replace old data source with new data source
                        original_feature.replaceDataSource(
                            renamed_feature_workspace, "FILEGDB_WORKSPACE",
                            renamed_feature_basename)
                    else:
                        print '     No broken links were fixed because 1) there were no broken layers or 2) no broken layers matched original feature'
                    # for lyr in mapping.ListBrokenDataSources(mxd):
                    #     lyrName = lyr.name
                    #     print '  Broken Layer in ' + mxdName + '.mxd: ' + lyrName

                    #     if lyr.supports("DATASOURCE"):
                    #         # See if the original feature is one of the broken data layers
                    #         if original_feature in lyr.dataSource:
                    #             print '     Replacing broken layer workspace: ' + lyrName
                    #             # replace old data source with new data source
                    #             lyr.replaceDataSource(renamed_feature_workspace,
                    #             "FILEGDB_WORKSPACE", renamed_feature_basename)

                # Ignore tables
                except:
                    #AttributeError
                    for table in tables:
                        if table.isBroken == True:
                            pass

                mxd.save()
                del mxd