Python split / shatter curves

Continuing the discussion from Python Split curve with curve?:

hi there,

I am trying exactly that on python (learning python at the moment) but i found several problems

here is my code at the moment:

#shift curves list
new_list =
for i in Curves:
new_list.insert(len(new_list)-1, i)

#get points at intersection
int_events =
for crv in Curves:
for n_crv in new_list:
int = rs.CurveCurveIntersection(crv, n_crv)
int_events.append(int[0])

#extract elements from list of lists
def Extract(a, lst):
return [item[a] for item in lst]

int_pts_a = Extract(1, int_events)
int_param_a = Extract(5, int_events)

#output
Intersection_Points = int_pts_a
Crv_param_at_int_Points = int_param_a
a = int_events

the problems I am facing so far are:

there is one intersection missing…???
if I use the shatter component with the output produced, I get a list of non-sense points…???

any help here pleasepython_split_curves.gh (6.5 KB)

rhinoscriptsyntax:

import rhinoscriptsyntax as rs
import ghpythonlib.treehelpers as th
params = []
for i in range(len(crvs)):
    params.append([])
for i in range(len(crvs)):
    for j in range(i+1, len(crvs)):
        events = rs.CurveCurveIntersection(crvs[i], crvs[j])
        for event in events:
            params[i].append(event[5])
            params[j].append(event[7])
a = th.list_to_tree(params)

Rhinocommon:

from ghpythonlib.treehelpers import list_to_tree
from Rhino.Geometry.Intersect import Intersection
from scriptcontext import doc
tol = doc.ModelAbsoluteTolerance
params = []
for i in range(len(crvs)):
    params.append([])
for i in range(len(crvs)):
    for j in range(i+1, len(crvs)):
        events = Intersection.CurveCurve(crvs[i], crvs[j], tol, tol)
        for event in events:
            params[i].append(event.ParameterA)
            params[j].append(event.ParameterB)
sub_curves = []
for i in range(len(crvs)):
        sub_curves.append(crvs[i].Split(params[i]))
a = list_to_tree(sub_curves)

Shatter.gh (8.0 KB)

1 Like

many thank!!!

rhinoscriptsyntax vs rhino common.gh (21.4 KB)

many thanks for the answer @Mahdiyar it works perfectly !

one question, if I may;

testing different sets of curves, I realise that the rhinoscriptsyntax one not always work (see attached gh file), meanwhile the rhino common yes

Does that mean that is always preferable to work on rhino common?
or this is just one specific case …

just trying to understand whats going on

hi @Mahdiyar

rhinoscriptsyntax:(shatter) give Error about some curves


Shatter (2).gh (11.0 KB)

Ehsan.gh (8.3 KB)

1 Like

@Mahdiyar
but it possible to how script split the list of Curves(a) by the list Of Curves(b)?

)
for example the results is wrongs (Because Paramtherefore param Are wrong and not proprietary)Therefore by pythons(c#)how did it?
spiltCurve.gh (9.4 KB)

hi against
I found myself solving split Curve by Curve And apparently works properly!Do you think this solution is correct? With c # how?

from ghpythonlib.treehelpers import list_to_tree
from Rhino.Geometry.Intersect import Intersection
from scriptcontext import doc
tol = doc.ModelAbsoluteTolerance
params = []
for i in range(len(crvs)):
    params.append([])
for i in range(len(crvs)):
    for j in range(len(cutter)):
        events = Intersection.CurveCurve(crvs[i], cutter[j], tol, tol)
        for event in events:
            params[i].append(event.ParameterA)

sub_curves = []
for i in range(len(crvs)):
        sub_curves.append(crvs[i].Split(params[i]))
a = list_to_tree(sub_curves)

split Curve by Curve.gh (11.2 KB)

#python
from Rhino.Geometry.Intersect import Intersection
from scriptcontext import doc
tol = doc.ModelAbsoluteTolerance
parameters = []
for cutter in cutters:
    events = Intersection.CurveCurve(crv, cutter, tol, tol)
    for e in events:
        parameters.append(e.ParameterA)
a = crv.Split(parameters)
//C#
private void RunScript(Curve crv, List<Curve> cutters, ref object A)
{
  var tol = RhinoDocument.ModelAbsoluteTolerance;
  var parameters = new List<double>();
  foreach(var cutter in cutters)
  {
    var events = Intersection.CurveCurve(crv, cutter, tol, tol);
    foreach(var e in events)
      parameters.Add(e.ParameterA);
  }
  A = crv.Split(parameters);
}

Ehsan.gh (7.5 KB)

1 Like