3

I would like to update the data source of a specific layer in multiple map documents using ArcPy.

However, I'm getting a <type 'exceptions.SyntaxError'>: invalid syntax error on if lyr.datasetName == inputlayer in the code below.

import arcpy, string, os
import arcpy.mapping as MAP

try:
    MXDList = string.split(arcpy.GetParameterAsText(0), ";") #ArcMap document(s)
    inputlayer = arcpy.GetParameterAsText(1) # featureclass
    newwork = arcpy.GetParameterAsText(2) # Workspace

    for MXDPath in MXDList:
        MXD = MAP.MapDocument(MXDPath)
        for dataframe in arcpy.mapping.ListDataFrames(MXD):
            lyrs = arcpy.mapping.ListLayers(dataframe)  
            for lyr in lyrs:
                if lyr.datasetName == inputlayer
                    lyr.replaceDataSource(newwork, "FILEGDB_WORKSPACE", "Center")
    MXD.save()

What causes the SyntaxError here?

I was attempting to reference this forum thread.

0

1 Answer 1

5

You're missing a colon. if lyr.datasetName == inputlayer:

Also, the last line MXD.save() should be indented an additional 4 spaces.

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.