Author Topic: .NET DIMENSION, LEADER Routines  (Read 19658 times)

0 Members and 1 Guest are viewing this topic.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
.NET DIMENSION, LEADER Routines
« on: January 27, 2010, 03:09:33 AM »
LIBRARY THREAD for  AutoCAD DIMENSIONS, LEADERS
 Members are encouraged to post any functions, methods, snips regarding
AutoCAD DIMENSIONS, LEADERS in .NET : C# ,  VB , F# , Python , etc

Feel free to include comments, descriptive notes, limitations,  and images to document your post.

Please post questions in a regular thread.
« Last Edit: January 27, 2010, 03:12:53 AM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

fixo

  • Guest
Autodimensioning polyline
« Reply #1 on: May 02, 2010, 03:11:18 AM »
Feel free to change to your needs
Code - C#: [Select]
  1.  
  2.         [CommandMethod("DIMP")]
  3.         public static void DimPline()
  4.         {
  5.             Document doc = acadApp.DocumentManager.MdiActiveDocument;
  6.  
  7.             Editor ed = doc.Editor;
  8.  
  9.             Database db = doc.Database;
  10.  
  11.             Transaction tr = db.TransactionManager.StartTransaction();
  12.  
  13.             using (tr)
  14.             {
  15.                 try
  16.                 {
  17.                     PromptEntityOptions peo = new PromptEntityOptions("\nSelect a polyline:");
  18.                     PromptEntityResult eres = ed.GetEntity(peo);
  19.  
  20.                     if (eres.Status != PromptStatus.OK) return;
  21.  
  22.                     ObjectId id = eres.ObjectId;
  23.  
  24.                     Entity ent = (Entity)tr.GetObject(id, OpenMode.ForRead);
  25.  
  26.                     Polyline pl = (Polyline)ent as Polyline;
  27.  
  28.                     BlockTableRecord btr =
  29.                         (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
  30.                     double sign;
  31.  
  32.                     if (IsCCW(pl) == true)
  33.                     {
  34.                         sign = -1;
  35.                     }
  36.                     else
  37.                     {
  38.                         sign = 1;
  39.                     }
  40.  
  41.                     Plane plan = pl.GetPlane();
  42.  
  43.                     double gap = (double)acadApp.GetSystemVariable("DIMTXT");// change to suit, may be hard value instead
  44.                     for (int i = 0; i < pl.NumberOfVertices; i++)
  45.                     {
  46.                         switch (pl.GetSegmentType(i))
  47.                         {
  48.                             case SegmentType.Line:
  49.  
  50.                                 LineSegment3d seg = pl.GetLineSegmentAt(i);
  51.  
  52.                                 Vector3d vec = seg.Direction;
  53.  
  54.                                 double ang = vec.AngleOnPlane(plan);
  55.  
  56.                                 Point3d p1 = seg.StartPoint;
  57.  
  58.                                 Point3d p2 = seg.EndPoint;
  59.  
  60.                                 Point3d p3 = seg.MidPoint;
  61.  
  62.                                 p3 = PolarPoint(p3, ang + Math.PI / 2 * sign, gap * 6);// gap * 6 - is offset distance from polyline,change to suit
  63.  
  64.                                 RotatedDimension dimr = new RotatedDimension();
  65.  
  66.                                 dimr.SetDatabaseDefaults();
  67.  
  68.                                 dimr.XLine1Point = p1;
  69.  
  70.                                 dimr.XLine2Point = p2;
  71.  
  72.                                 dimr.Rotation = ang;
  73.  
  74.                                 dimr.DimLinePoint = p3;
  75.  
  76.                                 dimr.DimensionStyle = db.Dimstyle;
  77.  
  78.                                 dimr.TextRotation = ang;
  79.  
  80.                                 btr.AppendEntity(dimr);
  81.  
  82.                                 tr.AddNewlyCreatedDBObject(dimr, true);
  83.  
  84.                                 break;
  85.  
  86.                             case SegmentType.Arc:
  87.  
  88.                                 CircularArc3d circ = pl.GetArcSegmentAt(i);
  89.  
  90.                                 Point3d cp = circ.Center;
  91.  
  92.                                 Point3d mp = circ.EvaluatePoint(0.5);
  93.  
  94.                                 double rad = circ.Radius;
  95.  
  96.                                 Point3d sp = circ.StartPoint;
  97.  
  98.                                 Point3d ep = circ.EndPoint;
  99.  
  100.                                 Point3d tp = PolarPoint(cp, AngleFromX(cp, mp), rad + gap * 6);// gap * 6 - is offset distance from polyline
  101.                                 // (center, start,end, text point)
  102.                                 ArcDimension adim = new ArcDimension(
  103.                                     cp, sp, ep, tp, "<>", db.Dimstyle);
  104.  
  105.                                 if (sign < 0)
  106.                                 {
  107.                                     adim.TextRotation = AngleFromX(sp, ep);
  108.                                 }
  109.                                 else
  110.                                 {
  111.                                     adim.TextRotation = AngleFromX(sp, ep)+ Math.PI;
  112.                                 }
  113.                                 btr.AppendEntity(adim);
  114.  
  115.                                 tr.AddNewlyCreatedDBObject(adim, true);
  116.  
  117.                                 break;
  118.  
  119.                             default:
  120.  
  121.                                 break;
  122.                         }
  123.  
  124.                     }
  125.  
  126.  
  127.                     tr.Commit();
  128.                 }
  129.                 catch (Autodesk.AutoCAD.Runtime.Exception ex)
  130.                 {
  131.                     ed.WriteMessage(ex.Message + "\n" + ex.StackTrace);
  132.  
  133.                 }
  134.             }
  135.         }
  136.  
  137.         /// by Herbert Putz
  138.         /// Methode GetAreaDMD( Polyline oPoly)
  139.         /// Berechnet die Fläche eines geschlossenen  Polygons nach der
  140.         /// DoubleMeridianDistance-Methode
  141.         /// (-(x1*y2)-(x2*y3)-...(xn*y1)+(y1*x2)+(y2*x3)+...(yn*x1))/2
  142.         ///
  143.         ///
  144.         /// oPoly ist eine AutoCAD-Polylinie
  145.         ///
  146.         ///
  147.         /// Flächenwert als Double
  148.         /// nArea > 0 --> Fläche im Uhrzeigersinn  gezeichnet
  149.         /// nArea Fläche gegen den Urzeigersinn gezeichnet
  150.         ///
  151.  
  152.         public static double GetAreaDMD(Polyline oPoly)
  153.         {
  154.             int nPoints;
  155.             double nArea;
  156.             nPoints = oPoly.NumberOfVertices - 1; // -1 weil  Nullbasiert
  157.             nArea = 0.00;
  158.  
  159.             for (int i = 0; i < nPoints; i++)
  160.             {
  161.                 nArea -=
  162.                 (oPoly.GetPoint2dAt(i).X * oPoly.GetPoint2dAt(i + 1).Y);
  163.                 nArea +=
  164.                 (oPoly.GetPoint2dAt(i).Y * oPoly.GetPoint2dAt(i + 1).X);
  165.             } // for ...
  166.             nArea -=
  167.             (oPoly.GetPoint2dAt(nPoints).X * oPoly.GetPoint2dAt(0).Y);
  168.             nArea +=
  169.             (oPoly.GetPoint2dAt(nPoints).Y * oPoly.GetPoint2dAt(0).X);
  170.  
  171.             return nArea / 2;
  172.         } // GetAreaDMD()
  173.  
  174.  
  175.         /// <summary>
  176.         ///  check if polyline direction is counterclockwise
  177.         /// </summary>
  178.         /// <param name="pline"></param>
  179.         /// <returns></returns>
  180.         public static bool IsCCW(Polyline pline)
  181.         {
  182.             double area = GetAreaDMD(pline);
  183.             if (area > 0)
  184.             {
  185.                 return false;
  186.             }
  187.             else
  188.             {
  189.                 return true;
  190.             }
  191.         }
  192.         /// Polar point // credit to Tony Tanzillo
  193.         /// </summary>
  194.         /// <param name="basepoint"></param>
  195.         /// <param name="angle"></param>
  196.         /// <param name="distance"></param>
  197.         /// <returns></returns>
  198.         public static Point3d PolarPoint(Point3d basepoint, double angle, double distance)
  199.         {
  200.             return new Point3d(
  201.             basepoint.X + (distance * Math.Cos(angle)),
  202.             basepoint.Y + (distance * Math.Sin(angle)),
  203.             basepoint.Z);
  204.         }
  205.  
  206.         public static double AngleFromX(Point3d pt1, Point3d pt2)
  207.         {
  208.             Plane ucsplane = new Plane(new Point3d(0, 0, 0), new Vector3d(0, 0, 1));
  209.  
  210.             Vector3d vec = pt2 - pt1;
  211.  
  212.             double ang = vec.AngleOnPlane(ucsplane);
  213.  
  214.             return ang;
  215.         }

~'J'~

edit:kdub - [code = csharp]
« Last Edit: September 05, 2023, 04:02:39 PM by kdub_nz »

sinc

  • Guest
Re: .NET DIMENSION, LEADER Routines
« Reply #2 on: May 02, 2010, 10:59:43 AM »
It looks like we're still missing access to the MLeader.Scale property in 2011.

I've been using this, which adds GetScale() and SetScale() extension methods to the MLeader class, and seems to be working for both 32-bit and 64-bit:

Code - C#: [Select]
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using Autodesk.AutoCAD.DatabaseServices;
  4. using Autodesk.AutoCAD.Runtime;
  5.  
  6. namespace Quux.AcadUtilities.Extensions
  7. {
  8.     public static class MLeaderExtensions
  9.     {
  10.         ///*********************************************************************************************************
  11.         ///*********************************************************************************************************
  12.         /// There is no access to the MLeader "scale" methods in the managed API,
  13.         /// so we need to use a PInvoke to call the ObjectARX method.
  14.         ///*********************************************************************************************************
  15.         private static class AcDbMLeader
  16.         {
  17.             [System.Security.SuppressUnmanagedCodeSecurity]
  18.  
  19.             [DllImport(GlobalAcad.AcDbDllName, CallingConvention = CallingConvention.ThisCall, CharSet = CharSet.Unicode,
  20.                EntryPoint = "?scale@AcDbMLeader@@QBENXZ")]
  21.             public static extern double scale(IntPtr mleader);
  22.  
  23.             [DllImport(GlobalAcad.AcDbDllName, CallingConvention = CallingConvention.ThisCall, CharSet = CharSet.Unicode,
  24.                EntryPoint = "?setScale@AcDbMLeader@@QAE?AW4ErrorStatus@Acad@@N@Z")]
  25.             public static extern ErrorStatus setScale(IntPtr mleader, double scale);
  26.         }
  27.  
  28.         private static class AcDbMLeader64
  29.         {
  30.             [System.Security.SuppressUnmanagedCodeSecurity]
  31.  
  32.             [DllImport(GlobalAcad.AcDbDllName, CallingConvention = CallingConvention.ThisCall, CharSet = CharSet.Unicode,
  33.                EntryPoint = "?scale@AcDbMLeader@@QEBANXZ")]
  34.             public static extern double scale(IntPtr mleader);
  35.  
  36.             [DllImport(GlobalAcad.AcDbDllName, CallingConvention = CallingConvention.ThisCall, CharSet = CharSet.Unicode,
  37.                EntryPoint = "?setScale@AcDbMLeader@@QEAA?AW4ErrorStatus@Acad@@N@Z")]
  38.             public static extern ErrorStatus setScale(IntPtr mleader, double scale);
  39.         }
  40.  
  41.         public static double GetScale(this MLeader mldr)
  42.         {
  43.             return (IntPtr.Size > 4) ?
  44.                 AcDbMLeader64.scale(mldr.UnmanagedObject) : AcDbMLeader.scale(mldr.UnmanagedObject);
  45.         }
  46.  
  47.         public static void SetScale(this MLeader mldr, double scale)
  48.         {
  49.             if (IntPtr.Size > 4)
  50.                 AcDbMLeader64.setScale(mldr.UnmanagedObject, scale);
  51.             else
  52.                 AcDbMLeader.setScale(mldr.UnmanagedObject, scale);
  53.         }
  54.         ///*********************************************************************************************************
  55.         ///*********************************************************************************************************
  56.     }
  57. }
  58.  

When I needed to get it working for 64-bit, that was the first way I discovered to do it.  I'm open to other options.


edit:kdub - [ code = csharp ]
« Last Edit: April 01, 2012, 12:20:03 AM by Kerry »

Jeff H

  • Needs a day job
  • Posts: 6144
Re: .NET DIMENSION, LEADER Routines
« Reply #3 on: November 16, 2010, 09:28:45 AM »
It looks like we're still missing access to the MLeader.Scale property in 2011.

This seems to work setting the MleaderStyle scale property if that works for you

Code - C#: [Select]
  1.                         MLeader mLdr = new MLeader();
  2.                         mLdr.MLeaderStyle = mLdrDict.GetAt("KeyNoteLeader");
  3.                         ObjectId dbentry = mLdrDict.GetAt("KeyNoteLeader");
  4.                         MLeaderStyle mlStyle = dbentry.GetObject(OpenMode.ForWrite) as MLeaderStyle;
  5.                         mlStyle.Scale = 20;
  6.  

edit:kdub - [ code = csharp ]
« Last Edit: April 01, 2012, 12:20:59 AM by Kerry »

sinc

  • Guest
Re: .NET DIMENSION, LEADER Routines
« Reply #4 on: November 16, 2010, 02:19:01 PM »
No, I wasn't trying to change the scale of the Style, but the scale of the individual MLeader.

Jeff H

  • Needs a day job
  • Posts: 6144
Re: .NET DIMENSION, LEADER Routines
« Reply #5 on: September 15, 2011, 10:54:01 AM »
A question asked somewhere else but thought this would be good place to put
 
Changing all dimstyle of dimensions,
Just set Dimension.DimensionStyle to the ObjectId of the style you want or
set Dimension.DimensionStyleName to the name of string.
 
 
I used GetPersistentReactorIds to get the dimensions instead of a selection filter or iterating model space---just out of boredom
VB and C#
 
 
Code - C#: [Select]
  1.  [CommandMethod("ChangeDimStlye")]
  2.  public void ChangeDimStlye()
  3.  {
  4.      Document doc = Application.DocumentManager.MdiActiveDocument;
  5.      Database db = doc.Database;
  6.      Editor ed = doc.Editor;
  7.      using (Transaction trx = db.TransactionManager.StartTransaction())
  8.      {
  9.          DimStyleTable dimTbl = (DimStyleTable)trx.GetObject(db.DimStyleTableId, OpenMode.ForRead);
  10.          DimStyleTableRecord dimDtr = (DimStyleTableRecord)trx.GetObject(dimTbl["DimStyle1"], OpenMode.ForRead);
  11.          ObjectIdCollection ids = dimDtr.GetPersistentReactorIds();
  12.          foreach (ObjectId id in ids)
  13.          {
  14.              if (id.ObjectClass.IsDerivedFrom(RXClass.GetClass(typeof(Dimension))))
  15.              {
  16.                  Dimension dim = (Dimension)trx.GetObject(id, OpenMode.ForWrite);
  17.                  dim.DimensionStyle = dimTbl["DimStyle2"];
  18.                  //dim.DimensionStyleName = "DimStyle2";
  19.              }
  20.          }
  21.          trx.Commit();
  22.      }
  23.  }
  24.  

Code - vb.net: [Select]
  1.  
  2.         <CommandMethod("ChangeDimStlye")> _
  3.         Public Sub ChangeDimStlye()
  4.             Dim doc As Document = Application.DocumentManager.MdiActiveDocument
  5.             Dim db As Database = doc.Database
  6.             Dim ed As Editor = doc.Editor
  7.             Using trx As Transaction = db.TransactionManager.StartTransaction()
  8.                 Dim dimTbl As DimStyleTable = trx.GetObject(db.DimStyleTableId, OpenMode.ForRead)
  9.                 Dim dimDtr As DimStyleTableRecord = trx.GetObject(dimTbl("DimStyle1"), OpenMode.ForRead)
  10.                 Dim ids As ObjectIdCollection = dimDtr.GetPersistentReactorIds()
  11.                 For Each objId As ObjectId In ids
  12.                     If objId.ObjectClass.IsDerivedFrom(RXClass.GetClass(GetType(Dimension))) Then
  13.                         Dim dimen As Dimension = trx.GetObject(objId, OpenMode.ForWrite)
  14.                         dimen.DimensionStyle = dimTbl("DimStyle2")
  15.                         ''''' or
  16.                         ''''''dimen.DimensionStyleName = "DimStyle2"
  17.                     End If
  18.                 Next
  19.                 trx.Commit()
  20.             End Using
  21.         End Sub
  22.  

edit:kdub - [ code = csharp ] and [ code = vbnet ]
« Last Edit: April 01, 2012, 12:22:01 AM by Kerry »

Jeff H

  • Needs a day job
  • Posts: 6144
Re: .NET DIMENSION, LEADER Routines
« Reply #6 on: November 03, 2011, 12:54:23 PM »
A questioned asked somewhere on textoverrides for dimensions and did this a while back but,
what I can remeber if it is not overridden  Dimension.DimensionText = "" or if it has a special character will contain "<>".
Anyways a small simple one that will make oveeriden dimension appear

 
VB & C#
Code - vb.net: [Select]
  1.         <CommandMethod("GetDimensionsOveriddenVB")> _
  2.         Public Sub GetDimensionsOveriddenVB()
  3.             Dim doc As Document = Application.DocumentManager.MdiActiveDocument
  4.             Dim db As Database = doc.Database
  5.             Dim ed As Editor = doc.Editor
  6.  
  7.             Using trx As Transaction = db.TransactionManager.StartTransaction()          
  8.  
  9.                 Dim bt As BlockTable = trx.GetObject(db.BlockTableId, OpenMode.ForRead)
  10.                 Dim modelSpace As BlockTableRecord = trx.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForRead)
  11.  
  12.                 For Each Id As ObjectId In modelSpace
  13.  
  14.                     If Id.ObjectClass.IsDerivedFrom(RXClass.GetClass(GetType(Dimension))) Then
  15.  
  16.                         Dim dimen As Dimension = trx.GetObject(Id, OpenMode.ForRead)
  17.                         If Not (dimen.DimensionText = "") OrElse (dimen.DimensionText.Contains("<>")) Then
  18.  
  19.                             dimen.UpgradeOpen()
  20.                             dimen.Dimclrt = Color.FromColorIndex(ColorMethod.ByAci, 2)
  21.                             dimen.Dimtfill = 2
  22.                             dimen.Dimtfillclr = Color.FromColorIndex(ColorMethod.ByAci, 1)
  23.  
  24.                         End If
  25.                     End If
  26.  
  27.                 Next
  28.  
  29.                 trx.Commit()
  30.  
  31.             End Using
  32.  
  33.         End Sub
  34.  

Code - C#: [Select]
  1.         [CommandMethod("GetDimensionsOveridden")]
  2.         public void GetDimensionsOveridden()
  3.         {
  4.             Document doc = Application.DocumentManager.MdiActiveDocument;
  5.             Database db = doc.Database;
  6.             Editor ed = doc.Editor;
  7.             using (Transaction trx = db.TransactionManager.StartTransaction())// Start Transaction
  8.             {
  9.                 BlockTable bt = (BlockTable)trx.GetObject(db.BlockTableId, OpenMode.ForRead);
  10.                 BlockTableRecord modelSpace = (BlockTableRecord)trx.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead);
  11.  
  12.                 foreach (ObjectId Id in modelSpace)
  13.                 {
  14.                     if (Id.ObjectClass.IsDerivedFrom(RXClass.GetClass(typeof(Dimension))))
  15.                     {
  16.                         Dimension dim = (Dimension)trx.GetObject(Id, OpenMode.ForRead);
  17.                         if (!(dim.DimensionText == "" || dim.DimensionText.Contains("<>")))
  18.                         {
  19.                             dim.UpgradeOpen();
  20.                             dim.Dimclrt = Autodesk.AutoCAD.Colors.Color.FromColorIndex(ColorMethod.ByAci, 2);
  21.                             dim.Dimtfill = 2;
  22.                             dim.Dimtfillclr = Autodesk.AutoCAD.Colors.Color.FromColorIndex(ColorMethod.ByAci, 1);
  23.                         }
  24.                     }
  25.                 }
  26.                 trx.Commit();
  27.             }
  28.         }
  29.  
  30.  

 
 edit:kdub - [ code = csharp ]
« Last Edit: April 01, 2012, 12:24:43 AM by Kerry »

Jeff H

  • Needs a day job
  • Posts: 6144
Re: .NET DIMENSION, LEADER Routines
« Reply #7 on: November 07, 2011, 04:44:14 PM »
This was handy and thrown together real quick and needs to be redone, but used to select existing text and change it into a multileader.
 
A drawing that looked like a bunch of multi-leaders were exploded and needed to be change back.
 
 
Code - C#: [Select]
  1.  [CommandMethod("TxtToMleader")]
  2.         public void TxtToMleader()
  3.         {
  4.             StringBuilder sb = new StringBuilder();        
  5.             ObjectIdCollection idsToDelete = new ObjectIdCollection();
  6.  
  7.             while (true)
  8.             {
  9.                 PromptEntityOptions peo = new PromptEntityOptions("\nAdd Text");
  10.                 peo.SetRejectMessage("\nThat is not a Text Object");
  11.                 peo.AddAllowedClass(typeof(DBText), true);
  12.                 peo.AddAllowedClass(typeof(MText), true);
  13.                 peo.AllowNone = true;
  14.                 PromptEntityResult per = Ed.GetEntity(peo);
  15.                 if (per.Status == PromptStatus.None)
  16.                 {
  17.                     break;
  18.                 }
  19.                 if (per.Status != PromptStatus.OK)
  20.                 {
  21.                     break;
  22.                 }
  23.                 using (Transaction trx = Db.TransactionManager.StartTransaction())
  24.                 {
  25.                     if (per.ObjectId.ObjectClass == (RXClass.GetClass(typeof(MText))))
  26.                     {
  27.                         MText txt = (MText)trx.GetObject(per.ObjectId, OpenMode.ForWrite);
  28.                         idsToDelete.Add(per.ObjectId);
  29.                         txt.Transparency = new Autodesk.AutoCAD.Colors.Transparency(75);
  30.                         sb.Append(txt.Text);
  31.                     }
  32.                     if (per.ObjectId.ObjectClass == (RXClass.GetClass(typeof(DBText))))
  33.                     {
  34.                         DBText txt = (DBText)trx.GetObject(per.ObjectId, OpenMode.ForWrite);
  35.                         idsToDelete.Add(per.ObjectId);
  36.                         txt.Transparency = new Autodesk.AutoCAD.Colors.Transparency(75);
  37.                         sb.Append(txt.TextString);
  38.                         sb.Append("\\P");
  39.                     }
  40.                     trx.Commit();
  41.                 }
  42.             }
  43.  
  44.  
  45.  
  46.             using (Transaction trx = Db.TransactionManager.StartTransaction())
  47.             {            
  48.                 BlockTableRecord btr = (BlockTableRecord)trx.GetObject(Db.CurrentSpaceId, OpenMode.ForRead);
  49.  
  50.                 MLeader ml = new MLeader();
  51.                 MLeaderStyle mlStyle = (MLeaderStyle)trx.GetObject(Db.MLeaderstyle, OpenMode.ForRead);
  52.                 Db.Textstyle = mlStyle.TextStyleId;
  53.                 ml.SetDatabaseDefaults();
  54.                 ml.MLeaderStyle = Db.MLeaderstyle;
  55.                 int leaderNumber = ml.AddLeader();
  56.  
  57.          
  58.                 Point3d startPoint;
  59.                 Point3d endPoint = Point3d.Origin;
  60.                 PromptPointResult ppr1 = Ed.GetPoint("\nSpecify leader arrowhead location");
  61.                 if (ppr1.Status != PromptStatus.OK)
  62.                 {
  63.                     return;
  64.                 }
  65.                 startPoint = ppr1.Value;
  66.                 int leaderLineNum = -1;
  67.                 bool firstTime = true;
  68.                 double direction = 1.0;
  69.                 while (true)
  70.                 {
  71.                     PromptPointOptions ppo = new PromptPointOptions("\nSpecify next Point");
  72.                     ppo.AllowNone = true;
  73.                     ppo.BasePoint = startPoint;
  74.                     ppo.UseBasePoint = true;
  75.                     PromptPointResult ppr2 = Ed.GetPoint(ppo);
  76.                     if (ppr2.Status == PromptStatus.None)
  77.                     {
  78.  
  79.                         break;
  80.                     }
  81.                     if (ppr2.Status != PromptStatus.OK)
  82.                     {
  83.                         return;
  84.                     }
  85.  
  86.                     endPoint = ppr2.Value;
  87.                     if (firstTime)
  88.                     {
  89.                         leaderLineNum = ml.AddLeaderLine(leaderNumber);
  90.                         ml.AddFirstVertex(leaderLineNum, startPoint);
  91.                         firstTime = false;
  92.                     }
  93.                     ml.AddLastVertex(leaderLineNum, endPoint);
  94.                     if ((endPoint - startPoint).DotProduct(Vector3d.XAxis) < 0.0)
  95.                     {
  96.                         direction = -1.0;
  97.                     }
  98.  
  99.                     startPoint = endPoint;
  100.                 }
  101.                
  102.                 ml.SetDogleg(leaderNumber, Vector3d.XAxis.MultiplyBy(direction));
  103.                 MText mt = new MText();
  104.                 mt.SetDatabaseDefaults();
  105.  
  106.                 mt.Contents = sb.ToString();
  107.                 ml.MText = mt;
  108.  
  109.                 btr.UpgradeOpen();
  110.                 btr.AppendEntity(ml);
  111.  
  112.                 trx.AddNewlyCreatedDBObject(ml, true);
  113.  
  114.                 ml.TextHeight = mlStyle.TextHeight;
  115.                 ml.MText.LineSpacingFactor = 0.8;
  116.                 if (direction > 0)
  117.                 {
  118.                     ml.TextAlignmentType = TextAlignmentType.LeftAlignment;
  119.                 }
  120.                 else
  121.                 {
  122.                     ml.TextAlignmentType = TextAlignmentType.RightAlignment;
  123.                 }
  124.                 foreach (ObjectId id in idsToDelete)
  125.                 {
  126.                     DBObject dbo = trx.GetObject(id, OpenMode.ForWrite);
  127.                     dbo.Erase();
  128.                 }
  129.                 trx.Commit();
  130.             }
  131.            
  132.         }
  133.  

edit:kdub - [ code = csharp ]
« Last Edit: April 01, 2012, 12:26:23 AM by Kerry »