developer:sdksamples:pointsfromtext


Creating Points from Text Entities

C++

Summary: Demonstrates how to create point objects based on text entities using Rhino SDK.

Question

I have many text elements that display numeric values that identify elevation. I would like to convert these elements to points objects using the Rhino SDK. Again, the text elements denote the elevations of the locations. I would like create the 2-D point by the location of the text and then use the number of the text as the z-coordinate. Is this possible?

Answer

The following example code demonstrates how to solve your problem.

C++

 

To make picking text entities easier for the user, we will use a custom object picker that just filters CRhinoAnnotationText objects.

class CRhGetTextObject : public CRhinoGetObject
{
public:
  bool CustomGeometryFilter(
        const CRhinoObject* object,
        const ON_Geometry* geometry,
        ON_COMPONENT_INDEX component_index
        ) const
  {
    if( object && CRhinoAnnotationText::Cast(object) )
      return true;
    return false;
  }
};

Here is the portion of the command that creates points from the text entities.

CRhinoCommand::result CCommandTest::RunCommand( const CRhinoCommandContext& context )
{
  CRhGetTextObject go;
  go.SetCommandPrompt( L"Select text" );
  go.GetObjects( 1, 0 );
  if( go.CommandResult() != success )
    return go.CommandResult();
 
  int i;
  for( i = 0; i < go.ObjectCount(); i++ )
  {
    const CRhinoAnnotationText* text_obj = CRhinoAnnotationText::Cast( go.Object(i).Object() );
    if( 0 == text_obj )
      continue;
 
    ON_wString text_str( text_obj->String() );
    text_str.TrimLeftAndRight();
 
    double z = 0.0;
    if( RhinoParseNumber(text_str, &z) )
    {
      ON_3dPoint text_pt = text_obj->m_text_block.Plane().Origin();
      text_pt.z = z;
      context.m_doc.AddPointObject( text_pt );
    }
  }
 
  context.m_doc.Redraw();
 
  return success;
}
developer/sdksamples/pointsfromtext.txt · Last modified: 2010/01/26 16:37 (external edit) Driven by DokuWiki Recent changes RSS feed

 © 1997-2012 

McNeel North America Europe Latin AmericaAsia