Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

developer:sdksamples:pointsfromtext [2015/09/14] (current)
Line 1: Line 1:
 +====== 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.
 +
 +<code c++>
 +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;
 +  }
 +};
 +
 +</​code>​
 +Here is the portion of the command that creates points from the text entities.
 +
 +<code c++>
 +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;
 +}
 +</​code>​
 +
 +\\
 +
 +{{tag>​Developer cplusplus}}
  
developer/sdksamples/pointsfromtext.txt ยท Last modified: 2015/09/14 (external edit)