rs.ExplodeCurves has different behavior than Explode Rhino command?

I am writing a python script that makes use of the ExplodeCurves command in rhinoscriptsyntax. However I noticed that the command does not give the same result as when I go through the process manually.
If you use the attached file and dummy script, you will see that calling the Explode command in Rhino will return 6 curves. While using the python script only returns 2 curves.
Is this intentional? If so what am I missing?
ExplodeCurve.3dm (22.8 KB)
ExplodeCurve.py (119 Bytes)

Hi @Hunter2,

The difference is that the underlying function behind rs.ExplodeCurves is Curve.DuplicateSegments, and the Explode command uses RhinoObject.GetSubObjects.

Here is a more equivalent script:

import Rhino
import scriptcontext as sc

def test_explode_curve():
    # Pick a single curve object
    filter = Rhino.DocObjects.ObjectType.Curve
    rc, objref = Rhino.Input.RhinoGet.GetOneObject("Select curve to explode", False, filter)
    if not objref or rc != Rhino.Commands.Result.Success: 
        return
    
    # Get the selected Rhino object
    rh_obj = objref.Object()
    if not rh_obj:
        return
    
    # Get the sub0objects
    sub_objs = rh_obj.GetSubObjects()
    if not sub_objs:
        return
    
    # Add the sub-object geometry
    for sub_obj in sub_objs:
        sc.doc.Objects.Add(sub_obj.Geometry)
    sc.doc.Objects.Delete(rh_obj)
    sc.doc.Views.Redraw();

if __name__ == "__main__":
    test_explode_curve()

– Dale

1 Like

This is perfect! Thanks so much!