SplitMeshLargeDiff

Created Diff never expires
7 removals
104 lines
7 additions
104 lines
import rhinoscriptsyntax as rs
import rhinoscriptsyntax as rs
import Rhino as rhino
import Rhino as rhino
import scriptcontext as sc
import scriptcontext as sc


__commandname__ = "splitMeshLarge"
__commandname__ = "splitMeshLarge"


def RunCommand( is_interactive ):
def RunCommand( is_interactive ):
curr_doc = sc.doc
curr_doc = sc.doc
filter = rhino.DocObjects.ObjectType.Mesh
filter = rhino.DocObjects.ObjectType.Mesh
rc, objrefs = rhino.Input.RhinoGet.GetMultpileObjects("Select Meshs to split", False, filter)
rc, objrefs = rhino.Input.RhinoGet.GetMultpileObjects("Select Meshs to split", False, filter)


for objref in objrefs
for objref in objrefs:
old_mesh=objref.Mesh()
mesh=objref.Mesh()
if old_mesh.IsClosed:
if mesh.IsClosed:
print("Your Mesh is already closed')
print("Your Mesh is already closed')
return
return
mesh.old_mesh.DuplicateMesh()
mesh.DuplicateMesh()
mesh.Vertices.CombineIdentical(True,True)
mesh.Vertices.CombineIdentical(True,True)
curr_doc.Objects.Replace(objref,mesh)
curr_doc.Objects.Replace(objref,mesh)


meshTopologyEdgeList = mesh.TopologyEdges
meshTopologyEdgeList = mesh.TopologyEdges
meshTopologyVertexList = mesh.TopologyVertices
meshTopologyVertexList = mesh.TopologyVertices
verticesNakedDict = mesh.GetNakedEdgePointStatus()
verticesNakedDict = mesh.GetNakedEdgePointStatus()
nakedEdges = []
nakedEdges = []
nakedEdgePoints = []
nakedEdgePoints = []
nakedEdgeLengths = []
nakedEdgeLengths = []


for i in range(meshTopologyEdgeList.Count):
for i in range(meshTopologyEdgeList.Count):
pairVertices = meshTopologyEdgeList.GetTopologyVertices(i)
pairVertices = meshTopologyEdgeList.GetTopologyVertices(i)
index1 = pairVertices[0]
index1 = pairVertices[0]
index2 = pairVertices[1]
index2 = pairVertices[1]
if verticesNakedDict[index1] and verticesNakedDict[index2]:
if verticesNakedDict[index1] and verticesNakedDict[index2]:
pt1=mesh.Vertices[index1]
pt1=mesh.Vertices[index1]
pt2=mesh.Vertices[index2]
pt2=mesh.Vertices[index2]
nakedEdgePoints.append([pt1,pt2])
nakedEdgePoints.append([pt1,pt2])
nakedEdges.append(i)
nakedEdges.append(i)
line = rhino.Geometry.Line(pt1,pt2)
line = rhino.Geometry.Line(pt1,pt2)
nakedEdgeLengths.append(line.Length)
nakedEdgeLengths.append(line.Length)
ignoreVar, nakedEdges = zip(*sorted(zip(nakedEdgeLengths, nakedEdges), reverse=True))
ignoreVar, nakedEdges = zip(*sorted(zip(nakedEdgeLengths, nakedEdges), reverse=True))
ignoreVar, nakedEdgePoints = zip(*sorted(zip(nakedEdgeLenghts, nakedEdgePoints), reverse=True))
ignoreVar, nakedEdgePoints = zip(*sorted(zip(nakedEdgeLenghts, nakedEdgePoints), reverse=True))
for i in range(len(nakedEdges)):
for i in range(len(nakedEdges)):
pairVertices = meshTopologyEdgeList.GetTopologyVertices(nakedEdges[i])
pairVertices = meshTopologyEdgeList.GetTopologyVertices(nakedEdges[i])
testpt = nakedEdgePoints[i][0]
testpt = nakedEdgePoints[i][0]
for counter,vertex in enumerate(mesh.Vertices):
for counter,vertex in enumerate(mesh.Vertices):
if vertex == nakedEdgePoints[i][0]:
if vertex == nakedEdgePoints[i][0]:
index1=counter
index1=counter
elif vertex == nakedEdgePoints[i][1]:
elif vertex == nakedEdgePoints[i][1]:
index2=counter
index2=counter
line = rhino.Geometry.Line(mesh.Vertices[index1], mesh.Vertices[index2])
line = rhino.Geometry.Line(mesh.Vertices[index1], mesh.Vertices[index2])
bb = line.BoundingBox
bb = line.BoundingBox
rs.ZoomBoundingBox(bb)
rs.ZoomBoundingBox(bb)
line_GUID = curr_doc.Objects.AddLine(line)
line_GUID = curr_doc.Objects.AddLine(line)
rs.SelectObject(line_GUID)
rs.SelectObject(line_GUID)
curr_doc.View.Redraw()
curr_doc.Views.Redraw()


gi=rhino.Input.Custom.GetInteger()
gi=rhino.Input.Custom.GetInteger()
gi.SetCommandPrompt('How many times should we split this edge')
gi.SetCommandPrompt('How many times should we split this edge')
gi.SetCommandPromptDefault('0')
gi.SetCommandPromptDefault('0')
gi.SetDefaultInteger(0)
gi.SetDefaultInteger(0)
gi.AddOption('Exit')
gi.AddOption('Exit')
gi.SetLowerLimit(0, False)
gi.SetLowerLimit(0, False)
gi.SetUpperLimit(9,False)
gi.SetUpperLimit(9,False)
get_gi = gi.Get()
get_gi = gi.Get()
if gi.CommandResult()!=rhino.Commands.Result.Success:
if gi.CommandResult()!=rhino.Commands.Result.Success:
curr_doc.Objects.Delete(line_GUID,True)
curr_doc.Objects.Delete(line_GUID,True)
return
return
if get_gi == rhino.Input.GetResult.Number:
if get_gi == rhino.Input.GetResult.Number:
curr_doc.Objects.Delete(line_GUID,True)
curr_doc.Objects.Delete(line_GUID,True)
numSplits = gi.Number()
numSplits = gi.Number()
elif get_gi == rhino.Input.GetResult.Option:
elif get_gi == rhino.Input.GetResult.Option:
curr_doc.Objects.Delete(line_GUID,True)
curr_doc.Objects.Delete(line_GUID,True)
print('User exited')
print('User exited')
return
return


if numSplits==0:
if numSplits==0:
continue
continue


edgeTopoIndex = meshTopologyEdgeList.GetEdgeIndex(index1,index2)
edgeTopoIndex = meshTopologyEdgeList.GetEdgeIndex(index1,index2)
for j in range(numSplits):
for j in range(numSplits):
splitPercentage = (j+1)/(numSplits+1)
splitPercentage = (j+1)/(numSplits+1)
edgeTopoIndex = meshTopologyEdgeList.GetEdgeIndex(index1,index2)
edgeTopoIndex = meshTopologyEdgeList.GetEdgeIndex(index1,index2)
print(meshTopologyEdgeList.Count)
print(meshTopologyEdgeList.Count)
flag = meshTopologyEdgeList.SplitEdge(edgeTopoIndex,splitPercentage) #THE ISSUE IS HERE!!
flag = meshTopologyEdgeList.SplitEdge(edgeTopoIndex,splitPercentage) #THE ISSUE IS HERE!!
print(meshTopologyEdgeList.Count)
print(meshTopologyEdgeList.Count)
print(flag)
print(flag)
curr_doc.Objects.Replace(objref,mesh)
curr_doc.Objects.Replace(objref,mesh)
curr_doc.View.Redraw()
curr_doc.Views.Redraw()
if flag!=False:
if flag!=False:
meshTopologyEdgeList = meshTopologyEdges
meshTopologyEdgeList = meshTopologyEdges
old_index1 = index1
old_index1 = index1
index1 = mesh.Vertices.Count-1
index1 = mesh.Vertices.Count-1
verticesNakedDict = mesh.GetNakedEdgePointStatus()
verticesNakedDict = mesh.GetNakedEdgePointStatus()
edgeTopoIndex = meshTopologyEdgeList.GetEdgeIndex(index1,index2)
edgeTopoIndex = meshTopologyEdgeList.GetEdgeIndex(index1,index2)
else:
else:
print('Script error')
print('Script error')
return
return
curr_doc.Objects.Replace(objref,mesh)
curr_doc.Objects.Replace(objref,mesh)
curr_doc.View.Redraw()
curr_doc.Views.Redraw()
print('All done with naked Edges')
print('All done with naked Edges')


RunCommand(True)
RunCommand(True)