LinearDimension prints sideways in WorldZX plane

I don’t know what I’m doing wrong, but the linear dimension prints sideways. How can I get the linear dimension to appear correctly above the line it is measuring while aligning the dimension to the front viewport?

```

#! python 2

import Rhino.Geometry as rg
import Rhino

# Create the line from (0, 0, 1) to (5, 0, 1)
start_point = rg.Point3d(0, 0, 1)
end_point = rg.Point3d(5, 0, 1)
line = rg.Line(start_point, end_point)
line_curve = rg.LineCurve(line)

# Use the World ZX plane
zx_plane = rg.Plane.WorldZX

# Project points onto the ZX plane (returns Point3d)
start_point_3d = zx_plane.ClosestPoint(start_point)
end_point_3d = zx_plane.ClosestPoint(end_point)

# Convert projected points to Point2d
# For WorldZX plane: Point2d.X = Point3d.X, Point2d.Y = Point3d.Z
start_point_2d = rg.Point2d(start_point_3d.X, start_point_3d.Z)
end_point_2d = rg.Point2d(end_point_3d.X, end_point_3d.Z)

# Define the dimension line offset (in the Y direction of the ZX plane)
offset_distance = 2.0
offset_vector = zx_plane.YAxis * offset_distance
dimension_point_3d = (start_point_3d + end_point_3d) * 0.5 + offset_vector  # Midpoint + offset

# Convert the dimension point to a Point2d
dimension_point_2d = rg.Point2d(dimension_point_3d.X, dimension_point_3d.Z)

# Create the LinearDimension
linear_dimension = rg.LinearDimension(zx_plane, start_point_2d, end_point_2d, dimension_point_2d)

# Add the line and dimension to the Rhino document
doc = Rhino.RhinoDoc.ActiveDoc
doc.Objects.AddLine(line)
doc.Objects.AddLinearDimension(linear_dimension)

# Refresh the view
doc.Views.Redraw()

Results of above code is shown below (I want the dimension to be horizontal and aligned to the line):

Hi @webdunce ,

#! python 2

import Rhino.Geometry as rg
import Rhino

start_point = rg.Point3d(0, 0, 1)
end_point = rg.Point3d(5, 0, 1)
line = rg.Line(start_point, end_point)

dimension_plane = rg.Plane(rg.Point3d(0, 0, 1), rg.Vector3d.XAxis, rg.Vector3d.YAxis)

start_point_2d = rg.Point2d(start_point.X, start_point.Y)
end_point_2d = rg.Point2d(end_point.X, end_point.Y)

offset_distance = 2.0
dimension_point_2d = rg.Point2d((start_point.X + end_point.X) * 0.5, 
                                 start_point.Y + offset_distance)

linear_dimension = rg.LinearDimension(dimension_plane, start_point_2d, end_point_2d, dimension_point_2d)

doc = Rhino.RhinoDoc.ActiveDoc
doc.Objects.AddLine(line)
doc.Objects.AddLinearDimension(linear_dimension)
doc.Views.Redraw()

You must use the correct plane, the above snippet works correctly.

Hope this clarifies your doubt,

Farouk

1 Like

Thanks, Farouk.

I had to do a lot of experimenting, but your example was enough to get me started. I originally had these measurments in a long TextDot object. That was messy looking, unintuitive and could get in the way during zooms. The dimensions are much better.