How to initialize an array of surface objects in RhinoPython?

Hi everyone,

I would like to dynamically add surfaces to an object array through Rhinopython.

I tried doing this but it did not work out:

import rhinoscriptsyntax as rs
center=(0,0,0)
radius=1
j=0
while j<4:

   surf = rs.AddSphere(center,radius+j)
   if j==0:
            objs={surf}  
   else:
            objs={objs,surf} 

I am getting an error, “set objects are unhashable”.
Does anyone have any suggestions of any other way to go about it?

Hello - I’m guessing you’ll want to make a list and append it with each new ‘surf’, but keep in mind that each ‘surf’ in the script will be a guid and not a surface object. Also, increment ‘j’.

import rhinoscriptsyntax as rs
center=(0,0,0)
radius=1
j=0
ids = []
while j<4:

   surfId = rs.AddSphere(center,radius+j)
   if surfId: ids.append(surfId)
   j += 1

or, more compactly:

import rhinoscriptsyntax as rs
center=(0,0,0)
radius=1

ids = [rs.AddSphere(center,radius+j) for j in range(4)]

-Pascal

1 Like

Hi Pascal,

Thank you very much. I will use this then.

I was trying to figure out to define an empty array and add on to it as you have shown through the Append function.