0

Can someone tell me why I am getting this value error when attempting to access the Montreal.tif layer object?

The first three lines access the object and set the transparency perfectly well, but when I attempt to access it using the following 4 lines I get the illustrated ValueError?

I need the second method since the b variable (Montreal) will change.

ArcGIS Desktop v10.1, ArcInfo license.

enter image description here

The following is a successful workaround (among others), but I'm still not sure why the above was giving me an error?

mxd = arcpy.mapping.MapDocument("Current")
df = arcpy.mapping.ListDataFrames(mxd)[0]

b = "Montreal"
for lyr in arcpy.mapping.ListLayers(mxd, "", df):
    if "{0}.tif".format(b) in lyr.name:
        lyr.transparency = 50
  • 2
    What is actual name of layer in table of content? – FelixIP Jun 18 '17 at 1:54
2

The code in your picture, where the error is seen, has an extra level of quotes i.e.

c = '"{0}.tif"'.format(b)

so try:

c = '{0}.tif'.format(b)

or:

c = "{0}.tif".format(b)

instead.

  • That was actually the first syntax I originally tried and it wasn't working. Trying it again from another machine this afternoon and it works... odd. Anyway small issue. Thanks PolyGeo, great work as always. Should I delete this post? I'm not sure it contributes anything to the site.. – pyRsq Jun 20 '17 at 19:51
  • Rather than trying to delete it, which you won't be able to do because it has an upvoted answer, I think it would gain more value if you supplement the picture in the question with your code and error as text so that it is available to future searches. – PolyGeo Jun 20 '17 at 19:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.