Curve.Extend by length doesn't work?

from Rhino.DocObjects import *
from Rhino.Input.Custom import *
from Rhino.Geometry import *

gc = GetObject()
gc.SetCommandPrompt("Select curve to extend")
gc.GeometryFilter = ObjectType.Curve
gc.GeometryAttributeFilter = GeometryAttributeFilter.OpenCurve

curve_obj_ref = gc.Object(0)

curve_obj_ref.Curve().Extend(CurveEnd.Both, 1, CurveExtensionStyle.Smooth) # this does nothing

Hi @Asterisk,

If you review the Curve.Extend documentation, you will see that this method returns a new curve - it does not modify an existing curve. The documention also includes this sample.

– Dale

1 Like

My bad! It does work, just not with negative length numbers, when one wants to shorten the curve by specific length, like rs.ExtendCurveLength() can. How do I shorten it?

if you run your script and place a breakpoint at rs.ExtendCurveLength(), run the script and at the breakpoint choose: Step Into, you can see which methods are used. To shorten you’ll need to use Curve.Trim()

1 Like

You’re right, I gotta start using breakpoints more. There’s so much stuff going on behind the scenes, it looks overwhelming for a noob like me who started dabbling in rhinocommon couple of months ago. Considering no programming background except BASIC.

Dam, this all looks like inception… All python methods are python scripts with rhinocommon… I wish somebody done a Primer booklet on this, like there is one on Rhinoscript and Python…

I don’t really get what you mean here, the rhinoscript syntax is basically rhinoscript translated to python. Or do you mean a Primer about what happens inside all rhinoscriptsyntax functions? That’s more a story about writing a primer about Rhino Common API

I meant Primer on rhinocommon, sorry, got several things going on right now.

Hi @Asterisk,

To shorten a curve, have a look at the following example:

import Rhino
import scriptcontext as sc

def test_shorten_curve():
    filter = Rhino.DocObjects.ObjectType.Curve
    rc, objref = Rhino.Input.RhinoGet.GetOneObject("Select curve to shorten", False, filter)
    if not objref or rc != Rhino.Commands.Result.Success: 
    crv = objref.Curve()
    if not crv:
    crv_length = crv.GetLength()
    if crv_length < Rhino.RhinoMath.ZeroTolerance:
    str = "Curve length is {0:.3f}. Length to remove".format(crv_length)
    length = 1.0
    rc, length = Rhino.Input.RhinoGet.GetNumber(str, False, length, 0, crv_length)
    if rc != Rhino.Commands.Result.Success or length <= 0 or length >= crv_length: 
    crv_trim = crv.Trim(Rhino.Geometry.CurveEnd.End, length)
    if crv_trim:
        sc.doc.Objects.Replace(objref, crv_trim)

if __name__ == "__main__":

– Dale

Yes, thanks Dale, Gijs pointed me in the right direction towards Curve.Trim

The reason it’s hard for me to navigate thru rhinocommon is that nomenclature of it doesn’t always match python methods and/or native rhino commands nomenclature.

Like in this example: I’d use Extend command with negative distance or rs.ExtendCurveLength() with negative distance or Curve.Trim with positive distance. When I already have a concept of Trim being what Trim command does my eyes don’t stop on Curve.Trim to see what it does.
I know I should’ve RTFM closer, but sometimes you just ignore things like this involuntarily.

It would be very helpful if search worked a bit better: