Cannot modify the arrow style of the Leader object

I can’t modify the arrow type of the Leader object in code, can anyone tell me why, I’m using Rhinoceros version 7, here’s the code snippet:

        Point3d point1 = startPoint;
        Point3d point2 = startPoint + new Point3d(500, 500, 500);
        Point3d point3 = point2 + new Point3d(500, 0, 0);
        DimensionStyle dimStyle = new DimensionStyle();
        dimStyle.LeaderArrowType = DimensionStyle.ArrowType.Dot;

        doc.DimStyles.Add(dimStyle, true);

        Point3d[] points = { point1, point2, point3 };
        Leader leader = Leader.Create("Label", Plane.WorldXY, dimStyle, points);
        doc.Objects.AddLeader(leader);
        doc.Views.Redraw();

Hi @wang_bi, below Python code seems to work for me in V7:

import Rhino
import scriptcontext
import rhinoscriptsyntax as rs

def DoSomething():
    
    obj_id = rs.GetObject("Select leader", rs.filter.annotation, True, False)
    if not obj_id: return
    
    leader_obj = rs.coercerhinoobject(obj_id, True, True)
    if not isinstance(leader_obj, Rhino.DocObjects.LeaderObject): return
    
    leader_obj.Geometry.LeaderArrowType = Rhino.DocObjects.DimensionStyle.ArrowType.Dot
    leader_obj.CommitChanges()
    
    scriptcontext.doc.Views.Redraw()
    
DoSomething()

_
c.

Leader Object has no CommitChanges method in C#

Hi @wang_bi,

not sure about C# but LeaderObject inherits Rhino.DocObjects.RhinoObject which does have CommitChanges. Did you import that ?

_
c.

Can I only modify it via LeaderObject, can’t I just specify the arrow type when I create the Leader?

Normally yes but you add a dimension style whenever you do this in your code:

doc.DimStyles.Add(dimStyle, true);

Check if your leader has the correct dimension style after you added it to the document. I made a quick test and found that in my case, using a code similar to yours, it used the Default dim style and not the one which was added.

To circumvent that, i’ve got the index returned from DimStyles.Add and then got the ds which i’ve used to create the leader. Funny about this is, if you call dim_style.IsValid before adding it to the DimStyles table, it returns False. But if you call ds.IsValid after adding it to the table, it returns True :roll_eyes:

It looks like this in python:

import Rhino
import scriptcontext
import System

def DoSomething():
    
    dim_style = Rhino.DocObjects.DimensionStyle()
    dim_style.LeaderArrowType = Rhino.DocObjects.DimensionStyle.ArrowType.Dot
    
    # get index and dim style by index 
    index = scriptcontext.doc.DimStyles.Add(dim_style, True)
    ds = scriptcontext.doc.DimStyles[index]
    
    plane = Rhino.Geometry.Plane.WorldXY
    pts = System.Array.CreateInstance(Rhino.Geometry.Point3d, 3)
    pts[0] = Rhino.Geometry.Point3d(0,0,0)
    pts[1] = Rhino.Geometry.Point3d(10,10,0)
    pts[2] = Rhino.Geometry.Point3d(20,10,0)
    leader = Rhino.Geometry.Leader.Create("Hello", plane, ds, pts)
    scriptcontext.doc.Objects.AddLeader(leader)
    scriptcontext.doc.Views.Redraw()

DoSomething()

Seems to work but my first example does not require to create a new dim style. Above creates one on every run. Are you sure you want this ?
_
c.

Do you know how to set ”Underlined“ property for Leader object? I set it up like the following code, but it doesn’t work

        DimensionStyle style = new DimensionStyle
        {
            LeaderArrowType = DimensionStyle.ArrowType.None,
            TextHeight = 15,
            TextUnderlined = true,
        };
        int index = doc.DimStyles.Add(style, true);
        DimensionStyle dsInDoc = doc.DimStyles[index];
        Plane plane = Plane.WorldXY;
        Point3d[] points = { pt1, pt2, pt3 , pt4};
        Leader leader = Leader.Create(point.Y.ToString("F2"), plane, dsInDoc, points);

Hi @wang_bi, you’ll might want to set:

dim_style.LeaderTextVerticalAlignment = Rhino.DocObjects.TextVerticalAlignment.BottomOfBoundingBox

https://developer.rhino3d.com/api/rhinocommon/rhino.docobjects.dimensionstyle/leadertextverticalalignment
_
c.