Site Tools


How To: Add a Linear Dimension to Rhino

Developer: C++
Summary: Demonstrates how to add a linear dimension object using the Rhino SDK.

C++

// The following is a demonstration of how to interactively add a linear dimension object to Rhino.
CRhinoCommand::result CCommandTest::RunCommand( const CRhinoCommandContext& context )
{
  CRhinoLinearDimension* pDim = 0;
 
  CArgsRhinoDimLinear args;
  args.SetFirstPointPrompt( L"First dimension point" );
  args.SetSecondPointPrompt( L"Second dimension point" );
  args.SetDragPointPrompt( L"Dimension location" );
  args.SetIsInteractive( context.IsInteractive() ? true : false );
 
  CRhinoCommand::result rc = RhinoGetDimLinear( args, pDim, 0 );
 
  if( rc == success && pDim )
  {
    context.m_doc.AddObject( pDim, FALSE);
    context.m_doc.Redraw();
  } 
 
  return rc;
}

The following is a demonstration of how to non-interactively add a linear dimension object to Rhino 4.0.

CRhinoCommand::result CCommandTestSdk::RunCommand( const CRhinoCommandContext& context )
{
  ON_3dPoint origin( 1, 1, 0 );
  ON_3dPoint offset( 11, 1, 0 );
  ON_3dPoint pt( (offset.x-origin.x)/2, 3, 0 );
 
  CRhinoLinearDimension* dim_obj = new CRhinoLinearDimension();
 
  ON_Plane plane( ON_xy_plane );
  plane.SetOrigin( origin );
  dim_obj->SetPlane( plane );
  double u, v;
  plane.ClosestPointTo( origin, &u, &v );
  dim_obj->SetPoint( 0, ON_2dPoint(u,v) );
 
  plane.ClosestPointTo( offset, &u, &v );
  dim_obj->SetPoint( 2, ON_2dPoint(u,v) );
 
  plane.ClosestPointTo( pt, &u, &v );
  dim_obj->UpdateDimPoints( ON_2dPoint(u,v) );
  dim_obj->UpdateText();
 
  if( context.m_doc.AddObject(dim_obj) )
    context.m_doc.Redraw();
  else
    delete dim_obj;
 
  return CRhinoCommand::success;
}
developer/sdksamples/addlineardimension.txt ยท Last modified: 2020/08/14 (external edit)