McNeel Wiki
Creating Radial Dimensions
edit · print · help · all topics
Main Pages

AccuRender

Bongo

Brazil r/s

Developer

Flamingo

Penguin

Rhino Blogs

Rhino

Rhino Labs

Search

Languages

Česky

Deutsch

English

Español

Français

Italiano

Polish

日本語

한국어

中文(繁體)

中文(简体)

 
.
Developer.NET
SummaryDemonstrates how to create radial dimensions using the Rhino SDK.

Question

I would like to create radial dimensions from my plug-in but I am not sure how. Can you help?

Answer

To create a radial dimension, you must create a MRhinoLinearDimension object. The radial dimension's definition is ON_RadialDimension2. Here is the description of ON_RadialDimension2 found in opennurbs_annotation.h:

    The annotation's dimstyle controls the position of TEXT, and the size of the arrowheads.


    In the picture below, [n] means ON_Annotation2::m_points[n].


    Radial dimensions do not permit user positioned text


           knee
            [3]--------[2] TEXT
            /         (tail)
           /
          /
        [1] (arrow head here)


    + [0] = (usually at (0,0) = center of circle)

where:

  • Arrow head [1] is usually a location the user picked on the curve that is being dimensioned.
  • Center [0] is based on the length and direction of the curvature vector at [0].
  • Knee [3] is usually the location the user picked constrained in the direction of the curvature vector at [0].

The following example demonstrates how to create a radial dimension based on a curve picked by the user. This example differs from Rhino's DimRadial command in that it does not allow the user to pick the location of the knee point, and it does not orient the dimension's plane to be parallel with the active construction plane. But, the example should give you a good understanding of how to create radial dimensions.

C#

  public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
  {
    // Select curve for radius dimension
    MRhinoGetObject go = new MRhinoGetObject();
    go.SetCommandPrompt("Select curve for radius dimension");
    go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.curve_object);
    go.GetObjects(1, 1);
    if (go.CommandResult() != IRhinoCommand.result.success)
      return go.CommandResult();


    // Get the curve and the location on the curve where the user picked
    double t = 0;
    IOnCurve curve = go.Object(0).CurveParameter(ref t);
    if (curve == null)
      return IRhinoCommand.result.failure;


    // Make sure the curve is linear
    if (curve.IsLinear() || curve.IsPolyline() > 0)
    {
      RhUtil.RhinoApp().Print("Curve must be non-linear.\n");
      return IRhinoCommand.result.nothing;
    }


    // In this example, just deal with planar curves
    OnPlane plane = new OnPlane();
    if( !curve.IsPlanar(plane) )
    {
      RhUtil.RhinoApp().Print("Curve must be planar.\n");
      return IRhinoCommand.result.nothing;
    }


    // Get the curvature at the picked location
    On3dVector cv = new On3dVector(curve.CurvatureAt(t));
    double len = cv.Length();
    if (len < OnUtil.On_SQRT_EPSILON || len > 1e100)
    {
      cv.Set(0.0, 0.0, 0.0);
      len = 0.0;
    }


    // Center point at end of radius vector
    if (len != 0.0)
    {
      cv.Unitize();
      cv *= 1.0 / len;
    }


    // Set dimension plane
    On3dPoint crv_pt = new On3dPoint(curve.PointAt(t));
    On3dPoint origin = new On3dPoint(plane.ClosestPointTo(crv_pt + cv));
    plane.SetOrigin(origin);


    double u = 0.0, v = 0.0;


    // Get arrow location
    plane.ClosestPointTo(crv_pt, ref u, ref v);
    On2dPoint arrow_pt = new On2dPoint(u, v);


    // Get knee location
    plane.ClosestPointTo(crv_pt - cv, ref u, ref v);
    On2dPoint knee_pt = new On2dPoint(u, v);


    // Create radial dimension
    MRhinoRadialDimension dim = new MRhinoRadialDimension();
    dim.m_radial_dimension.m_type = IOn.eAnnotationType.dtDimRadius;
    dim.SetUserText("<>");
    dim.SetPlane(plane);
    dim.UpdateDimPoints(ref arrow_pt, ref knee_pt);
    dim.UpdateText();


    // Add to document
    context.m_doc.AddObject(dim);
    context.m_doc.Redraw();


    return IRhinoCommand.result.success;
  }
Last Modified [10/8/2008] rename · changes · history · subscriptions · references · file upload