forked from DomCR/ACadSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDocumentExamples.cs
71 lines (61 loc) · 1.87 KB
/
DocumentExamples.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
67
68
69
70
71
using ACadSharp.Entities;
using ACadSharp.IO.DWG;
using ACadSharp.Tables;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ACadSharp.Examples
{
public static class DocumentExamples
{
/// <summary>
/// Get all the entities in the model
/// </summary>
/// <param name="file"></param>
/// <returns></returns>
public static IEnumerable<Entity> GetAllEntitiesInModel(string file)
{
CadDocument doc = DwgReader.Read(file);
// Get the model space where all the drawing entities are
BlockRecord modelSpace = doc.BlockRecords["*Model_Space"];
// Get all the entities in the model space
return modelSpace.Entities;
}
/// <summary>
/// Get all the blocks in the model
/// </summary>
/// <param name="file"></param>
/// <param name="blockname"></param>
/// <returns></returns>
public static IEnumerable<Insert> GetInsertEntities(string file, string blockname)
{
CadDocument doc = DwgReader.Read(file);
// Get the model space where all the drawing entities are
BlockRecord modelSpace = doc.BlockRecords["*Model_Space"];
// Get the insert instance that is using the block that you are looking for
return modelSpace.Entities.OfType<Insert>().Where(e => e.Block.Name == blockname);
}
/// <summary>
/// Example on how to create entities and add them into the drawing
/// </summary>
public static void CreateEntities()
{
//Create a new document
CadDocument doc = new CadDocument();
//Create a point located in (10, 10, 0)
Point pt = new Point
{
Location = new CSMath.XYZ(10, 10, 0)
};
//Create a line from the origin to the point (5, 5, 0)
Line line = new Line
{
StartPoint = CSMath.XYZ.Zero,
EndPoint = new CSMath.XYZ(5, 5, 0)
};
doc.BlockRecords["*Model_Space"].Entities.Add(pt);
doc.BlockRecords["*Model_Space"].Entities.Add(line);
}
}
}