ExtendSrf and preselect edges

Hi,

I am facing an issue that the usual Rhino ExtendSrf command supports trimmed surfaces while the one in RhinoCommon and Python Script does not. When I use it script the surface will be untrimmed so I need to use rs.Command(“_ExtrudeSrf”) and the edge need to be preselected.

I have found some resources that gives idea however it does not work. I found the following topic and the last message from clement includes a solution when the user select the surface-edge.

In my situation, the script will sleect the edge by a given Index number. I came up with the following script steps however the edge remains unselected.

import Rhino
import scriptcontext
import rhinoscriptsyntax as rs

# Get object:
ge = Rhino.Input.Custom.GetObject()
ge.SetCommandPrompt("Select edges")
ge.GeometryFilter = Rhino.DocObjects.ObjectType.Surface
ge.EnableUnselectObjectsOnExit(False)
ge.SubObjectSelect = False
ge.EnableUnselectObjectsOnExit(False)
ge.EnablePreSelect(True, True)
ge.Get()

# ObjRef -> RhinoObject
rh_object = ge.Object(0).Object()
number = 2

index_type = Rhino.Geometry.ComponentIndexType.BrepEdge
comp_index = Rhino.Geometry.ComponentIndex(index_type, number)
rh_object.SelectSubObject(comp_index, True, True)
rs.Command("_ExtendSrf " + "1")

Idea 2:

import Rhino
import scriptcontext
import rhinoscriptsyntax as rs

# Get object:
ge = Rhino.Input.Custom.GetObject()
ge.SetCommandPrompt("Select edges")
ge.GeometryFilter = Rhino.DocObjects.ObjectType.Surface
ge.EnableUnselectObjectsOnExit(False)
ge.SubObjectSelect = False
ge.Get()

# Return -> ObjRef
obj_ref = ge.Object(0)
# ObjRef -> Return: RhinoObject
rh_object = obj_ref.Object()
number = 2
edge = obj_ref.Brep().Edges[number]
edge_index = edge.EdgeIndex

index_type = Rhino.Geometry.ComponentIndexType.BrepEdge
comp_index = Rhino.Geometry.ComponentIndex(index_type, number)
rh_object.SelectSubObject(comp_index, True, True)
rs.Command("_ExtendSrf " + "1")
import rhinoscriptsyntax as rs
from scriptcontext import doc
import Rhino.Geometry as rg
id = rs.GetSurfaceObject()[0]
brep = doc.Objects.FindId(id)
component_index = rg.ComponentIndex(rg.ComponentIndexType.BrepEdge, 1)
brep.SelectSubObject(component_index, True, True, True)
rs.Command("_ExtendSrf 5 _Enter")

ExtendSrf.py (316 Bytes)

Thank you, It works, great in Rhino 6. I have found the solution for Rhino 5 as well.

import Rhino
import scriptcontext
import rhinoscriptsyntax as rs
from collections import defaultdict


ge = Rhino.Input.Custom.GetObject()
ge.SetCommandPrompt("Select edges")
ge.GeometryFilter = Rhino.DocObjects.ObjectType.Curve
ge.EnableUnselectObjectsOnExit(False)
ge.EnablePreSelect(True, True)
ge.SubObjectSelect = True
ge.Get()
number = 3
obj_ref = ge.Object(0)
edge = obj_ref.Edge()
edge_index = edge.EdgeIndex
rh_object = obj_ref.Object()
index_type = Rhino.Geometry.ComponentIndexType.BrepEdge
comp_index = Rhino.Geometry.ComponentIndex(index_type, number)
rs.UnselectAllObjects()
rh_object.SelectSubObject(comp_index, True, True)
rs.Command("_ExtendSrf " + "1")