コード例 #1
0
ファイル: XyLeader.cs プロジェクト: Alain72/AgwXyLeader
        private bool DrawLeader(ObjectId mLeaderStyleId, IList <Point3d> pnt)
        {
            var leader = new MLeader()
            {
                MLeaderStyle = mLeaderStyleId,
                Layer        = "0",
            };

            using (Active.Document.LockDocument())
                using (Transaction tr = Active.Database.TransactionManager.StartTransaction())
                {
                    try
                    {
                        var idx       = leader.AddLeaderLine(pnt[0]);
                        var direction = 1.0;
                        if ((pnt[0] - pnt[1]).DotProduct(Vector3d.XAxis) < 0)
                        {
                            direction = -1;
                        }

                        leader.SetDogleg(idx, Vector3d.XAxis.MultiplyBy(direction));

                        var text = "{X= " + Decimal.Round((decimal)pnt[0].X, 2) + "}" +
                                   "\\P{Y= " + Decimal.Round((decimal)pnt[0].Y, 2) + "}";

                        pnt.RemoveAt(0);

                        foreach (Point3d pt in pnt)
                        {
                            leader.AddFirstVertex(idx, pt);
                        }

                        MText mText = new MText();
                        mText.SetDatabaseDefaults();

                        mText.Annotative       = AnnotativeStates.True;
                        mText.Contents         = text;
                        mText.Attachment       = (direction < 0) ? AttachmentPoint.MiddleRight : AttachmentPoint.MiddleLeft;
                        leader.MText           = mText;
                        leader.TextHeight      = 1.75;
                        leader.EnableFrameText = true;

                        Active.Database.AddEntities(leader);
                        tr.Commit();
                        return(true);
                    }
                    catch (System.Exception e)
                    {
                        Console.WriteLine(e);
                        return(false);
                    }
                }
        }