Site Tools


Differences

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

Link to this comparison view

developer:sdksamples:addlineardimension [2015/09/14] (current)
Line 1: Line 1:
 +====== How To: Add a Linear Dimension to Rhino ======
 +> **Developer:​** //​[[developer:​cplusplusplugins|C++]]//​
 +> **Summary:​** //​Demonstrates how to add a linear dimension object using the Rhino SDK.//
 +
 +===== C++ =====
 +<code 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;
 +}
 +</​code>​
 +
 +The following is a demonstration of how to non-interactively add a linear dimension object to Rhino 4.0.
 +
 +<code c++>
 +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;​
 +}
 +</​code>​
 +
 +
 +{{tag>​Developer cplusplus}}
  
developer/sdksamples/addlineardimension.txt ยท Last modified: 2015/09/14 (external edit)