Layer is not callable error


#1

Hello,

I am creating layers and then want to randomly select one of them. All works well except the last line of code where I get error “Layer is not callable”. What gives?

#!/usr/bin/python -tt

import Rhino
import scriptcontext
import System.Drawing.Color
import System.Enum
import System.Array
import time
import random
from random import *

from scriptcontext import doc

numDepth = 5
minDepth = .25
maxDepth = .5
deltaDepth = (maxDepth - minDepth)/(numDepth-1)

depth=[0 for i in range(numDepth)]
layerName=[0 for i in range(numDepth)]
layerIndex=[0 for i in range(numDepth)]

for i in range(0, numDepth):
depth[i] = minDepth + i * deltaDepth
layerName[i] = “depth_” + str(depth[i]) + "_inch"
layerIndex[i] = doc.Layers.Add(layerName[i], System.Drawing.Color.Black)
print depth[i], layerName[i], layerIndex[i]

seed(time.time())
randomDepth = randint(0, numDepth-1)
print randomDepth, layerName[randomDepth]
doc.Layers.CurrentLayer(layerName[randomDepth])


(Pascal Golay) #2

Hi Elaner = CurrentLayer() is read only, but you can use

doc.Layers.SetCurrentLayerIndex(layerIndex[randomDepth],False)

-Pascal


#3

Thank you, Pascal!