Why doesn’t the line extend with the following code:
import rhinoscriptsyntax as rs
import Rhino
import scriptcontext as sc
import Rhino.Geometry as rg
def Test():
p1 = rs.GetPoint('Select the first point')
rs.AddPoint(p1)
p2 = rs.GetPoint('Select the 2nd point')
rs.AddPoint(p2)
new_line = rs.AddLine(p1, p2)
o_new_line = rs.coerceline(new_line)
extend_length = rs.GetReal('How much do you want to extend the end by')
result = o_new_line.Extend(0, extend_length)
if result: print 'Extension successful.'
sc.doc.Views.Redraw()
if __name__ == '__main__':
Test()
the line does extend, but you’re not adding the extended line to the document using this call:
result = o_new_line.Extend(0, extend_length)
To add it to the document you would use this:
result = o_new_line.Extend(0, extend_length)
if result:
print 'Extension successful.'
sc.doc.Objects.AddLine(o_new_line)
note that when you use rs based methods, you’re always adding to the document or work with objects in the document, but when you convert your object id to a line object using rs.coerceline you’re working with RhinoCommon geometry. This exists only in memory and needs to be added using code.
Alternatively you might look into using rs.ExtendCurveLength which works on lines or curves in the document.