How can i get LinearDimensionObject origin point?


#1

i use c#

        foreach (Rhino.DocObjects.RhinoObject textobject in rhobjs)
        {
            string s = textobject.GetType().ToString();
            if(s == "Rhino.DocObjects.TextObject")
            {
                Rhino.DocObjects.TextObject to = textobject as Rhino.DocObjects.TextObject;
                Point3d pp = to.TextGeometry.Plane.Origin;
                textPointList.Add(pp);
            }
            else if(s == "Rhino.DocObjects.LinearDimensionObject")
            {
                Rhino.DocObjects.LinearDimensionObject to = textobject as Rhino.DocObjects.LinearDimensionObject;
                How to....?

                
            }

(Dale Fugier) #2

Let me know if this sample code helps you.

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
  foreach (var rh_obj in doc.Objects)
  {
    // Try casting the object's geometry as a LinearDimension
    var dim = rh_obj.Geometry as Rhino.Geometry.LinearDimension;
    if (null != dim)
    {
      // Dimensions are planar objects, and their reference points
      // are 2d points on the dimension's plane.
      var dim_points = new Point2d[5];
      dim_points[0] = dim.Arrowhead1End;
      dim_points[1] = dim.Arrowhead2End;
      dim_points[2] = dim.ExtensionLine1End;
      dim_points[3] = dim.ExtensionLine2End;
      dim_points[4] = dim.TextPosition;

      // Get a 3d point by evaluating the 2d points on the 
      // dimension's plane
      var points = new Point3d[5];
      for (var i = 0; i < dim_points.Length; i++)
      {
        var pt = dim_points[i];
        points[i] = dim.Plane.PointAt(pt.X, pt.Y);
      }

      // Add the points
      doc.Objects.AddPoints(points);
    }
  }

  doc.Views.Redraw();
      
  return Result.Success;
}

– Dale