Friday 15 June 2018

python - Create Multiple Feature Layer and Add to MXD


I am really stuck with this one and cannot seems to get the code to execute. Every time I do so, I get the error: Input Features: Dataset [u'Test1'.....] does not exist or is not supported. My guess is that it is the latter as I have tested the code with a arcpy.Exists command and the code executes but does not populate the data frame appropriately.


Code:


  import arcpy, os

arcpy.env.workspace = r'c:\pathway to geodatabase'
fcs = arcpy.ListFeatureClasses()


mxd = arcpy.mapping.MapDocument(r'C:\pathway to mxd')
DF = arcpy.mapping.ListDataFrames(mxd,'*')[0]

for fc in fcs:
inputlayer = fcs
outlayer = os.path.join(*(fcs) + '.lyr')
arcpy.MakeFeatureLayer_management(inputlayer,outlayer)

layer = arcpy.mapping.Layer(fc)

arcpy.mapping.AddLayer(DF,layer,"AUTO_ARRANGE")

When I print fcs, this produces a string with the 'u' with unicode preceding the actual value. I did try to convert it to ASCII and got the follow error: AttributeError: 'MapDocument' object has no attribute 'encode'


Where am I going wrong?




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...