-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMleader.cs
53 lines (41 loc) · 1.61 KB
/
Mleader.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
#region Autodesk
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
#endregion
namespace AcadNet
{
class Mleader
{
public static void Create(Point3d flagPosition, string contents)
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
using (Transaction Tx = db.TransactionManager.StartTransaction())
{
BlockTable table = Tx.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord model = Tx.GetObject(table[BlockTableRecord.ModelSpace], OpenMode.ForWrite)
as BlockTableRecord;
MLeader leader = new MLeader();
leader.SetDatabaseDefaults();
leader.ContentType = ContentType.MTextContent;
MText mText = new MText();
mText.SetDatabaseDefaults();
//mText.Width = 100;
//mText.Height = 50;
mText.SetContentsRtf(contents);
mText.Location = new Point3d(flagPosition[0]+1, flagPosition[1] + 1, 0);
leader.MText = mText;
int idx = leader.AddLeaderLine(flagPosition);
leader.AddFirstVertex(idx, flagPosition);
model.AppendEntity(leader);
Tx.AddNewlyCreatedDBObject(leader, true);
Tx.Commit();
}
}
}
}