Since it’s been so nicely fixed in R7 and does exactly what’s expected, I’m looking to automate shrinkage of specific edges emulating ExtendSrf with rhinocommon.
It’s probably this method:
https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Geometry_Surface_Extend.htm
This doesn’t work for trimmed surfaces. The command does. How do we get around it?
import Rhino
from Rhino.Input.Custom import *
from Rhino.DocObjects import *
from Rhino.Commands import *
from Rhino.Geometry import *
from scriptcontext import doc
def RunCommand():
go = Rhino.Input.Custom.GetObject()
go.SetCommandPrompt("Select edge of surface to extend")
go.GeometryFilter = ObjectType.EdgeFilter
go.GeometryAttributeFilter = GeometryAttributeFilter.EdgeCurve
go.Get()
if go.CommandResult() != Result.Success:
return go.CommandResult()
obj_ref = go.Object(0)
surface = obj_ref.Surface()
if surface == None:
print "Unable to extend polysurfaces."
return Result.Failure
brep = obj_ref.Brep()
face = obj_ref.Face()
if brep == None or face == None:
return Result.Failure
if face.FaceIndex < 0:
return Result.Failure
if not brep.IsSurface:
print "Unable to extend trimmed surfaces."
return Result.Nothing
curve = obj_ref.Curve()
trim = obj_ref.Trim()
if trim == None:
return Result.Failure
if trim.TrimType == BrepTrimType.Seam:
print "Unable to extend surface at seam."
return Result.Nothing
extended_surface = surface.Extend(trim.IsoStatus, 5.0, True)
if extended_surface != None:
mybrep = Brep.CreateFromSurface(extended_surface)
doc.Objects.Replace(obj_ref.ObjectId, mybrep)
doc.Views.Redraw()
return Result.Success
if __name__ == "__main__":
RunCommand()
Yes a trimmed surface is a Brep
. So you need to access the brep edge to extend (e.g. using Brep.Edges.Item
) and call one of its several Extend
method overloads (I think, haven’t ever implemented these):
Edit: Those don’t actually look relevant on further inspection. One can access a BrepFace
and Extend
that, but this calls the same untrimmed surface method. Apologies for the confusion.
You have to get the trimmed BrepFace, but BrepFace accesses the untrimmed, underlying surface(or so), typing from memory.
Something along this might work:
Brep brep = brepFace.DuplicateFace(true);
Surface srf = brep.Faces[0].DuplicateSurface();
Extending trimmed surfaces is not exposed to the SDK and RhinoCommon. I added this request to YouTrack here…