Overwriting Layer

Hi everybody,
I’m not an expert in programming with python and I would like to know the procedure to overwriting a layer with some lines, after I run again the script. Otherwise, every time I will modify the reference surfaces I will have always new lines.

Thank you
Ale

This is my script for now:

import rhinoscriptsyntax as rs
import Rhino.Geometry as rg

surface_base = rs.GetObject('Select the base surface')
surface_top = rs.GetObject('Select the top surface')
points1 = rs.SurfaceEditPoints(surface_base)
points2 = rs.SurfaceEditPoints(surface_top)

for point in points1:
    base_points = rs.AddPoints(points1)
    for point in points2:
        top_points = rs.AddPoints(points2)
    
for point1 in points1:
    for point2 in points2:
        lines = rs.AddLine(point1,point2)
        rs.ObjectLayer(lines,'dummy')

@alexdell, see oif below does what you want. It just clears the objects on the layer “dummy” before adding the points and lines to it. So whenever you change the surfaces and run the script again, the lines and points are updated.

import rhinoscriptsyntax as rs

def DoSomething():
    
    surface_base = rs.GetObject('Select the base surface')
    if not surface_base: return
    surface_top = rs.GetObject('Select the top surface')
    if not surface_top: return
    points1 = rs.SurfaceEditPoints(surface_base)
    points2 = rs.SurfaceEditPoints(surface_top)
    
    layer_name = "dummy"
    
    # clear the dummy layer, or create it if it is not there
    if rs.IsLayer(layer_name):
        objs = rs.ObjectsByLayer(layer_name, select=False)
        if objs: rs.DeleteObjects(objs)
    else:
        rs.AddLayer(layer_name)
    
    base_points = rs.AddPoints(points1)
    top_points = rs.AddPoints(points2)
    rs.ObjectLayer(base_points, layer_name)
    rs.ObjectLayer(top_points, layer_name)
    
    for point1 in points1:
        for point2 in points2:
            line = rs.AddLine(point1,point2)
            rs.ObjectLayer(line, layer_name)
    
DoSomething()

note that i changed the code to add the points only once (without duplicates).

c.

Thanks Clement :slight_smile: