Displaypipeline drawleader?

I was wondering how I can preview the position of the elevation and the value of the elevation when I create custom elevation symbols in succession (I used the method leader.create to create the custom elevation symbols), I tried to use the method in displaypipeline, but I can only find DrawInstanceDefinition, using this method does not Doesn’t show the elevation perfectly (it only shows the instance definition, no value)Is there a similar method for drawleader that allows me to preview the leader graphic I’m creating?

This is my code

        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            leftDefinition = doc.InstanceDefinitions.Find("LeftElevationSymbol");            
            if (leftDefinition == null)
            {
                var line1 = new LineCurve(new Point3d(-1, -1, 0), new Point3d(0, 0, 0));
                var line2 = new LineCurve(new Point3d(0, 0, 0), new Point3d(-2, 0, 0));
                var line3 = new LineCurve(new Point3d(-2, 0, 0), new Point3d(-1, -1, 0));
                var line4 = new LineCurve(new Point3d(-1, -1, 0), new Point3d(4, -1, 0));


                var geolist = new List<GeometryBase>()
                {
                    line1, line2, line3, line4
                };


                var leftindex = doc.InstanceDefinitions.Add("LeftElevationSymbol", "", new Point3d(0, 0, 0), geolist);
                leftid = doc.InstanceDefinitions[leftindex].Id;
                leftDefinition = doc.InstanceDefinitions[leftindex];

            }
            else 
            {
                leftid = leftDefinition.Id;

                    
            }
          
            dimstyle =  doc.DimStyles.FindName("Dim01");
            int dimstyleindex;

            if(dimstyle == null )
            {
                dimstyle = new DimensionStyle();
                dimstyle.Name = "Dim01";
                dimstyle.LeaderArrowBlockId = leftid;
                dimstyle.LeaderArrowType = DimensionStyle.ArrowType.UserBlock;
                dimstyle.ArrowType1 = DimensionStyle.ArrowType.UserBlock;
                dimstyle.ArrowType2 = DimensionStyle.ArrowType.UserBlock;
                dimstyle.TextUnderlined = true;
                dimstyle.DimTextLocation = DimensionStyle.TextLocation.InDimLine;

                dimstyle.LeaderArrowLength = 50;
                dimstyle.ArrowBlockId1 = leftid;
                dimstyle.ArrowBlockId2 = leftid;
                dimstyle.TextHeight = 50;               
                dimstyle.LeaderTextVerticalAlignment = TextVerticalAlignment.BottomOfBoundingBox;
                dimstyleindex = doc.DimStyles.Add(dimstyle, false);
                dimstyle = doc.DimStyles[dimstyleindex];
            }
            else
            {
                dimstyleindex = dimstyle.Index;
            }          
            Point3d starpt;
            var rc= RhinoGet.GetPoint("start of line",false,out starpt);
            if (rc != Result.Success)
            {
                return rc;
            }
            Point3d midpt = new Point3d(starpt.X, starpt.Y + dimstyle.LeaderArrowLength, 0);
            GetPoint pt2 = new GetPoint();
            pt2.SetBasePoint(midpt, true);
            pt2.SetCommandPrompt("end of line");
            pt2.DrawLineFromPoint(midpt, true);
            ModelAidSettings.Ortho = true;
            pt2.DynamicDraw += new EventHandler<GetPointDrawEventArgs>(gp_DynamicDraw);
            pt2.Get();
            if(pt2.CommandResult()!= Result.Success)
            {
                return pt2.CommandResult(); 
            }
            Point3d endpt = pt2.Point();
            Point3d[] pts = { midpt, endpt };
            doc.DimStyles.SetCurrent(dimstyleindex, true);
            myleader = Leader.Create("±0.000", Plane.WorldXY, dimstyle, pts);           
            doc.Objects.AddLeader(myleader);
            for(; ; )
            {
                GetPoint pt = new GetPoint();
                pt.SetBasePoint(midpt, true);
                pt.SetCommandPrompt("end of line");
                pt.DrawLineFromPoint(midpt, true);
                ModelAidSettings.Ortho = true;
                pt.DynamicDraw += new EventHandler<GetPointDrawEventArgs>(gp_DynamicDraw);
                pt.Get();
                if (pt.CommandResult() != Result.Success)
                {
                    return pt.CommandResult();
                }
                Point3d endpoint = new Point3d(endpt.X,pt.Point().Y,0);
                Point3d middlepoint = new Point3d(midpt.X, pt.Point().Y , 0);
                Point3d[] ptlist = { middlepoint, endpoint };
                myleader = Leader.Create((pt.Point().Y-starpt.Z).ToString(), Plane.WorldXY, dimstyle, ptlist);
                doc.Objects.AddLeader(myleader);
            }

            doc.Views.Redraw();
            ModelAidSettings.Ortho = false;
            return Result.Success;
        }

        void gp_DynamicDraw(object sender, GetPointDrawEventArgs e)
        {
            Point3d basePt;
            if (e.Source.TryGetBasePoint(out basePt))
            {
                // Format distance as string
                double distance = basePt.DistanceTo(e.CurrentPoint);
                string text = string.Format("{0:0.000}", distance);

                // Get world-to-screen coordinate transformation
                Transform xform = e.Viewport.GetTransform(Rhino.DocObjects.CoordinateSystem.World, Rhino.DocObjects.CoordinateSystem.Screen);


                Point3d screenPt = xform * e.CurrentPoint;
                screenPt.X += 20.0;
                screenPt.Y -= 20.0;

                e.Display.Draw2dText(text, Color.Black, new Point2d(screenPt.X, screenPt.Y), false, (int)dimstyle.TextHeight, dimstyle.Font.FaceName);
                
                var scale = Transform.Scale(new Point3d(0, 0, 0), dimstyle.LeaderArrowLength);
                var translation = Transform.Translation(basePt - new Point3d(0, 0, 0));
                
                e.Display.DrawInstanceDefinition(leftDefinition,translation*scale);


            }
        }

Try this
https://developer.rhino3d.com/api/rhinocommon/rhino.display.displaypipeline/drawannotation

Sorry I haven’t learned rhinocommon for a long time, so I’m not sure how a class like AnnotationBase is used, can you give me some examples for reference? (I tried to create an instance of AnnotationBase by using new but it fails, also I want to know how can I find the leader from AnnotationBase)

Leader class inherits from AnnotationBase class and if I understood you correctly, you have a Leader instance that you would like to draw; so you can pass the instance of the Leader into the DrawAnnotation() method.

Okay, I’ll give it a try. Thank you for your answer!