McNeel Wiki
Picking Text Dots with CRhinoGetObject
edit · print · help · all topics
Main Pages

AccuRender

Bongo

Brazil r/s

Developer

Flamingo

Penguin

Rhino Blogs

Rhino

Search

Languages

Česky

Deutsch

English

Español

Français

Italiano

Polish

日本語

한국어

中文(繁體)

 
.
DeveloperC++, .NET
VersionRhino 4.0
SummaryDemonstrates how to interactively select Text Dot objects with CRhinoGetObject.

Question

I would like to allow the user to interactively select text dot objects from my plug-in command. But, I do not see a text dot geometry filter available for the CRhinoGetObject class. Is this possible?

Answer

If CRhinoGetObject does not have filters to select what you want, then simply derive a new class from CRhinoGetObject and override the CustomGeometryFilter virtual function. From within this function, simply return true if the object meets your selection criteria.

Example

The following example code demonstrates how to derive a new class from CRhinoGetObject and override the CustomGeometryFilter virtual function in order to allow for selection of just text dot objects. That is, those objects whose geometry member is ON_TextDot.

C++

  class CGetTextDotObject : public CRhinoGetObject
  {
    bool CustomGeometryFilter(
        const CRhinoObject* object,
        const ON_Geometry* geometry,
        ON_COMPONENT_INDEX component_index
        ) const;
  };


  bool CGetTextDotObject::CustomGeometryFilter(
      const CRhinoObject* object,
      const ON_Geometry* geometry,
      ON_COMPONENT_INDEX component_index
      ) const
  {
    bool rc = false;
    if( geometry )
    {
      const ON_TextDot* p = ON_TextDot::Cast( geometry );
      if( p )
        rc = true;
    }
    return rc;
  }

C#

  public class GetTextDotObject : RMA.Rhino.MRhinoGetObject
  {
    public override bool CustomGeometryFilter(
        IRhinoObject rh_object, 
        IOnGeometry geometry, 
        OnCOMPONENT_INDEX component_index
        )
    {
      bool rc = false;
      IOnTextDot dot = OnTextDot.ConstCast(geometry);
      if( dot != null )
        rc = true;
      return rc;
    }
  }

Usage

The following example code demonstrates how you can use the new class.

C++

  CRhinoCommand::result CCommandTest::RunCommand( const CRhinoCommandContext& context )
  {
    CGetTextDotObject go;
    go.SetCommandPrompt( L"Select text dots" );
    go.GetObjects( 1, 0 );
    if( go.CommandResult() != success )
      return go.CommandResult();


    const int object_count = go.ObjectCount();
    int i;
    for( i = 0; i < object_count; i++ )
    {
      const ON_TextDot* p = ON_TextDot::Cast( go.Object(i).Geometry() );
      if( p )
      {
        ON_wString sPoint;
        RhinoFormatPoint( p->m_point, sPoint );
        RhinoApp().Print( L"TextDot%d: point = (%s), text = \"%s\"\n", 
                i, sPoint, p->m_text );
      }
    }


    return success;
  }

C#

  public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
  {
    GetTextDotObject go = new GetTextDotObject();
    go.SetCommandPrompt( "Select text dots" );
    go.GetObjects( 1, 0 );
    if( go.CommandResult() != IRhinoCommand.result.success )
    return go.CommandResult();


    int object_count = go.ObjectCount();
    int i = 0;
    for( i = 0; i < object_count; i++ )
    {
      IOnTextDot dot = OnTextDot.ConstCast(go.Object(i).Geometry());
      if (dot != null)
      {
        string sPoint = "";
        RMA.Rhino.RhUtil.RhinoFormatPoint( dot.m_point, ref sPoint );
        RhUtil.RhinoApp().Print(string.Format("TextDot{0}: point = ({1}), text = \"{2}\"\n", 
                i, sPoint,dot.m_text));
      }
    }


    return IRhinoCommand.result.success;
  }
rename · changes · history · subscriptions · lost and found · references · file upload