Trying to find object layer name to use with csv. also changing object layer

rhino
python

#1

Hello I am trying to get the layer name for a file by searching for it. in def Ballast_Point after if rc I define Brand as ‘phillips’ I need to define brand by searching for the word ballast in my layers and then stripping the word ballast. for example if my layer was named phillips ballast id be left with just phillips. I am also trying to move the spheres I created to a different layer specifically named “Audio Evaluation”. anything helps! thank you!

import Rhino
import scriptcontext as sc
import rhinoscriptsyntax as rs
import math as ma
doc = Rhino.RhinoDoc.ActiveDoc

filename = 'import.csv'
folder = 'C:\\Users\\gornall72\\Desktop\\'



def Ballast_Points():
    
    search_string = "Ballast"
    
    for layer in sc.doc.Layers:
        
        if search_string.lower() in layer.Name.lower():
             
            for rh_obj in sc.doc.Objects.FindByLayer(layer):
                
                if rs.IsSurface(rh_obj.Id):
                    
                    rc = rs.SurfaceAreaCentroid(rh_obj.Id)
                    if rc:
                            Brand='phillips'
                            rawdata = []
                            with open(folder+filename,'r') as infile:
                                for line in infile:
                                    rawdata.append(line)
        
                            dataset = []
                            for data in rawdata:
                                dataset.append(data.strip('\n').split(','))



                            header_row = dataset.pop(0)
                            data_array = []
                            for i in range(len(dataset)):
                                data_dict = {}
                                for j in range(len(dataset[i])):
                                    data_dict[header_row[j]] = dataset[i][j]
                                data_array.append(data_dict)
            




                            for row in data_array:
                                if(Brand in row['Brand Name']):
                                    I = (float(row['dB']))

                            D= 3/ma.sqrt(30/I)

                            D2= D+3
                            rs.AddSphere(rc[0],D2)

    sc.doc.Views.Redraw()

            
def delete_points(point):
    objs = rs.AllObjects()
    for obj in objs:
        if rs.IsPoint(obj):
            rs.DeleteObject(obj)

response=rs.MessageBox("Evaluate Classroom?",4)
if response!=7:
    Ballast_Points()

    delete_points()
else:
    rs.MessageBox("Evaluation Aborted")

(Dale Fugier) #2

Hi @Christopher_Gornall,

If you find layer with the name “phillips” when not just use the string “phillips”? Why do you need to strip the layer name of “ballast” when all you really want is the name you are searching for?

– Dale