I am working on a python script that allows me to automatically export and update big architectural rhino files to 3dsmax in the most convenient and fast way.
I have problems selecting objects from a list of layers.
let’s say I have tens of layers and sublayers in my 3dm file:
-layer00
-layer01
-layer n
My steps are:
Extract in a separate text file the layers names list. (DONE)
Now I would like to select just the objects from a portion of the layers that I saved in the previously created text file.
If I understand what you are asking, you want to read in a list of layer names from an ini (text) file and select the objects on those layers (then you can run your export function)
Something like this should work - assume the name of the file is “Layer List” and it is on your desktop:
import rhinoscriptsyntax as rs
file=open(r"C:\Users\yourusername\Desktop\Layer List.txt")
layers=rs.LayerNames()
for line in file:
#get rid of any whitespace or end of line characters
layername=line.strip()
if layername in layers:
rs.ObjectsByLayer(layername,True)
file.close()
Note that as Python is case sensitive, you may also need to make provisions for non-case sensitive layer name matching - if you think that might be necessary.
Once all the objects are selected, you can export them. Or, to export layer by layer, run the export function inside the selection loop.
Oh, I forgot to describe the format for the .ini file, in my test case it has one layer name per line (not comma separated). But it’s pretty easy to adapt the scriptlet to parse other formatting.