Last active
January 19, 2019 16:30
-
-
Save pgolay/266ad83232df8ba181ef3ca84d8bd29e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import rhinoscriptsyntax as rs | |
import scriptcontext as sc | |
import Rhino | |
def RadialSplit(): | |
blnDel = True | |
while True: | |
if sc.sticky.has_key('DELETE_SPLIT'): | |
blnDel = sc.sticky['DELETE_SPLIT'] | |
go = Rhino.Input.Custom.GetObject() | |
go.GeometryFilter = Rhino.DocObjects.ObjectType.Surface | |
go.SetCommandPrompt("Select surface to split") | |
opDel = Rhino.Input.Custom.OptionToggle(blnDel,'No', 'Yes') | |
go.AddOptionToggle("DeleteInput", opDel) | |
rc = go.Get() | |
if go.CommandResult() != Rhino.Commands.Result.Success: | |
return go.CommandResult() | |
if rc == Rhino.Input.GetResult.Option: | |
blnDel = opDel.CurrentValue | |
sc.sticky['DELETE_SPLIT'] = blnDel | |
continue | |
if rc == Rhino.Input.GetResult.Object: | |
objref = go.Object(0) | |
idx = objref.GeometryComponentIndex.Index | |
id = go.Object(0).ObjectId | |
break | |
if not id: return | |
tol = sc.doc.ModelAbsoluteTolerance | |
geo = sc.doc.Objects.Find(id).BrepGeometry | |
if idx == -1: idx = 0 | |
face = geo.Faces[idx] | |
if not face.IsPlanar(): | |
print "The selected face is not planar. Nothing done." | |
return | |
trims = [face.OuterLoop.Trims[n].Edge.EdgeCurve for n in range(face.OuterLoop.Trims.Count)] | |
border = Rhino.Geometry.Curve.JoinCurves(trims)[0] | |
border = border.Simplify(Rhino.Geometry.CurveSimplifyOptions.All,tol, sc.doc.ModelAngleToleranceRadians | |
if border.IsClosable(tol*10): | |
border.MakeClosed(tol) | |
#sc.doc.Objects.AddCurve(border) | |
mp = Rhino.Geometry.AreaMassProperties.Compute(border) | |
if not mp: | |
print "Error locating centroid" | |
return | |
pt = mp.Centroid | |
pts = [] | |
for trim in trims: | |
pts.append(trim.PointAtStart) | |
pts.append(trim.PointAtEnd) | |
pts = Rhino.Geometry.Point3d.CullDuplicates(pts, tol) | |
lines = [Rhino.Geometry.LineCurve(point, pt) for point in pts] | |
brep = face.Split(lines, tol) | |
if brep: | |
brep.Compact() | |
if blnDel: | |
sc.doc.Objects.Replace(id, brep) | |
else: | |
sc.doc.Objects.AddBrep(brep) | |
sc.doc.Views.Redraw() | |
if __name__ == '__main__':RadialSplit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment