#1 Fri 12 January 2018 10:28
- gravier3000
 - Juste Inscrit !
 - Date d'inscription: 19 Dec 2016
 - Messages: 3
 
arcpy: AssertionError dans RemoveLayer
Bonjour,
Je tente de réaliser un code qui effectue la boucle suivante:
- ajouter un shapefile au projet mxc en cours
- lui appliquer une symbologie sur base d'un .lyr
- exporter en PNG
- retirer le layer du projet mxd
Code:
import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
arcpy.env.workspace = r"L:\RHOPALOLUX\ANALYSES\Sp_distribution_table\ShapefileBySpecies"
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
fcs = arcpy.ListFeatureClasses()
for fc in fcs:
    arcpy.MakeFeatureLayer_management(fc, fc)
    arcpy.ApplySymbologyFromLayer_management(fc+"layer", r"L:\RHOPALOLUX\CARTO\Distribution\Sp_distribution_p2_mxd\Layer_file\Species_period2.lyr")
    arcpy.mapping.ExportToPNG(mxd, r"L:\RHOPALOLUX\CARTO\Distribution\Sp_distribution_p2_png\Distribution_P2_" + fc + ".png")
    arcpy.mapping.RemoveLayer(df, fc)Cela me renvoie l'erreur suivante:
Runtime error 
Traceback (most recent call last):
  File "<string>", line 4, in <module>
  File "c:\program files (x86)\arcgis\desktop10.5\arcpy\arcpy\utils.py", line 182, in fn_
    return fn(*args, **kw)
  File "c:\program files (x86)\arcgis\desktop10.5\arcpy\arcpy\mapping.py", line 1845, in RemoveLayer
    assert isinstance(remove_layer, Layer)
AssertionError
Je n'arrive pas à comprendre l'origine. Merci d'avance pour votre aide
Hors ligne


