Feedback during selection of objects

Hi All,

Quick question I can’t seem to find an answer to:

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.

Any ideas?

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;
}

Hi @dale

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):

  1. It seems that sub object selection highlighting does not work
  2. 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.

Any ideas where I might be going wrong here?

You didn’t translate my code correctly. :wink:

Try this:

import Rhino
import scriptcontext
import rhinoscriptsyntax as rs

class GetBrepFaces(Rhino.Input.Custom.GetObject):

    def __init__(self):
        self.GeometryFilter = Rhino.DocObjects.ObjectType.Surface
        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)
        return True

go = GetBrepFaces()
go.SetCommandPrompt('Select FACE')
go.GetMultiple(1,0)

The ‘return True’ statement makes all the difference! :slight_smile:
Otherwise the custom get() doesn’t know whether or not the object passed the geometryfilter test…correct?

Thanks a lot @dale

Correct!