Hi! I am not an experienced programmer. I am trying to add dimensions to a list of curves, and having difficulty with the vertical (y axis) dimensions in the xy plane. Could someone tell me how to rotate the dimension values 90 degrees, or make them horizontal to the viewport? The code below is working, but I am unable to change how the text is displayed in the heightDim dimension text.
public static List AddDimensionsToLayout(RhinoDoc doc, List curves, double spacing = 1.0, double dimensionFontSize = 0.2)
{
if (curves == null || curves.Count == 0)
{
RhinoApp.WriteLine(“No curves provided for dimensioning.”);
return new List();
}
List<LinearDimension> dimensions = new List<LinearDimension>();
// Process each curve individually
foreach (Curve curve in curves)
{
BoundingBox bbox = curve.GetBoundingBox(true);
// Skip invalid bounding boxes
if (!bbox.IsValid)
continue;
// Create width dimension (horizontal)
double width = bbox.Max.X - bbox.Min.X;
if (width > RhinoMath.ZeroTolerance)
{
// Create horizontal dimension below the curve
Point3d startPt = new Point3d(bbox.Min.X, bbox.Min.Y - spacing,0);
Point3d endPt = new Point3d(bbox.Max.X, bbox.Min.Y - spacing,0);
Point3d dimLinePt = new Point3d(bbox.Max.X, bbox.Max.Y + spacing ,0);
// Create dimension line
LinearDimension widthDim = LinearDimension.Create(AnnotationType.Aligned, doc.DimStyles.Current, Plane.WorldXY, new Vector3d(1, 0, 0), startPt, endPt, dimLinePt, 0);
widthDim.TextHeight = dimensionFontSize;
widthDim.DimensionStyle.TextGap = dimensionFontSize * 0.5;
widthDim.DimensionStyle.ArrowLength = dimensionFontSize * 1.5;
// Add dimension to result
dimensions.Add(widthDim);
}
// Create height dimension (vertical)
double height = bbox.Max.Y - bbox.Min.Y;
if (height > RhinoMath.ZeroTolerance)
{
// Create vertical dimension to the right of the curve
Point3d startPt = new Point3d(bbox.Max.X + spacing, bbox.Min.Y,0);
Point3d endPt = new Point3d(bbox.Max.X + spacing, bbox.Max.Y,0);
Point3d dimLinePt = new Point3d(bbox.Max.X + spacing * 1.5, (bbox.Min.Y + bbox.Max.Y) / 2,0);
// Create dimension line
LinearDimension heightDim =LinearDimension.Create(AnnotationType.Aligned, doc.DimStyles.Current, Plane.WorldXY,new Vector3d(0,1,0), startPt, endPt, dimLinePt, Math.PI/2);
heightDim.TextHeight = dimensionFontSize;
heightDim.DimensionStyle.TextGap = dimensionFontSize * 0.5;
heightDim.DimensionStyle.ArrowLength = dimensionFontSize * 1.5;
heightDim.TextRotation = Math.PI/2; // Rotate text to be more readable
dimensions.Add(heightDim);
}
}
return dimensions;
}