Optimizing split surfaces by curves

Hi everyone,

I am trying to split a bunch of surfaces using curves but the component takes so long… I wonder if there is a way of optimizing the script, maybe using a c# magic component or similar.

The input I have is a data tree of polylines, and a x,y,z interval which is used to divide the polylines. I would like to keep the data structure used in the initial polylines input. Maybe it is just better to operate in polylines instead of surface to reduce the computational time but I don’t know how to split closed polylines by lines.

Also, the final output can be either surfaces or closed polylines

Maybe @inno , @Quan_Li, @michaelvollrath or @TomTom can do magic again! :slight_smile:

Initial surfaces

Result I want to get but optimized

Thanks in advance!

Surface Split.gh (24.2 KB)

It is possible to intersect in parallel using C# script, this speeds up the intersections on my machine by about three-fold, going from 8 seconds to 2.7 or so.
Take care to put input Tree Access and type hint Brep on the input and output ports.

// Grasshopper Script Instance
#region Usings
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;

using Rhino;
using Rhino.Geometry;
using System.Threading.Tasks;
using Grasshopper;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Data;
using Grasshopper.Kernel.Types;

public class Script_Instance : GH_ScriptInstance
    private void RunScript(DataTree<Brep> x, DataTree<Curve> y, ref object a)
        // check that all paths exist on both trees
        foreach(var path in x.Paths)
            if (!y.PathExists(path))
                Console.WriteLine("Path not found");
        foreach(var path in y.Paths)
            if (!x.PathExists(path))
                Console.WriteLine("Path not found");

        DataTree<Brep> result = new DataTree<Brep>();
        // use a parallel task to perform the intersections
        Parallel.For(0, x.Paths.Count, i => 
            GH_Path p = x.Paths[i];
            Brep b = x[p, 0];

            IEnumerable<Curve> splitters = y.Branch(p);

            Brep[] splitted = b.Split(splitters, 0.001);

            result.AddRange(splitted, p);


        a = result;

1 Like

Why do you want to do that? What is the final goal?