-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcFile.cs
102 lines (85 loc) · 2.54 KB
/
cFile.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
namespace cdLAYER
{
public class cFile
{
public List<string> Filenames
{
get { return _Filenames; }
set { _Filenames = value; }
}
public string Filename
{
get
{
return _Filename;
}
set
{
_Filename = value;
}
}
public List<LayerItem> List
{
get
{
return _List;
}
set
{
_List = value;
}
}
private List<string> _Filenames;
private string _Filename;
public void Add()
{
System.Windows.Forms.OpenFileDialog _dialog;
_dialog = new System.Windows.Forms.OpenFileDialog();
_dialog.Multiselect = false;
_dialog.InitialDirectory = "C:/";
_dialog.Title = "Select Autocad dwg ritdef file";
_dialog.Filter = "dwg file | *.dwg";
_dialog.FilterIndex = 2;
_dialog.RestoreDirectory = true;
_Filenames = new List<string>();
if (_dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
_Filename = _dialog.FileName;
}
}
private List<LayerItem> _List;
public bool Read(string filename)
{
Database workingDB = HostApplicationServices.WorkingDatabase;
Database db = new Database(false, true);
try
{
db.ReadDwgFile(filename, System.IO.FileShare.ReadWrite, false, "");
db.CloseInput(true);
HostApplicationServices.WorkingDatabase = db;
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show("\nUnable to open .dwg file : " + ex.StackTrace);
return false;
}
Transaction tr = db.TransactionManager.StartTransaction();
using (tr)
{
_List = cLayer.ReadLayers(db);
HostApplicationServices.WorkingDatabase = workingDB;
db.SaveAs(filename, DwgVersion.Current);
return true;
}
}
}
}