AnsweredAssumed Answered

Why is this unicode?

Question asked by ginomellino on Sep 23, 2015
Latest reply on Sep 23, 2015 by rastrauch



Apologies, I understand this is a basic issue but it confuses me. I have a script tool which I am writing in python to work with a particular MXD. In this script tool I have the following lines of code to reference two layers in the MXD's TOC.


subjectLayer = arcpy.mapping.ListLayers(mxd,subjectlayerName)[0]

subjectLayer.definitionQuery = ""

cadastralLayer = arcpy.mapping.ListLayers(mxd,"Cadastre")[0]

arcpy.AddMessage( cadastralLayer) #To test if layer is set correctly

cadastralLayer.definitionQuery = ""


The subjectLayer object gets set correctly. This is chosen as a parameter in the tools UI. The definition query also gets set correctly.The cadastralLayer object gets populated also (AddMessage shows grouplayername\layername) but I get a "Script failure: 'unicode' object has no attribute 'definitionQuery'" error when it tries to set a definition query on it. This object is set by referencing the layer name in the TOC.


My question is why is one a unicode and the other a layer object as they were both referenced using ListLayers? How do I correctly reference layers in the TOC?


Thanks in advance.