Say I have a small mesh cube, now how can I run a script and select mesh face 1,3 and 5?
Thanks!
Say I have a small mesh cube, now how can I run a script and select mesh face 1,3 and 5?
Thanks!
Hi @Holo,
do you want to prompt the user for a mesh face selection or just a function to pass mesh face indices (numbers) and the script should end with those faces selected ?
c.
Hi Clement, I need the latter.
I will use a predefined mesh and I need to select a defined set of those mesh faces to edit.
So the box is a good, simple example.
Later on I will need to select some faces and then store that selection, but that is not needed now.
I’ll probably make a loop selection tool also, but still that is not what I need now.
Hi @Holo,
below example outlines some differences in V5 vs V6 when doing subobject selection. In V5, the subobject selection can be done, but is not persistent, so it will only remain during scriptrun. My way around that has been to use HighlightSubObject
instead.
In V6 there is a new functionality which adds a persistentSelect
argument to SelectSubObject
. So you could do below and the mesh faces are ready to be transformed, deleted etc. after scriptrun. My example just selects the first mesh face (index = 0):
import Rhino
import scriptcontext
import rhinoscriptsyntax as rs
def DoSomething():
id = rs.GetObject("Select mesh", 32, True, False)
if not id: return
obj = rs.coercerhinoobject(id, True, True)
index_type = Rhino.Geometry.ComponentIndexType.MeshFace
comp_index = Rhino.Geometry.ComponentIndex(index_type, 0) # face no. 0
# new in V6, persistent subobject selection
persistent = True
state = obj.SelectSubObject(comp_index, True, True, persistent)
# V5, highlight remains, even after scriptrun
# obj.HighlightSubObject(comp_index, True)
# V5, subselection only remains during scriptrun
# obj.SelectSubObject(comp_index, True, True)
# rs.Sleep(100)
scriptcontext.doc.Views.Redraw()
DoSomething()
Note that in above example for V6, you can query the selection state
after SelectSubObject
has been called. Here is some info about the returned integers. (that works in V5 too of course)
c.
Excellent! That works fine in V6!
I see that if I want to select mesh face 0,1,2 and 3 then this works:
(but is that the correct way, or could I make an array of the numbers?)
import Rhino
import scriptcontext
import rhinoscriptsyntax as rs
def DoSomething():
id = rs.GetObject("Select mesh", 32, True, False)
if not id: return
obj = rs.coercerhinoobject(id, True, True)
index_type = Rhino.Geometry.ComponentIndexType.MeshFace
comp_index_0 = Rhino.Geometry.ComponentIndex(index_type, 0) # face no. 0
comp_index_1 = Rhino.Geometry.ComponentIndex(index_type, 1) # face no. 1
comp_index_2 = Rhino.Geometry.ComponentIndex(index_type, 2) # face no. 2
comp_index_3 = Rhino.Geometry.ComponentIndex(index_type, 3) # face no. 3
# new in V6, persistent subobject selection
persistent = True
state = obj.SelectSubObject(comp_index_0, True, True, persistent)
state = obj.SelectSubObject(comp_index_1, True, True, persistent)
state = obj.SelectSubObject(comp_index_2, True, True, persistent)
state = obj.SelectSubObject(comp_index_3, True, True, persistent)
scriptcontext.doc.Views.Redraw()
DoSomething()
@Holo, yes you can loop too:
import Rhino
import scriptcontext
import rhinoscriptsyntax as rs
def DoSomething():
id = rs.GetObject("Select mesh", 32, True, False)
if not id: return
obj = rs.coercerhinoobject(id, True, True)
index_type = Rhino.Geometry.ComponentIndexType.MeshFace
face_indices = [0,1,2,3]
for i in face_indices:
comp_index = Rhino.Geometry.ComponentIndex(index_type, i)
obj.SelectSubObject(comp_index, True, True, True)
scriptcontext.doc.Views.Redraw()
DoSomething()
c.