Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 5938

LinearDimension prints sideways in WorldZX plane

$
0
0

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):

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 5938

Trending Articles