Why does it behave like that?

To put dim text below dim line (a hidden/old option).

This works:

        dim = Rhino.Geometry.LinearDimension(plane, pt1, pt2, pt0)
        dim.Aligned = True
        dim = sc.doc.Objects.AddLinearDimension(dim)
        dim = Rhino.DocObjects.ObjRef(dim).Object()

        dim.Geometry.TextLocation = Rhino.DocObjects.DimensionStyle.TextLocation.BelowDimLine
        dim.CommitChanges()

This doesn’t:

        dim = Rhino.Geometry.LinearDimension(plane, pt1, pt2, pt0)
        dim.Aligned = True
        dim.TextLocation = Rhino.DocObjects.DimensionStyle.TextLocation.BelowDimLine
        dim = sc.doc.Objects.AddLinearDimension(dim)
        dim = Rhino.DocObjects.ObjRef(dim).Object()

Hi, is this a RhinoScript code?
Can you share a more complete code sample hat I can run at my end? Thanks.

import Rhino
import scriptcontext as sc

plane = Rhino.Geometry.Plane.WorldXY
pt1 = Rhino.Geometry.Point2d(0, 0)
pt2 = Rhino.Geometry.Point2d(10, 0)
pt0 = Rhino.Geometry.Point2d(0, 5)

#dim = Rhino.Geometry.LinearDimension(plane, pt1, pt2, pt0)
#dim.Aligned = True
#dim = sc.doc.Objects.AddLinearDimension(dim)
#dim = Rhino.DocObjects.ObjRef(dim).Object()
#
#dim.Geometry.TextLocation = Rhino.DocObjects.DimensionStyle.TextLocation.BelowDimLine
#dim.CommitChanges()

dim = Rhino.Geometry.LinearDimension(plane, pt1, pt2, pt0)
dim.Aligned = True
dim.TextLocation = Rhino.DocObjects.DimensionStyle.TextLocation.BelowDimLine
dim = sc.doc.Objects.AddLinearDimension(dim)
dim = Rhino.DocObjects.ObjRef(dim).Object()

I do see it.
Rhino.DocObjects.DimensionStyle.TextLocation.BelowDimLine

is basically ignored if set up during the creation of the dimension, and only takes effect if set afterwards. This is perhaps a bug and will investigate further.
Added a bug here…

1 Like

I know this is not intuitive but setting the TextLocation (or any other value that comes from the annotation style) attempts to override the annotation style TextLocation value but in this case no annotation style is associated with the dimension until you add the dimension to the document.

Instead of calling the LinearDimension constructor you can associate an annotation style with the dimension by creating the LinearDimension like this:

aligned = Rhino.Geometry.AnnotationType.Aligned
ds = sc.doc.DimStyles.Current
plane = Rhino.Geometry.Plane.WorldXY
v = Rhino.Geometry.Vector3d(0,5,0)
pt1 = Rhino.Geometry.Point3d(0,0,0)
pt2 = Rhino.Geometry.Point3d(10,0,0)
pt0 = Rhino.Geometry.Point3d(0,5,0)
dim = Rhino.Geometry.LinearDimension.Create(aligned, ds, plane, v, pt1, pt2, pt0, 0)
1 Like

Makes sense!

I’m having troubles with creating dims that aren’t strictly horizontal:

aligned = Rhino.Geometry.AnnotationType.Aligned
ds = sc.doc.DimStyles.Current
plane = Rhino.Geometry.Plane.WorldXY
v = Rhino.Geometry.Vector3d(-5,0,0)
pt1 = Rhino.Geometry.Point3d(0,0,0)
pt2 = Rhino.Geometry.Point3d(0,10,0)
pt0 = Rhino.Geometry.Point3d(-5,0,0)
dim = Rhino.Geometry.LinearDimension.Create(aligned, ds, plane, v, pt1, pt2, pt0, 0)

Hi,

I’m not sure exactly what kind of dimension you’re trying to create but the last argument of the Create function is the angle.

I figured it out:

pt2 should go before pt1, otherwise after manual dimension edit, it mirrors along the start - offset point line.

Rhino.Geometry.LinearDimension.Create(aligned, ds, plane, v, **pt2, pt1**, pt0, 0)

Is this how one would check if the angle should be positive or negative?

if v.Y < 0: angle = -angle