-
Notifications
You must be signed in to change notification settings - Fork 0
/
SetCurrentSpec.cs
280 lines (248 loc) · 10.7 KB
/
SetCurrentSpec.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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.UI;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.DB.Structure;
namespace WorkApp
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
class SetCurrentSpec : IExternalCommand
{
Result IExternalCommand.Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Application app = uiapp.Application;
Document doc = uidoc.Document;
PhaseArray xcom = doc.Phases;
Phase lastPhase = xcom.get_Item(xcom.Size - 1);
ElementId idPhase = lastPhase.Id;
FilterableValueProvider valueProvider = new ParameterValueProvider(new ElementId(BuiltInParameter.PHASE_CREATED));
FilterNumericRuleEvaluator evaluator = new FilterNumericEquals();
ElementId ruleValue = idPhase;
ElementParameterFilter stageFilter = new ElementParameterFilter(new FilterElementIdRule(valueProvider, evaluator, ruleValue));
List<List<Element>> collectFromModel = new List<List<Element>>();
collectFromModel.Add(new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_StructuralFraming)
.WhereElementIsNotElementType()
.WherePasses(stageFilter)
.Where(x => ((FamilyInstance)x).StructuralType.ToString() != "NonStructural")
.Cast<Element>()
.ToList());
//collectFromModel.Add(karkas);
collectFromModel.Add(new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_StructuralColumns)
.WhereElementIsNotElementType()
.WherePasses(stageFilter)
.Cast<Element>()
.ToList());
collectFromModel.Add(new FilteredElementCollector(doc).OfClass(typeof(Rebar))
.WherePasses(stageFilter)
.ToElements().ToList());
collectFromModel.Add(new FilteredElementCollector(doc).OfClass(typeof(RebarInSystem))
.WherePasses(stageFilter)
.ToElements().ToList());
collectFromModel.Add(new FilteredElementCollector(doc).OfClass(typeof(Railing))
.WhereElementIsNotElementType()
.WherePasses(stageFilter)
.ToElements()
.ToList());
collectFromModel.Add(new FilteredElementCollector(doc).OfClass(typeof(HostedSweep))
.WhereElementIsNotElementType()
.WherePasses(stageFilter)
.ToElements()
.ToList());
collectFromModel.Add(new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Roofs)
.WhereElementIsNotElementType()
.WherePasses(stageFilter)
.Cast<Element>()
.ToList());
collectFromModel.Add(new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_StructConnectionPlates)
.WhereElementIsNotElementType()
.WherePasses(stageFilter)
.Cast<Element>()
.ToList());
collectFromModel.Add(new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_StructConnectionAnchors)
.WhereElementIsNotElementType()
.WherePasses(stageFilter)
.Cast<Element>()
.ToList());
collectFromModel.Add(new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_GenericModel)
.WhereElementIsNotElementType()
.WherePasses(stageFilter)
.Cast<Element>()
.Where(x => x.Name != "cube")
.ToList());
List<Element> floors = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Floors)
.WhereElementIsNotElementType()
.WherePasses(stageFilter)
.Cast<Element>()
.ToList();
List<Element> walls = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls)
.WhereElementIsNotElementType()
.WherePasses(stageFilter)
.Cast<Element>()
.ToList();
List<Element> fundament = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_StructuralFoundation)
.WhereElementIsNotElementType()
.WherePasses(stageFilter)
.Cast<Element>()
.ToList();
List<Element> lestnici = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Stairs)
.WhereElementIsNotElementType()
.WherePasses(stageFilter)
.Cast<Element>()
.ToList();
//genModel = genModel.Where(x => x.Name != "cube").ToList();
List<Cube> allCube = new List<Cube>();
foreach (List<Element> a in collectFromModel)
{
foreach (Element e in a)
{
Cube abc = new Cube(e);
if (abc.out_Name == null| abc.out_Name =="")
{
abc.out_Name = "Исключение: " + abc.typeName;
}
allCube.Add(abc);
}
}
foreach (Element f in floors)
{
foreach (ElementId m in f.GetMaterialIds(false))
{
Cube abc = new Cube(doc.GetElement(m), f);
if (abc.out_Name != null)
{
allCube.Add(abc);
}
}
}
foreach (Element w in walls)
{
foreach (ElementId m in w.GetMaterialIds(false))
{
Cube abc = new Cube(doc.GetElement(m), w);
if (abc.out_Name != null)
{
allCube.Add(abc);
}
}
}
foreach (Element f in fundament)
{
foreach (ElementId m in f.GetMaterialIds(false))
{
Cube abc = new Cube(doc.GetElement(m), f);
if (abc.out_Name != null)
{
allCube.Add(abc);
}
}
}
foreach (Element f in lestnici)
{
foreach (ElementId m in f.GetMaterialIds(false))
{
Cube abc = new Cube(doc.GetElement(m), f);
if (abc.out_Name != null)
{
allCube.Add(abc);
}
}
}
List<List<Cube>> groupingCube = new List<List<Cube>>();
//List<string> groupNum=allCube.Select(x => x.Group).Distinct().ToList();
foreach (string eqGroup in allCube.Select(x => x.out_Group).Distinct())
{
List<Cube> similarGroup = new List<Cube>();
foreach (Cube c in allCube)
{
if (c.out_Group == eqGroup)
{
similarGroup.Add(c);
}
}
groupingCube.Add(similarGroup);
}
List<Cube> outCube = new List<Cube>();
foreach (List<Cube> item in groupingCube)
{
int a = 1;
//int addpos = 1;
foreach (string eqName in item.Select(x => x.out_Name).Distinct())
{
List<Cube> b = new List<Cube>();
foreach (Cube i in item)
{
if (i.out_Name == eqName)
{
b.Add(i);
}
}
(Cube addCube, int addpos) = Meta.forgeCube(b, a);
if (addCube.out_Name.Contains("Исключение"))
{
a--;
}
a += addpos;
outCube.Add(addCube);
}
}
List<ElementId> argh = uidoc.Selection.GetElementIds().ToList();
List<wtf.Product> TabSel = new List<wtf.Product>();
foreach (var item in argh)
{
TabSel.Add(new wtf.TABSCreator().Create(doc.GetElement(item)));
}
foreach (var item in TabSel)
{
foreach (Cube c in outCube)
{
if (item.grouping==c.out_Group)
{
item.linkedElt.Add(c);
}
}
}
using (Transaction tr = new Transaction(doc,"SetCurrentSpec"))
{
tr.Start();
foreach (wtf.Product i in TabSel)
{
if (i.linkedElt.Count<2)
{
continue;
}
}
int rowCount = 0;
foreach (wtf.Product e in TabSel)
{
e.refElt.refElement.setP("Лист", doc.GetElement(e.refElt.refElement.OwnerViewId).getP("Номер листа"));
e.refElt.refElement.setP("Строк", e.linkedElt.Count==1?2: e.linkedElt.Count);
e.linkedElt = e.linkedElt.OrderBy(x => x.Prior).ToList();
foreach (Cube cube in e.linkedElt)
{
if (cube.out_Name.Contains("Исключение"))
{
continue;
}
rowCount++;
e.refElt.refElement.setP($"Поз__{rowCount}", cube.out_Pos);
e.refElt.refElement.setP($"Обозначение__{rowCount}", cube.out_Gost);
e.refElt.refElement.setP($"Наименование__{rowCount}", cube.out_Name);
e.refElt.refElement.setP($"К__{rowCount}", cube.out_Kol_vo);
e.refElt.refElement.setP($"М__{rowCount}", cube.out_Mass);
e.refElt.refElement.setP($"Прим__{rowCount}", cube.out_Other);
}
rowCount = 0;
}
tr.Commit();
}
return Result.Succeeded;
}
}
}