@Jack_Minardi wrote:
I am attempting to write a python script that allows the user to preselect vertices on a mesh and then set their color. The code is pasted below. (It is modified from @pascal’s code found here.)
import Rhino import rhinoscriptsyntax as rs import scriptcontext as sc from System import Drawing def color_vertices(): color= Drawing.Color.White if sc.sticky.has_key("CRNT_COLOR"): color = sc.sticky["CRNT_COLOR"] rc, color = Rhino.UI.Dialogs.ShowColorDialog(color) if not rc: return sc.sticky["CRNT_COLOR"] = color gv = Rhino.Input.Custom.GetObject() gv.SetCommandPrompt("Select one ore more mesh vertices. Hit Enter when done.") gv.GeometryFilter = Rhino.DocObjects.ObjectType.MeshVertex gv.EnablePreSelect(True, True) result = gv.GetMultiple(1,0) if( gv.CommandResult() != Rhino.Commands.Result.Success ): return mesh = gv.Object(0).Mesh() Id = gv.Object(0).ObjectId count = mesh.VertexColors.Count if count == 0: mesh.VertexColors.CreateMonotoneMesh(Drawing.Color.White) count = mesh.VertexColors.Count colors = [mesh.VertexColors[i] for i in range(count)] for objref in gv.Objects(): idx = objref.GeometryComponentIndex.Index vList = [mesh.Vertices[i] for i in range (count)] idx = vList.index(mesh.TopologyVertices[idx]) colors[idx] = color mesh.VertexColors.Clear() for c in colors: mesh.VertexColors.Add(c) sc.doc.Objects.Replace(Id, mesh) sc.doc.Views.Redraw() color_vertices()
If I create a mesh, turn PointsOn, select some points, and then run the script I would expect those selected points to be used, but instead I have to select points after running the script every time. (Note I am using
gv.EnablePreSelect(True, True)
)The high level goal here is to allow the user to work with all the selecting methods (SelBoundary, SelBrush, etc) so if there is some other way to achieve that goal I am willing to try.
Posts: 3
Participants: 2