Created
July 8, 2022 15:52
-
-
Save pgolay/30b996c7648541a086208149266c8513 to your computer and use it in GitHub Desktop.
Temporarily draw naked edges on breps, meshes, extrusions and SubD objects.
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 Rhino | |
import scriptcontext as sc | |
import System | |
class DrawEdgesConduit(Rhino.Display.DisplayConduit): | |
def __init__(self, crvs): | |
self.crvs = crvs | |
self.pts = [crv.PointAtStart for crv in self.crvs] | |
self.pts += [crv.PointAtEnd for crv in self.crvs] | |
self.pts = list(set(self.pts)) | |
self.color = Rhino.ApplicationSettings.EdgeAnalysisSettings.ShowEdgeColor | |
self.bbox = Rhino.Geometry.BoundingBox() | |
for crv in crvs: | |
self.bbox.Union(crv.GetBoundingBox(True)) | |
def CalculateBoundingBox(self, e): | |
e.IncludeBoundingBox(self.bbox) | |
def DrawOverlay(self, e): | |
for item in self.crvs: | |
e.Display.DrawCurve(item , self.color, 4) | |
for item in self.pts: | |
e.Display.DrawPoint(item, self.color) | |
def DrawNakeds(): | |
id = rs.GetObject('Select an object for edge display', filter = 8 + 16 + 32, preselect=True) | |
if not id: return | |
geo = rs.coercegeometry(id) | |
if isinstance(geo, Rhino.Geometry.Extrusion): | |
geo = geo.ToBrep() | |
es = [] | |
if isinstance(geo, Rhino.Geometry.Brep): | |
for edge in geo.Edges: | |
if edge.Valence== Rhino.Geometry.EdgeAdjacency.Naked: | |
es.append(edge.ToNurbsCurve()) | |
elif isinstance(geo, Rhino.Geometry.Mesh): | |
eList = geo.TopologyEdges | |
for n in range (eList.Count): | |
if len(list(eList.GetConnectedFaces(n))) == 1: | |
es.append(eList.EdgeLine(n).ToNurbsCurve()) | |
elif isinstance(geo, Rhino.Geometry.SubD): | |
eList = geo.Edges | |
for edge in eList: | |
if (edge.FaceCount) == 1: | |
es.append(edge.ToNurbsCurve(True)) | |
if len(es) == 0: | |
print('No nakeds found.') | |
return | |
conduit = DrawEdgesConduit(es) | |
conduit.Enabled = True | |
sc.doc.Views.Redraw() | |
go = Rhino.Input.Custom.GetOption() | |
go.SetCommandPrompt(str(len(es)) + ' naked edges found. Press <Enter> to continue') | |
go.AddOption('DuplicateAndExit') | |
go.AcceptNothing(True) | |
rc = go.Get() | |
if go.CommandResult()!=Rhino.Commands.Result.Success: | |
return | |
if rc==Rhino.Input.GetResult.Option: | |
out = [] | |
for item in es: | |
out.append(sc.doc.Objects.AddCurve(item)) | |
newGroup = rs.AddGroup() | |
rs.AddObjectsToGroup(out, newGroup) | |
rs.SelectObjects(out) | |
conduit.Enabled = False | |
sc.doc.Views.Redraw() | |
if __name__ == '__main__': DrawNakeds() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment