"str is not callable" with CurrentLayer method


#1

In a python script, I am trying to change the current layer by using rs.CurrentLayer(‘mylayer’) .
During the first run of the script this works fine, however, on subsequent runs I get a message “str is not callable”. This happens also when I revert the Rhino file to the point where I ran the script the first time, and even if I use the script on a new drawing! (after closing the old drawing). The only way I can get it to work again is to quit Rhino and restart it.
Anybody any idea?

Edit: I found a solution. The root problem was in not using the right method to get back to the original current layer.


(Steve Baer) #2

Could you post a sample that demonstrates this problem? It will be a lot easier to help track down what is going on.


#3

This is the code I used:

Make ‘Duplications’ the current layer

rs.CurrentLayer(‘Duplications’)

Return to original current layer

rs.CurrentLayer=rs.CurrentLayer(‘Duplications’)

I know now that the second expression is rubbish, so I used the following instead.

old=rs.CurrentLayer()
rs.CurrentLayer(‘Duplications’)
rs.CurrentLayer(old)

But somehow the rubbish expression caused the “str is not callable” message on the second pass, with a reference to the first expression, so that was were I searched for the fault.


(Steve Baer) #4

This is the problem. You are reassigning the function rs.CurrentLayer to be a string and then trying to use rs.CurrentLayer as a function when python now knows that it is a string.


#5

OK Steve, I understand it now. Thank you.


#6

Hi Steve, I was thinking of bumping the topic because I just got the same error message, using the example of Python help:
import rhinoscriptsyntax as rs
rs.AddLayer(“MyLayer”)
rs.CurrentLayer(“MyLayer”)

I also tried with an even more simple script like this one:
import rhinoscriptsyntax as rs
rs.CurrentLayer(“MyLayer”)

I still get the error message “str is not callable”. Can you help me? Thanks


#7

Ok I don’t know what was wrong but I just close Rhino and open it again and now it is working