Remove layers using python- path orientation

المشرف العام

Administrator
طاقم الإدارة
Continuously to Code error - remove layer using python, i try to remove layers from mxd's (in ArcMap 10.3, python 2.7.8), that don't appear in the data frame with this code:

import arcpy,osfrom arcpy import envenv.workspace = r"D:\desktop\Project"for mxdname in arcpy.ListFiles('*.mxd'): print mxdname mxd = arcpy.mapping.MapDocument(os.path.join(env.workspace, mxdname)) df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] for lyr in arcpy.mapping.ListLayers(mxd, "" ,df): if lyr.getExtent() != None: if df.extent.disjoint(lyr.getExtent()): arcpy.mapping.RemoveLayer(df, lyr) print 'removed '+str(lyr) # this is optional(earase the # sign): ,'from '+str(mxdname) mxd.save()del mxdbut i get an error:

>>> project1.mxdremoved pointTraceback (most recent call last): File "C:\Program Files\CCleaner\yaron\shonot\software\---gis--- \tools\YARON_SCRIPTS\remove lyr that are not in df 2.py", line 19, in print 'removed '+str(lyr) # this is optional(earase the # sign): ,'from '+str(mxdname)UnicodeEncodeError: 'ascii' codec can't encode characters in position 1-5: ordinal not in range(128)>>> I think this error derives from the fact that one layer has different path orientation (right to left- different language from English). If i use layers with regular path orientation(English only) the code works just fine.



أكثر...
 
أعلى