-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
211 lines (172 loc) · 8.75 KB
/
Program.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xbim;
using Xbim.IO;
using Xbim.Common;
using Xbim.Ifc;
using Xbim.Ifc2x3;
using Xbim.XbimExtensions;
using Xbim.Ifc2x3.Kernel;
using Xbim.Ifc2x3.MeasureResource;
using Xbim.ModelGeometry.Converter;
using Xbim.Ifc2x3.Extensions;
using Xbim.Ifc2x3.ProductExtension;
using Xbim.Ifc2x3.SharedBldgElements;
using Xbim.Ifc2x3.PropertyResource;
using Xbim.Ifc2x3.RepresentationResource;
namespace XBIMConsole
{
class Program
{
static void Main(string[] args)
{
using (XbimModel model = new XbimModel())
{
string ifcFile = "BCAA_-Function_Hall(Archi+Stru).ifc";
string ifcLongFile = @"C:\Users\yemaw\gelement\Xbim\XBIMConsole\" + ifcFile;
string xbimLongFile = System.IO.Path.ChangeExtension(ifcLongFile, "xbim");
model.CreateFrom(ifcLongFile, xbimLongFile);
model.Open(xbimLongFile, Xbim.XbimExtensions.XbimDBAccess.ReadWrite);
IfcProductsToJson p2j = new IfcProductsToJson();
p2j.writeProducts(model);
Console.WriteLine("----------------------------------------------------");
Console.ReadLine();
IfcProject project = model.IfcProject as IfcProject;
Console.WriteLine(project.Name + " " + project.LongName);
IEnumerable<IfcSite> sites = project.GetSites();
foreach (IfcSite site in sites)
{
Console.WriteLine("-" + site.Name);
IEnumerable<IfcBuilding> buildings = site.GetBuildings();
foreach (IfcBuilding building in buildings)
{
Console.WriteLine("--" + building.Name + "(" + building.BuildingAddress + ")");
IEnumerable<IfcBuildingStorey> levels = building.GetBuildingStoreys();
foreach (IfcBuildingStorey level in levels)
{
IEnumerable<IfcObjectDefinition> children_l = level.SpatialStructuralElementChildren;
IEnumerable<IfcRelDecomposes> decomp = level.IsDecomposedBy;
IEnumerable<IfcObjectDefinition> objs = decomp.SelectMany(s => s.RelatedObjects);
Console.WriteLine("---" + level.Name + "[Total children=" + children_l.Count()+",decomposed related="+objs.Count()+"]");
IEnumerable<IfcProduct> products_l = level.GetContainedElements();
string included_products_l = "";
foreach (IfcProduct product in products_l)
{
included_products_l += product.Name;
}
//--Console.WriteLine("products in level=>"+included_products_l);
//IfcShapeRepresentation axis = level.GetAxisRepresentation();
//IfcShapeRepresentation body = level.GetBodyRepresentation();
//IEnumerable<IfcWall> walls = model.Instances.OfType<IfcWall>();
/*
IEnumerable<IfcRelDefines> defines = level.IsDefinedBy;
foreach (IfcRelDefines define in defines) {
IfcObjectSet objects = define.RelatedObjects;
foreach(IfcObject o in objects){
Console.WriteLine(o.Name);
}
}
*/
/*
IEnumerable<IfcRelContainedInSpatialStructure> ss = level.ContainsElements;
foreach (IfcRelContainedInSpatialStructure s in ss) {
Console.WriteLine(s.Name);
}
*/
IEnumerable<IfcSpace> spaces = level.GetSpaces();
foreach (IfcSpace space in spaces)
{
IfcObjectDefinition parent_s = space.SpatialStructuralElementParent;
IEnumerable<IfcObjectDefinition> children_s = space.SpatialStructuralElementChildren;
Console.WriteLine("----" + space.Name + " " + space.LongName + "["
+ " parent name=" + parent_s.Name
//--+ ", parent type=" + parent_s.GetType()
+ ", net floor area=" + space.GetNetFloorArea()
+ "]");
/* Products in a space */
IEnumerable<IfcProduct> products_s = space.GetContainedElements();
string included_products_s = "";
foreach (IfcProduct product in products_s)
{
included_products_s += product.Name;
}
Console.WriteLine("products in space=>"+included_products_s);
List<IfcPropertySet> sets = space.GetAllPropertySets();
foreach (IfcPropertySet set in sets)
{
Console.WriteLine("----->" + set.Name);
foreach (IfcProperty prop in set.HasProperties)
{
Console.WriteLine("-------" + prop.Name + "="+space.GetPropertySingleValue(set.Name, prop.Name));
}
}
}
}
}
}
IEnumerable<IfcWall> walls = model.Instances.OfType<IfcWall>();
Console.WriteLine(walls.Count());
}
Console.WriteLine("----------------------------------------------------");
Console.ReadLine();
}
}
}
/*
//OBTER TODAS AS ENTIDA DES DO MODELO
//-IfcProject project = model.IfcProject as IfcProject;
//-IEnumerable<IfcProduct> products = model.IfcProducts.Cast<IfcProduct>();
//IEnumerable<IfcBuildingStorey>
var pisos = model.Instances.OfType<IfcBuildingStorey>();
foreach (var piso in pisos)
{
IEnumerable<IfcRelDecomposes> decomp = piso.IsDecomposedBy;
IEnumerable<IfcObjectDefinition> objs = decomp.SelectMany(s => s.RelatedObjects);
IEnumerable<IfcSpace> spaces = objs.OfType<IfcSpace>();
foreach (var space in spaces)
{
var area = space.GetGrossFloorArea();
//Console.WriteLine("Space: {0} Area: {1}\r\n", space.Name, area.Value);
}
}
model.Close();
*/
/*
if (File.Exists(filesName))
{
Console.WriteLine("file found");
using (XbimModel model = new XbimModel())
{
string xbimFile = Path.ChangeExtension(filesName, "xBIM");
if (Path.GetExtension(filesName).ToLower() == ".xbim")
{
xbimFile = filesName;
}
else
{
model.CreateFrom(filesName, xbimFile, delegate(int percentProgress, object userState)
{
Console.Write("\rReading File {0}", percentProgress);
}
);
}
model.Open(xbimFile, XbimDBAccess.ReadWrite);
//model.CreateFrom(filesName);
//model.Open(filesName+".xBIM", Xbim.XbimExtensions.XbimDBAccess.ReadWrite);
Console.WriteLine("");
Console.WriteLine(model.Instances.Count + " instances read");
using (Xbim.IO.XbimReadWriteTransaction txn = model.BeginTransaction())
{
var door = model.Instances.New<Xbim.Ifc2x3.SharedBldgElements.IfcDoor>();
door.Name = "New Door";
txn.Commit();
model.SaveAs("BIM Logo with Door", Xbim.XbimExtensions.Interfaces.XbimStorageType.IFC);
}
Console.WriteLine(model.DefaultOwningApplication.ApplicationIdentifier.ToString());
model.Close();
}
}
*/