forked from tazuddinleton/revit-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHousingList.cs
117 lines (98 loc) · 3.14 KB
/
HousingList.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
using System.Windows.Media.Imaging;
using Autodesk.Revit;
using Autodesk.Revit.DB;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.UI;
using Excel = Microsoft.Office.Interop.Excel;
namespace BIMAsistant
{
public class HousingList
{
public int Rows;
public int Cols;
private List<List<string>> Columns = new List<List<string>>();
private string FilePath = string.Empty;
private object missValue = System.Reflection.Missing.Value;
private Excel.Application XL;
private Excel.Workbook Book;
private Excel.Worksheet Sheet;
private Excel.Range Range;
private object[,] Values = null;
public HousingList(string FilePath)
{
this.FilePath = FilePath;
this.Read();
this.SetColumns();
this.SanitizeHousingNumber();
this.Release(this.Sheet);
this.Release(this.Book);
this.Release(this.XL);
}
private void Read()
{
try
{
this.XL = new Excel.Application();
this.Book = XL.Workbooks.Open(this.FilePath, 0, true, 5, "", "");
this.Sheet = (Excel.Worksheet)this.XL.Worksheets.get_Item(1);
this.Range = this.Sheet.UsedRange;
this.Values = (object[,])this.Range.Value2;
this.Rows = this.Values.GetLength(0);
this.Cols = this.Values.GetLength(1);
}
catch (Exception Error)
{
TaskDialog.Show("HousingList", "Unable to open Excel file " + Error.ToString());
}
}
private void SetColumns()
{
for(int i = 0; i < this.Cols; i++)
{
List<string> placeHolder = new List<string>();
for(int j = 0; j < this.Rows; j++)
{
placeHolder.Add(this.Values[j + 1, i + 1].ToString());
}
this.Columns.Add(placeHolder);
}
}
private void SanitizeHousingNumber()
{
List<string> col1 = this.Columns[0];
for(int i = 0; i < this.Rows; i++)
{
string[] words = col1[i].Split('-');
this.Columns[0][i] = words[2];
}
}
private void Release(object obj)
{
try
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
obj = null;
}
catch (Exception Error)
{
obj = null;
TaskDialog.Show("HousingList", "Unable to release the Object " + Error.ToString());
}
finally
{
GC.Collect();
}
}
public List<string> GetHousingNumber()
{
return this.Columns[0];
}
}
}