I have a file that has almost 1000 layers, 165 top level layers plus sublayers. Many of the sublayers have the same name, and I want to turn off all of the sublayers that have a specific name or a certain snippet of text in the name.
This (python/rhinoscriptsyntax) totally doesn’t work:
import rhinoscriptsyntax as rs
import scriptcontext as sc
def TurnOffLayerViaNameSnippetList():
snippet="textbit"
names=rs.LayerNames()
found_count=0
for i in range(len(names)):
if snippet in names[i].lower():
found_count+=1
rs.LayerVisible(names[i], False)
print found_count
TurnOffLayerViaNameSnippetList()
I get 165 as a found_count but the layers containing the text snippet in their name remain on.
I have also tried this via RhinoCommon and scriptcontext access to the layer table, same problem
The equivalent in vb Rhinoscript works perfectly.
Option Explicit
Call TurnOffLayerViaNameSnippet()
Sub TurnOffLayerViaNameSnippet()
Dim layers, i, snippet, found_count
snippet = "textbit"
found_count = 0
layers = Rhino.LayerNames
For i=0 To Ubound(layers)
If instr(1, lcase(layers(i)), snippet) > 0 Then
found_count = found_count + 1
Call Rhino.LayerVisible(layers(i), False)
End If
Next
Call Rhino.Print(found_count)
End Sub
I get 165 as found_count and all the desired layers are turned off.
This is one aspect of the problem, another was importing the files that constituted this one big file. There are instances where Python/RhinoCommon is simply unable to write correctly to the layer table and causes the whole import script to error out. I will try to create a compact example of that as the combined files are over 500 Mb, but I have 3 of the 168 files that just refuse to have the filename written as a top level layer. I can see nothing in the name (no special characters, just ascii letters and numbers) that should prevent them being used to create a layer…
Anyway, not a happy camper at the moment, faced with rewriting my import script in vb rhinoscript because I know it should work…
–Mitch