0904
December 24, 2022, 1:14am
1
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?
603419608
(NARUTO)
December 24, 2022, 6:06am
2
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
0904
December 25, 2022, 4:00pm
3
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
emilio
December 25, 2022, 4:23pm
4
0904
December 25, 2022, 8:40pm
5
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
emilio
December 25, 2022, 9:29pm
6
This one should be able to split a curve at more than one parameter value.
Curve.Split Method (IEnumerable(Double)) (rhino3d.com)
0904
December 25, 2022, 9:46pm
7
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
emilio
December 25, 2022, 10:02pm
8
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 )
0904
December 25, 2022, 10:28pm
9
it works it works
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#
emilio
December 25, 2022, 10:34pm
10
IMO the script is calling this method
Curve.Split Method (IEnumerable(Double)) (rhino3d.com)
You think it’s a different method ?
Which one ?
0904
December 25, 2022, 11:00pm
11
I have no idea, I’m 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?
emilio:
IMO
ps IMO?
emilio
December 26, 2022, 12:17am
12
The difference is about looking carefully at what the docs say and not making wild guesses …
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()
0904:
ps IMO?
I n M y O pinion
1 Like
emilio
December 26, 2022, 8:01pm
13
My bad, sorry … I did not look at this code carefully enough …
0904:
using the method I posted to select the curve doesn’t work
crv=Rhino.Input.RhinoGet.GetOneObject("", False, Rhino.DocObjects.ObjectType.Curve)[1]
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 …