-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSelect.cs
66 lines (56 loc) · 1.89 KB
/
Select.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
54
55
56
57
58
59
60
61
62
63
64
65
66
using System;
using System.Collections.Generic;
#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 Select
{
public static List<Datas> Lines()
{
List<Datas> list = new List<Datas>();
Document doc = Application.DocumentManager.MdiActiveDocument;
Database acadDb = doc.Database;
Editor ed = doc.Editor;
TypedValue[] filterlist = new TypedValue[1];
filterlist[0] = new TypedValue(0, "LINE");
SelectionFilter filter = new SelectionFilter(filterlist);
PromptSelectionResult psr = ed.SelectAll(filter);
SelectionSet sset = null;
//Entity ent = null;
Line line = null;
if (psr.Status == PromptStatus.OK)
{
sset = psr.Value;
}
using (Transaction tr = acadDb.TransactionManager.StartTransaction())
{
if (sset != null)
{
for (int i = 0; i < sset.Count; i++)
{
try
{
line = tr.GetObject(sset[i].ObjectId, OpenMode.ForWrite) as Line;
if (line != null)
{
list.Add(new Datas { Position = line.StartPoint, Content = line.Layer });
}
}
catch (System.Exception ex)
{
ed.WriteMessage("\nËrror: " + ex);
}
}
}
tr.Commit();
return list;
}
}
}
}