I seem to be missing something here. In the file attached, there is one polycurve consisting of two segments, the split points are indicated with points. Each of the two subcurves is “kinked”, meaning it will explode into more segments.
Running the Rhino command “Explode” on the original curve produces 25 segments. I would like to be able to do this with RhinoCommon. I guess I am missing something, because I can’t find an exact way.
I ran the following script on the curve to test:
import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino
def TestExplode():
crvID=rs.GetObject("Pick polycurve",4,True)
p_crv=sc.doc.Objects.Find(crvID).Geometry
msg=""
msg+="Original has {} segments\n".format(p_crv.SegmentCount)
if p_crv.IsNested:
msg+="Polycurve is nested\n"
p_crv.RemoveNesting()
else:
msg+="Polycurve is NOT nested\n"
exploded=p_crv.Explode()
msg+="Number of segs after crv.Explode()={}\n".format(len(exploded))
dup_segs=p_crv.DuplicateSegments()
msg+="Number of segs found with crv.DuplicateSegments={}\n".format(len(dup_segs))
ex_crvs=rs.ExplodeCurves(crvID,False)
msg+="Number of segs found after rs.ExplodeCurves()={}\n".format(len(ex_crvs))
rs.SelectObject(crvID)
rs.Command("Explode",False)
lco=rs.LastCreatedObjects()
msg+="Number of segs found after Rhino Explode command={}\n".format(len(lco))
print msg
TestExplode()
The results are as follows:
Original has 2 segments
Polycurve is NOT nested
Number of segs after crv.Explode()=2
Number of segs found with crv.DuplicateSegments=19
Number of segs found after rs.ExplodeCurves()=19
Number of segs found after Rhino Explode command=25
I did not find any method that would completely explode the curve as the Rhino explode command does. Am I missing something? Or do I have to write my own function with FindNextDiscontinuity (painful) and split the curve, something like the following:
import Rhino
import rhinoscriptsyntax as rs
import scriptcontext as sc
def SplitAtAllDiscontinuities(crv):
dom=crv.Domain
params=[]
if crv.IsClosed:
cd=Rhino.Geometry.Continuity.C1_locus_continuous
else:
cd=Rhino.Geometry.Continuity.C1_continuous
param=dom[0]
while True:
chk,next_param=crv.GetNextDiscontinuity(cd,param,dom[1])
if chk:
params.append(next_param)
param=next_param
else:
break
return params
crvID=rs.GetObject("Select polycurve",4,preselect=True)
crv=sc.doc.Objects.Find(crvID).Geometry
parameters=SplitAtAllDiscontinuities(crv)
if len(parameters)>0:
pts=[rs.EvaluateCurve(crvID,p) for p in parameters]
rs.AddPoints(pts)
rs.SplitCurve(crvID,parameters,False)
However, although this does give me 26 split points (not 25), they are not exactly the same as the results from the Rhino command “Explode”… Some curves with kinks remain, and some without kinks have been split…
Edit: and, a corrolary to this question: Is there a RhinoCommon tool to detect a kinked single NURBS curve (as Properties>Details reports) as opposed to a polycurve?
–Mitch
ExplodeQuestion.3dm (26.0 KB)
ExplodeQuestion.zip (10.8 KB)