AnsweredAssumed Answered

fnmatch or re?

Question asked by howelltodd on Feb 20, 2015
Latest reply on Feb 20, 2015 by xander_bakker

I have a dynamic coded script that runs as a tool. It utilizes  arcpy.mapping to add some files to an existing template and then update the layer's symbology and name. I want to be able to differentiate between a couple different layers that have  the same geometry but different names. For example, there could be a Polyline file for a Assignment Break, as well as a Polyline file for a fire line file. This is the code that I have input so far (it isn't working).

code:

 

shapesList = arcpy.mapping.ListLayers(mxd_Update, "*_lyr", mainDataFrame_Update)

for shapes in shapesList:

    type = arcpy.Describe(shapes).shapetype.upper()

    name = arcpy.Describe(shapes).name.upper()

    if type== "POLYGON" and name== fnmatch.fnmatch(shapes, "*OLYGON*"):

        arcpy.mapping.UpdateLayer(mainDataFrame_Update, shapes, fire_perimeter)

        arcpy.SelectLayerByAttribute_management(shapes, "NEW_SELECTION")

        mainDataFrame_Update.zoomToSelectedFeatures()

        arcpy.SelectLayerByAttribute_management(shapes, "CLEAR_SELECTION")

        shapes.name = "Fire Perimeter"

    if type== "POLYGON" and name== fnmatch.fnmatch(shapes, "*NTENSE*"):

        arcpy.mapping.UpdateLayer(mainDataFrame_Update, shapes, intense_heat)

        shapes.name = "Intense Heat"

    if type== "POLYGON" and name== fnmatch.fnmatch(shapes, "*CATTERED*"):

        arcpy.mapping.UpdateLayer(mainDataFrame_Update, shapes, scatter_heat)

        shapes.name = "Scattered Heat"

    if type== "POLYLINE" and name== fnmatch.fnmatch(shapes, "*SSIGNMENT*"):

        arcpy.mapping.UpdateLayer(mainDataFrame_Update, shapes, assign_break)

        shapes.name = "Assignment Break"

    if type== "POLYLINE" and name== fnmatch.fnmatch(shapes, "*IRE*"):

        arcpy.mapping.UpdateLayer(mainDataFrame_Update, shapes, fire_line)

        shapes.name = "Fire Lines"

    if type== "POINT" and name== fnmatch.fnmatch(shapes, "*OINTS*"):

        arcpy.mapping.UpdateLayer(mainDataFrame_Update, shapes, fire_point)

        shapes.name = "Fire Points"

    if type== "POINT" and name== fnmatch.fnmatch(shapes, "*SOLATED*"):

        arcpy.mapping.UpdateLayer(mainDataFrame_Update, shapes, iso_heat)

        shapes.name = "Isolated Heat"

    else:

        print "no go fo sho tho"

 

 

 

 

A couple of basic questions... you can't use two (*) to grab a group of text from the middle of a string, correct? I can't really get my head wrapped around how I would use the m. functions in re to get this done... and I also can't use fnmatch because it isn't a filename, correct? Either way, I'm in over my head on this little bit

Outcomes