-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBIG_CenterAreaTags.dyn
423 lines (423 loc) · 17.5 KB
/
BIG_CenterAreaTags.dyn
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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
{
"Uuid": "a19d8f41-b681-4d82-a684-c47c9a10bfb8",
"IsCustomNode": false,
"Description": null,
"Name": "Area Tags",
"ElementResolver": {
"ResolutionMap": {
"DSCore.String.Split": {
"Key": "DSCore.String",
"Value": "DSCoreNodes.dll"
},
"DSCore.String": {
"Key": "DSCore.String",
"Value": "DSCoreNodes.dll"
}
}
},
"Inputs": [
{
"Id": "b1d2c2b82c924df8ac5b0d7addfceb1a",
"Name": "B. Chose option:\r\n1. Keep Area location | Move Tag to same point\r\n2. Keep Area location | Move Tag to geometrical center\r\n3. Move Area + Tag location to gemetrical center",
"Type": "number",
"Value": "3",
"MaximumValue": 3.0,
"MinimumValue": 1.0,
"StepValue": 1.0,
"NumberType": "Double",
"Description": "A slider that produces numeric values.",
"SelectedIndex": 0
},
{
"Id": "5bc772adfbda479b88e039ae1095a830",
"Name": "A. Process only Room Tags in warnings",
"Type": "boolean",
"Value": "false",
"Description": "Selection between a true and false.",
"SelectedIndex": 0
}
],
"Outputs": [
{
"Id": "267285e71d6240969a8722dd18825a95",
"Name": "Result:",
"Type": "string",
"InitialValue": "2 Area Tags was/were moved.",
"Description": "Visualize the node's output"
}
],
"Nodes": [
{
"ConcreteType": "PythonNodeModels.PythonNode, PythonNodeModels",
"NodeType": "PythonScriptNode",
"Code": "# Load the Python Standard and DesignScript Libraries\r\nimport clr\r\nimport sys\r\nimport os.path\r\nfrom datetime import datetime\r\nfrom System import Environment\r\nsys.path.append('C:\\Program Files (x86)\\IronPython 2.7\\Lib')\r\nimport System\r\nfrom System import Array\r\nfrom System.Collections.Generic import *\r\nclr.AddReference('ProtoGeometry')\r\nfrom Autodesk.DesignScript.Geometry import *\r\nclr.AddReference(\"RevitNodes\")\r\nimport Revit\r\nclr.ImportExtensions(Revit.Elements)\r\nclr.ImportExtensions(Revit.GeometryConversion)\r\nclr.AddReference(\"RevitServices\")\r\nimport RevitServices\r\nfrom RevitServices.Persistence import DocumentManager \r\nfrom RevitServices.Transactions import TransactionManager \r\n\r\nclr.AddReference(\"RevitAPI\")\r\nclr.AddReference(\"RevitAPIUI\")\r\n\r\nimport Autodesk \r\nfrom Autodesk.Revit.DB import *\r\nfrom Autodesk.Revit.UI import *\r\nimport time\r\n\r\ndoc = DocumentManager.Instance.CurrentDBDocument\r\nuiapp = DocumentManager.Instance.CurrentUIApplication \r\napp = uiapp.Application \r\nuidoc = uiapp.ActiveUIDocument\r\n\r\n### NOW LIFT WHAT THOUSANDS CAN'T SHIFT ### \r\n\r\nisolate_war = IN[0]\r\n\r\nif isolate_war:\r\n\twar_area_tag_ids, war_areas = [], []\r\n\twarnings = doc.GetWarnings()\r\n\tfor w in warnings:\r\n\t\tif \"Area Tag is outside of its Area.\" in w.GetDescriptionText():\r\n\t\t\tids = w.GetFailingElements()\r\n\t\t\tfor i in ids:\r\n\t\t\t\twar_area_tag_ids.Add(i)\r\n\twar_tags = [doc.GetElement(i) for i in war_area_tag_ids]\r\n\twar_areas = [i.Area for i in war_tags]\r\n\tOUT = war_tags, war_areas\r\n\r\nelse:\r\n\ttags = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_AreaTags).WhereElementIsNotElementType().ToElements()\r\n\tareas = [i.Area for i in tags]\r\n\tOUT = tags, areas\r\n\t",
"Engine": "IronPython2",
"VariableInputPorts": true,
"Id": "673f8cb599a14421941f2a5cdafe5fc8",
"Inputs": [
{
"Id": "83a6e44ff8f94c8a98d8870caaf33b69",
"Name": "IN[0]",
"Description": "Input #0",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Outputs": [
{
"Id": "faba6ac5434a4aeab330afb53d92e74f",
"Name": "OUT",
"Description": "Result of the python script",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Replication": "Disabled",
"Description": "Runs an embedded Python script."
},
{
"ConcreteType": "PythonNodeModels.PythonNode, PythonNodeModels",
"NodeType": "PythonScriptNode",
"Code": "import clr\r\nimport sys\r\nimport os.path\r\nfrom System import Environment\r\nsys.path.append('C:\\Program Files (x86)\\IronPython 2.7\\Lib')\r\nimport System\r\nfrom System import Array\r\nfrom System.Collections.Generic import *\r\nclr.AddReference('ProtoGeometry')\r\nfrom Autodesk.DesignScript.Geometry import (Geometry, Point as pt)\r\nclr.AddReference(\"RevitNodes\")\r\nimport Revit\r\nclr.ImportExtensions(Revit.Elements)\r\nclr.ImportExtensions(Revit.GeometryConversion)\r\nclr.AddReference(\"RevitServices\")\r\nimport RevitServices\r\nfrom RevitServices.Persistence import DocumentManager \r\nfrom RevitServices.Transactions import TransactionManager \r\nclr.AddReference(\"RevitAPI\")\r\nclr.AddReference(\"RevitAPIUI\")\r\nimport Autodesk \r\nfrom Autodesk.Revit.DB import *\r\nfrom Autodesk.Revit.UI import *\r\n\r\ndoc = DocumentManager.Instance.CurrentDBDocument\r\nuiapp = DocumentManager.Instance.CurrentUIApplication \r\napp = uiapp.Application \r\nuidoc = uiapp.ActiveUIDocument\r\n\r\n### NOW LIFT WHAT THOUSANDS CAN'T SHIFT ###\r\n\r\ntags = \tUnwrapElement(IN[0])\r\nareas = UnwrapElement(IN[1])\r\nopt = \tIN[2]\r\n\r\n# GET AREA CENTER\r\ndef get_center(area):\r\n # Get the Area Boundary segments\r\n sp_options = SpatialElementBoundaryOptions()\r\n bound_segments = area.GetBoundarySegments(sp_options)\r\n\r\n # Calculate the centroid point\r\n total_len = 0\r\n centroid_x = 0\r\n centroid_y = 0\r\n\r\n for segments in bound_segments:\r\n for boundary_segment in segments:\r\n curve = boundary_segment.GetCurve()\r\n \r\n centroid_x += curve.GetEndPoint(0).X * curve.Length\r\n centroid_y += curve.GetEndPoint(0).Y * curve.Length\r\n total_len += curve.Length\r\n\r\n if total_len != 0:\r\n centroid_x /= total_len\r\n centroid_y /= total_len\r\n \r\n elevation = area.Level.Elevation * 304.8\r\n\r\n return XYZ(centroid_x, centroid_y, elevation)\r\n\r\n# CENTER THE AREAS\r\ndef center_areas(areas):\r\n count = 0\r\n for area in areas:\r\n try:\r\n center = get_center(area)\r\n current = area.Location.Point # get current element location\r\n # MOVE THE AREA TO THE NEW LOCATION\r\n area.Location.Move(center - current)\r\n count += 1\r\n except:\r\n continue\r\n return count\r\n \r\n# ALIGN THE TAGS\r\ndef align_tags(tags, to_center): \r\n count = 0\r\n for tag in tags:\r\n current_loc = tag.Location.Point\r\n if to_center:\r\n new_loc = get_center(tag.Area)\r\n else:\r\n new_loc = tag.Area.Location.Point\r\n tag.Location.Move(new_loc - current_loc)\r\n count += 1\r\n return count\r\n \r\n\r\nTransactionManager.Instance.EnsureInTransaction(doc)\r\n\r\nif opt == 1:\r\n result = align_tags(tags, False)\r\nelif opt == 2:\r\n result = align_tags(tags, True)\r\nelif opt == 3:\r\n center_areas(areas)\r\n result = align_tags(tags, False) \r\n\r\nTransactionManager.Instance.TransactionTaskDone()\r\n\r\nif result > 0:\r\n\tOUT = str(result) + \" Area Tags was/were moved.\"\r\nelse:\r\n\tOUT = \"No Area Tags were moved.\"\r\n",
"Engine": "IronPython2",
"VariableInputPorts": true,
"Id": "35253e84d147415cbd135f81c3fc8744",
"Inputs": [
{
"Id": "45f8233be5b9441b8044ca2c49ae669f",
"Name": "IN[0]",
"Description": "Input #0",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
},
{
"Id": "e78cecdbee01439592d3315c87f05b89",
"Name": "IN[1]",
"Description": "Input #1",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
},
{
"Id": "fb322c5fd6d34ed1bb3262e234f8586f",
"Name": "IN[2]",
"Description": "Input #2",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Outputs": [
{
"Id": "21f2f92843fa4ab48db83068ca92509f",
"Name": "OUT",
"Description": "Result of the python script",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Replication": "Disabled",
"Description": "Runs an embedded Python script."
},
{
"ConcreteType": "Dynamo.Graph.Nodes.CodeBlockNodeModel, DynamoCore",
"NodeType": "CodeBlockNode",
"Code": "tags[0];\nareas[1];",
"Id": "8430f783f9c642fe9261a22b5c993357",
"Inputs": [
{
"Id": "28f444afc69d4fe9af289eaa176661e4",
"Name": "tags",
"Description": "tags",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
},
{
"Id": "00ddb173c56e4b149b368475367a0bb4",
"Name": "areas",
"Description": "areas",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Outputs": [
{
"Id": "44fa8c0c918d4b0a8cdfd0b4e800a718",
"Name": "",
"Description": "Value of expression at line 1",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
},
{
"Id": "1870ed72793d46d19aa8f5c83d149481",
"Name": "",
"Description": "Value of expression at line 2",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Replication": "Disabled",
"Description": "Allows for DesignScript code to be authored directly"
},
{
"ConcreteType": "CoreNodeModels.Input.DoubleSlider, CoreNodeModels",
"NodeType": "NumberInputNode",
"NumberType": "Double",
"MaximumValue": 3.0,
"MinimumValue": 1.0,
"StepValue": 1.0,
"InputValue": 3.0,
"Id": "b1d2c2b82c924df8ac5b0d7addfceb1a",
"Inputs": [],
"Outputs": [
{
"Id": "119d5276455f4e6e810e5ad4d52921d2",
"Name": "",
"Description": "Double",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Replication": "Disabled",
"Description": "A slider that produces numeric values."
},
{
"ConcreteType": "CoreNodeModels.Input.BoolSelector, CoreNodeModels",
"NodeType": "BooleanInputNode",
"InputValue": false,
"Id": "5bc772adfbda479b88e039ae1095a830",
"Inputs": [],
"Outputs": [
{
"Id": "4321617b30c04a94a8fd979e2643e25d",
"Name": "",
"Description": "Boolean",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Replication": "Disabled",
"Description": "Selection between a true and false."
},
{
"ConcreteType": "CoreNodeModels.Watch, CoreNodeModels",
"NodeType": "ExtensionNode",
"Id": "267285e71d6240969a8722dd18825a95",
"Inputs": [
{
"Id": "4164cbf12a444ee3821c5af30472ddc6",
"Name": "",
"Description": "Node to show output from",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Outputs": [
{
"Id": "829f037de68b4915b3e4e217e27b4ca6",
"Name": "",
"Description": "Node output",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Replication": "Disabled",
"Description": "Visualize the node's output"
}
],
"Connectors": [
{
"Start": "faba6ac5434a4aeab330afb53d92e74f",
"End": "28f444afc69d4fe9af289eaa176661e4",
"Id": "990bb854b80541ee9ad9361132eee8f0"
},
{
"Start": "faba6ac5434a4aeab330afb53d92e74f",
"End": "00ddb173c56e4b149b368475367a0bb4",
"Id": "0a6d9943fdd24ec5940613a041d46788"
},
{
"Start": "21f2f92843fa4ab48db83068ca92509f",
"End": "4164cbf12a444ee3821c5af30472ddc6",
"Id": "75a0ce08d9a54f59a46f950016c3fde7"
},
{
"Start": "44fa8c0c918d4b0a8cdfd0b4e800a718",
"End": "45f8233be5b9441b8044ca2c49ae669f",
"Id": "0e82c320621c46f7abf857b824952b11"
},
{
"Start": "1870ed72793d46d19aa8f5c83d149481",
"End": "e78cecdbee01439592d3315c87f05b89",
"Id": "5640f7cd24f941b38f165ce64c53f9fa"
},
{
"Start": "119d5276455f4e6e810e5ad4d52921d2",
"End": "fb322c5fd6d34ed1bb3262e234f8586f",
"Id": "380b682b31a34873a24c6eff3f8cef8d"
},
{
"Start": "4321617b30c04a94a8fd979e2643e25d",
"End": "83a6e44ff8f94c8a98d8870caaf33b69",
"Id": "df881d8af7474471b86f312511913c9f"
}
],
"Dependencies": [],
"NodeLibraryDependencies": [],
"Thumbnail": "",
"GraphDocumentationURL": null,
"ExtensionWorkspaceData": [
{
"ExtensionGuid": "28992e1d-abb9-417f-8b1b-05e053bee670",
"Name": "Properties",
"Version": "2.12",
"Data": {}
},
{
"ExtensionGuid": "DFBD9CC0-DB40-457A-939E-8C8555555A9D",
"Name": "Generative Design",
"Version": "1.10",
"Data": {}
}
],
"Author": "None provided",
"Linting": {
"activeLinter": "None",
"activeLinterId": "7b75fb44-43fd-4631-a878-29f4d5d8399a",
"warningCount": 0,
"errorCount": 0
},
"Bindings": [],
"View": {
"Dynamo": {
"ScaleFactor": 100.0,
"HasRunWithoutCrash": true,
"IsVisibleInDynamoLibrary": true,
"Version": "2.12.1.8246",
"RunType": "Manual",
"RunPeriod": "1000"
},
"Camera": {
"Name": "Background Preview",
"EyeX": -17.0,
"EyeY": 24.0,
"EyeZ": 50.0,
"LookX": 12.0,
"LookY": -13.0,
"LookZ": -58.0,
"UpX": 0.0,
"UpY": 1.0,
"UpZ": 0.0
},
"NodeViews": [
{
"ShowGeometry": true,
"Name": "Python Script",
"Id": "673f8cb599a14421941f2a5cdafe5fc8",
"IsSetAsInput": false,
"IsSetAsOutput": false,
"Excluded": false,
"X": 481.96856578123311,
"Y": -850.55292366560934
},
{
"ShowGeometry": true,
"Name": "Python Script",
"Id": "35253e84d147415cbd135f81c3fc8744",
"IsSetAsInput": false,
"IsSetAsOutput": false,
"Excluded": false,
"X": 831.04607505295212,
"Y": -865.3822407842008
},
{
"ShowGeometry": true,
"Name": "Code Block",
"Id": "8430f783f9c642fe9261a22b5c993357",
"IsSetAsInput": false,
"IsSetAsOutput": false,
"Excluded": false,
"X": 634.73044784499211,
"Y": -853.71545844376976
},
{
"ShowGeometry": true,
"Name": "B. Chose option:\r\n1. Keep Area location | Move Tag to same point\r\n2. Keep Area location | Move Tag to geometrical center\r\n3. Move Area + Tag location to gemetrical center",
"Id": "b1d2c2b82c924df8ac5b0d7addfceb1a",
"IsSetAsInput": true,
"IsSetAsOutput": false,
"Excluded": false,
"X": -153.55174000426,
"Y": -747.877240109199
},
{
"ShowGeometry": true,
"Name": "A. Process only Room Tags in warnings",
"Id": "5bc772adfbda479b88e039ae1095a830",
"IsSetAsInput": true,
"IsSetAsOutput": false,
"Excluded": false,
"X": 131.319292076333,
"Y": -850.20663628478314
},
{
"ShowGeometry": true,
"Name": "Result:",
"Id": "267285e71d6240969a8722dd18825a95",
"IsSetAsInput": false,
"IsSetAsOutput": true,
"Excluded": false,
"X": 994.58021660736244,
"Y": -863.45959278201144
}
],
"Annotations": [
{
"Id": "8fdb144cfcce425bbd263bb219bec8fc",
"Title": "B. Chose option:\r\n1. Keep Area location | Move Tag to same point\r\n2. Keep Area location | Move Tag to geometrical center\r\n3. Move Area + Tag location to gemetrical center\r\n\r\n",
"Nodes": [
"b1d2c2b82c924df8ac5b0d7addfceb1a",
"5bc772adfbda479b88e039ae1095a830"
],
"Left": -163.55174000426,
"Top": -1033.2066362847831,
"Width": 603.87103208059307,
"Height": 353.32939617558418,
"FontSize": 24.0,
"InitialTop": -850.20663628478314,
"InitialHeight": 247.32939617558418,
"TextblockHeight": 173.0,
"Background": "#FFD3D3D3"
}
],
"X": 205.74136395579944,
"Y": 1200.1911514248291,
"Zoom": 0.98439595971264227
}
}