Say I have a brep, and I would like the user to pick n number of faces, and after each face is selected print the face’s FaceIndex and continue with selection.
I’ve tried setting up a While loop with a Rhino.Input.RhinoGet.GetOneObject() as well as a Rhino.Input.Custom.GetMultiple(1, 0). In the first case the While loop breaks after the first face is selected. In the second case I cannot print any feedback until the user presses enter to complete the multiple object selection.
A cheezy way is to create a GetObject-inherited class like this:
class GetBrepFaces : GetObject
{
public GetBrepFaces()
{
GeometryFilter = ObjectType.Surface;
SubObjectSelect = true;
}
public override bool CustomGeometryFilter(RhinoObject obj, GeometryBase geom, ComponentIndex ci)
{
if (ci.ComponentIndexType == ComponentIndexType.BrepFace && null != obj)
{
var name = obj.Attributes.Name;
RhinoApp.WriteLine(String.IsNullOrEmpty(name)
? string.Format("Type: {0}, Index: {1}", obj.ObjectType.ToString(), ci.Index)
: string.Format("Name: {0}, Index: {1}", name, ci.Index));
}
return true;
}
}
And then use it like this:
protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
var go = new GetBrepFaces();
go.SetCommandPrompt("Select faces");
go.GetMultiple(1, 0);
return Result.Success;
}
I have implemented the above example in Python as follows:
import Rhino
import scriptcontext
import rhinoscriptsyntax as rs
class GetBrepFaces(Rhino.Input.Custom.GetObject):
def __init__(self):
self.GeometryFilter = Rhino.DocObjects.ObjectType.Surface
self.GeometryAttributeFilter = Rhino.Input.Custom.GeometryAttributeFilter.SubSurface
self.SubObjectSelect = True
def CustomGeometryFilter(self, rhObject, geoBase, ci):
print 'rhobj' , rhObject
print 'geoBase', geoBase
print 'ci', ci
if ci.ComponentIndexType == Rhino.Geometry.ComponentIndexType.BrepFace and rhObject != None:
print 'Face Idx: {}'.format(ci.Index)
go = GetBrepFaces()
go.SetCommandPrompt('Select FACE')
go.GetMultiple(1,-1)
I have two issues (refer to attached screenshot of a sample brep with 6 faces, shown as ghosted for clarity, shaded mode used to run the script):
It seems that sub object selection highlighting does not work
When selecting a face (for example clicking on face 1), either face 4 or face 0 index is printed by the custom Get(), as if it were selecting the face behind the picked face relative to the view.
The ‘return True’ statement makes all the difference!
Otherwise the custom get() doesn’t know whether or not the object passed the geometryfilter test…correct?