Phyton script - sweep2rail selecting objects by name

Dear all,
I’m trying to realize a sweep 2 rail using 2 rails and 2 curves.
I would like to select rails and curve by name but something doesn’t work.

I attach the 3dm file with the named curves I want to use.
Here below the script that I wrote.

import rhinoscriptsyntax as rs
imp
rairails ls = rs.ObjectsByName(“rail01”, “rail02”, True)
if if rails and len(rails)==2:
shapes = rs.ObjectsByName(“curva01”, “curva02”, True)
if shapes: rs.AddSweep2(rails, shapes)

Can you help me?
Thanks in advance,
Laura

sweep2rail_test01.3dm (21.5 KB)

Hi @laura.micoli,

This seems to work:

import rhinoscriptsyntax as rs

def __one_object_by_name(name):
    objs = rs.ObjectsByName(name)
    if objs and len(objs) == 1:
        return objs[0]
    return None

def test_laura():
    
    rail01 = __one_object_by_name('rail01')
    if rail01 is None:
        return
        
    rail02 = __one_object_by_name('rail02')
    if rail02 is None:
        return
        
    curva01 = __one_object_by_name('curva01')
    if curva01 is None:
        return
        
    curva02 = __one_object_by_name('curva02')
    if curva02 is None:
        return
    
    rs.AddSweep2([rail01, rail02], [curva01, curva02]) 
    
if __name__ == "__main__":
    test_laura()

– Dale

Dear Dale,

thanks a lot for your help.
I’m going to try your code.

Best regards,
Laura