Split Curve

Hi all,

I can split a curve
in Py with rhinoscriptsyntax
in VBS and also in Gh with C#
but i can’t do it using rhinocommon:

import Rhino
import scriptcontext
import Rhino.Geometry

crv=Rhino.Input.RhinoGet.GetOneObject("", False, Rhino.DocObjects.ObjectType.Curve)[1]

crv=crv.Curve().Split(0.5)

scriptcontext.doc.Views.Redraw()

the syntax does not return an error,
but neither does it give the split curve. . .

i searched the method in API
I searched posts in the forum
but I haven’t found any solution

where is my mistake?

Hi
You have to add Rhino Geometry to the rhino view.

import Rhino
import scriptcontext
import Rhino.Geometry

crv=Rhino.Input.RhinoGet.GetOneObject("", False, Rhino.DocObjects.ObjectType.Curve)[1]

crvs=crv.Curve().Split(0.5)
print crvs
#Add Rhino Geometry to the rhino view.
[scriptcontext.doc.Objects.AddCurve(cv) for cv in crvs]

scriptcontext.doc.Objects.Delete(crv.ObjectId,True)
scriptcontext.doc.Views.Redraw()
1 Like

thanks Naruto for reply, your solution for split works;

but how can i use it with crv.Curve().DivideByLength(100, False)

basically I need to simulate Rhino’s “Divide” command

Ciao Salvio

Just look at what rs.DivideCurveLength() does, here:

rhinoscriptsyntax/curve.py at rhino-6.x · mcneel/rhinoscriptsyntax · GitHub

ciao Emilio,

non so se il ragionamento era corretto ma per avere una curva divisa in più punti o divisa in n segmenti avevo pensato di abbinare metodo split con DivideByLength usando Rhinocommon, ora nel link invece vedo rhinoscript. facendo alcune ricerche sembra che in “split” si possa indicare un solo parametro come punto di divisione, stavo immaginando di procedere con un ciclo abbinando questo tipo di procedura:

Emilio, I don’t know if the reasoning was correct but to have a curve divided into several points or divided into n segments I had thought of combining the split method with DivideByLength using Rhinocommon, now in the link I see rhinoscript instead. doing some research it seems that in “split” only one parameter can be indicated as a division point, I was imagining proceeding with a cycle combining this type of procedure:

parA = [0, 1]
parB = [0.25, 0.5, 0.75]
splitCurve [[0, 0.25], [0.25, 0.5], [0.5, 0.75], [0.75, 1]]

mentre AddCurve abbina quel parametro di divisione con i punti che lo precedono e che lo seguono

while AddCurve matches that division parameter with the points that precede and follow it

This one should be able to split a curve at more than one parameter value.

Curve.Split Method (IEnumerable(Double)) (rhino3d.com)

infatti avevo visto in un’altra discussione che è stato consigliato questo metodo, ma mi dice:
Message: name ‘IEnumerable’ is not defined

in fact I had seen in another discussion that this method was recommended, but it tells me:
Message: name ‘IEnumerable’ is not defined

This script works fine here on Rhino 6, from EditPythonScript
( It requires a curve that you can select )

import Rhino
import rhinoscriptsyntax as rs
import scriptcontext

gid = rs.GetObject( "?" )
cu = Rhino.DocObjects.ObjRef( gid ).Curve()
u0, u1 = rs.CurveDomain( gid )
ts = [ u0 + ( u1 - u0 ) / 10 * n for n in range( 1, 10 ) ]
cus = list( cu.Split( ts ) )
for cu in cus:
   scriptcontext.doc.Objects.AddCurve( cu )

it works it works :+1:

fa parte sempre di Rhinocommon ma si tratta di un diverso metodo split
lo chiedo essendo che poi successivamente dovrei convertirlo in C#

it’s still part of Rhinocommon but it’s a different split method
I ask since then later I should convert it to C#

IMO the script is calling this method

Curve.Split Method (IEnumerable(Double)) (rhino3d.com)

You think it’s a different method ?
Which one ? :slight_smile:

I have no idea, I’m confused :confused:

I initially thought it was another method being that I hadn’t seen the .Curve() in cu.Split( ts )

instead you had entered it previously: cu = Rhino.DocObjects.ObjRef( gid ).Curve()

using the method I posted to select the curve doesn’t work

crv=Rhino.Input.RhinoGet.GetOneObject("", False, Rhino.DocObjects.ObjectType.Curve)[1]

while the one you posted Rhino.DocObjects.ObjRef( gid ).Curve() works just like I wanted

so the difference lies in the way used to select the curve?

ps IMO?

The difference is about looking carefully at what the docs say and not making wild guesses … :wink:

As we can see, this method
RhinoGet.GetOneObject Method (String, Boolean, GetObjectGeometryFilter, ObjRef) (rhino3d.com)

returns a Result value, not a curve or some other kind of object.
Moreover it has an out parameter of type ObjRef

So here Python returns a tuple with two values: the Result and the ObjRef.
You have to use it this way:

import Rhino
import scriptcontext

res, obref = Rhino.Input.RhinoGet.GetOneObject( "", False, Rhino.DocObjects.ObjectType.Curve )
cu = obref.Curve()
intv = cu.Domain
u0, u1 = intv.Min, intv.Max
ts = [ u0 + ( u1 - u0 ) / 10 * n for n in range( 1, 10 ) ]
cus = list( cu.Split( ts ) )
for cu in cus:
   scriptcontext.doc.Objects.AddCurve( cu )
scriptcontext.doc.Views.Redraw()

In My Opinion :wink:

1 Like

My bad, sorry … I did not look at this code carefully enough …

the code is OK. It gives you an ObjRef object that references the selected curve.
If the script does not work, the problem must be elsewhere …