Is there not a way to do this programmatically? Or only with hard typed values? my current solution I just needed to hard type the item from the list
e.g.
rg.MeshFace(new_face_0[0],new_face_0[1],new_face_0[2], new_face_0[3])
Script below, lines 177 to 186. The items at my determined positions don’t get changed.
# SPIN EDGE V1
import Rhino
import Rhino.Geometry as rg
import rhinoscriptsyntax as rs
import scriptcontext as sc
def SpinEdge():
go = Rhino.Input.Custom.GetObject()
go.SetCommandPrompt("Select edge to orient")
go.GeometryAttributeFilter = Rhino.Input.Custom.GeometryAttributeFilter.InnerLoop
go.GeometryFilter = Rhino.DocObjects.ObjectType.EdgeFilter
#go.GeometryFilter = Rhino.DocObjects.ObjectType.MeshEdge
#go.GeometryAttributeFilter = Rhino.Input.Custom.GeometryAttributeFilter.EdgeCurve
go.Get()
objref = go.Object(0)
subd = rs.coercegeometry(objref.ObjectId) #coerce guid
geo = objref.Geometry()
picked_edge_id = objref.GeometryComponentIndex.Index
picked_subd_edge = subd.Edges.Find(picked_edge_id)
if picked_subd_edge.FaceCount == 2:
face1 = picked_subd_edge.FaceAt(0)
face2 = picked_subd_edge.FaceAt(1)
else:
print "Cannot spin Naked Edge."
return
#cant handle triangles yet
#also appears to be an issue when two edges are a straight line
#this might be during subd creation or mesh?
# Manually Loop through subd quad faces (assuming they're quads not tris)
subd_verts = [picked_subd_edge.VertexFrom.Id, picked_subd_edge.VertexTo.Id]
face1, face2 = subd.Faces.Find(face1.Id), subd.Faces.Find(face2.Id)
mesh = rg.Mesh.CreateFromSubDControlNet(subd)
meshfaces, meshverts = mesh.Faces, mesh.Vertices
meshverts.UseDoublePrecisionVertices = True
p3d = meshverts.ToPoint3dArray()
picked_mesh_edge_indices = []
face_verts = []
# Get mesh vertices from subd vertices
for index, i in enumerate(p3d):
if i.DistanceTo(subd.Vertices.Find(subd_verts [0]).ControlNetPoint) == 0:
picked_mesh_edge_indices.append(index)
for index, i in enumerate(p3d):
if i.DistanceTo(subd.Vertices.Find(subd_verts [1]).ControlNetPoint) == 0:
picked_mesh_edge_indices.append(index)
# Determine the adjacent Mesh face indices and hence Corner Indices
all_faces = [ meshverts.GetVertexFaces(i) for i in picked_mesh_edge_indices ]
for i in all_faces:
for vert in i:
face_verts.append(vert)
face_verts_set = set(face_verts)
selected_faces = []
for i in face_verts_set:
if face_verts.count(i) > 1:
selected_faces.append(i)
vert0, vert1 = picked_mesh_edge_indices[0], picked_mesh_edge_indices[1]
face1_corners_list = [ vert for vert in meshfaces.Item[selected_faces[0]] ]
face2_corners_list = [ vert for vert in meshfaces.Item[selected_faces[1]] ]
print "Adjacent Mesh Face Indices are", selected_faces
print "Mesh Face 1 Corner Indices:", meshfaces.Item[selected_faces[0]]
print "Mesh Face 2 Corner Indices:", meshfaces.Item[selected_faces[1]]
print "Edge Indices:", vert0, ";", vert1
#Worked through example:
# [14,30,16,2] [18,30,14,3] 14/30:30/14 relation, rplace second/last occurence
# becomes >>>
# [14,3,16,2] [18,30,16,3]
# if both lists order with 14,30 then 14,30; may be an issue with normals if adjacent (cw/ccw)
#clockwise next vert after edge verts, from 30 on face 1 >> 16
#clockwise next vert after edge verts, from 14 on face 2 >> 3
#in each face, the last edge vert is replaced by the next cw vert
#eg 30 would be replaced with 3; 14 would be replaced with 16
# get list index of edge vert index 1, get list index of edge vert index 2; see which is bigger
#in both lists, get the index of where each value is from those selected
#store as dict eg 14:0 30:1, 30:1 14:2
#if index position difference is greater than one, theyre at ends, use the smallest
def FunctionifyTbd(picked_mesh_edge_indices, face1_corners_list):
for i in picked_mesh_indices:
if i in face1_corners_list:
mydict1[i] = face1_corners_list.index(i)
dictionary = {}
if abs(dictionary.get(vert0) - dictionary.get(vert1)) >1:
#if difference between dict values is > 1, use index of 0
# i.e. [0*,1,2,3*] <<< difference = 3, Tris [0*,1,2*]
face_index_to_edit = 0
else:
if dictionary.get(vert0) > dictionary.get(vert1):
face_index_to_edit = dictionary.get(vert0)
else:
face_index_to_edit = dictionary.get(vert1)
next_index = face_index_to_edit+1
if next_index == 4:
next_index = 0
mydict1 = {}
mydict2 = {}
#generate index locations of the picked vertices
#in respect to each faces makeup in terms of vertices
for i in picked_mesh_edge_indices:
if i in face1_corners_list:
mydict1[i] = face1_corners_list.index(i)
if i in face2_corners_list:
mydict2[i] = face2_corners_list.index(i)
if mydict1.get(vert0) == mydict1.get(vert0) | mydict2.get(vert0) == mydict2.get:
print "Hmm, something's up"
print "Dictionaries for Edge Vertex Location in Lists:", mydict1, mydict2
# checking difference, if the edges are at list ends, if difference is >1
if abs(mydict1.get(vert0) - mydict1.get(vert1)) >1:
#if difference between dict values is > 1, use index of 0
# i.e. [0*,1,2,3*] <<< difference = 3, Tris [0*,1,2*]
edit_face0_index = 0
else:
if mydict1.get(vert0) > mydict1.get(vert1):
edit_face0_index = mydict1.get(vert0)
else:
edit_face0_index = mydict1.get(vert1)
if abs(mydict2.get(vert0) - mydict2.get(vert1)) >1:
edit_face1_index = 0
else:
if mydict2.get(vert0) > mydict2.get(vert1):
edit_face1_index = mydict2.get(vert0)
else:
edit_face1_index = mydict2.get(vert1)
print "Indices to edit:", "face0:", edit_face0_index, "face1:", edit_face1_index
next_index_0 = edit_face0_index+1 #need to not let it be 4, ie 3+1, if tris then 2+1
next_index_1 = edit_face1_index+1
if next_index_0 == 4:
next_index_0 = 0
if next_index_1 == 4:
next_index_1 = 0
"""
if next_index_0 == 3:
next_index_0 = 0
if next_index_1 == 3:
next_index_1 = 0
"""
new_face_0, new_face_1 = face1_corners_list, face2_corners_list
list0_extracted_value = face1_corners_list[ next_index_0 ]
list1_extracted_value = face2_corners_list[ next_index_1 ]
#then swap
new_face_0[edit_face0_index] = list1_extracted_value
new_face_1[edit_face1_index] = list0_extracted_value
print "face 1:", new_face_0, "face 2:", new_face_1
# if the biggest dict value is 3, 0 index is the one to be swapped
# else dict value +1 is what is taken and used in other list
#meshfaces.Item[selected_faces[0]] = rg.MeshFace(new_face_0[0],new_face_0[1],new_face_0[2], new_face_0[3])
#meshfaces.Item[selected_faces[1]] = rg.MeshFace(new_face_1[0],new_face_1[1],new_face_1[2], new_face_1[3])
print "face0 index to edit:", edit_face0_index, "face1 index to edit:", edit_face1_index
print "value in face0 to replace with:", list1_extracted_value, "value in face1 to replace with:", list0_extracted_value
print meshfaces.Item[selected_faces[0]]
print meshfaces.Item[selected_faces[1]]
meshfaces.Item[selected_faces[0]].Item[edit_face0_index] = list1_extracted_value
meshfaces.Item[selected_faces[1]].Item[edit_face1_index] = list0_extracted_value
print meshfaces.Item[selected_faces[0]]
print meshfaces.Item[selected_faces[1]]
#Add SubD
newsubd = rg.SubD.CreateFromMesh( mesh )
sc.doc.Objects.Replace(objref.ObjectId, newsubd) #use guid to replace
if __name__ == "__main__":
SpinEdge()