-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPropertiesPlus_Client.js
More file actions
510 lines (423 loc) · 19.1 KB
/
PropertiesPlus_Client.js
File metadata and controls
510 lines (423 loc) · 19.1 KB
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
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
if (typeof PropertiesPlus == 'undefined')
{
PropertiesPlus = {};
}
// the current selection
var currentSelection;
// this is the history we're operating in
var nHistoryID;
var historyDepth = 0;
var editingHistoryName;
var editingHistoryInstances;
// instantiate arrays
var selectedObjectsIDArray;
var selectedObjectsTypeArray;
var selectedObjectsNameArray;
var selectedObjectsLevelsBoolArray;
var selectedObjectsGroupFamilyIDArray;
var selectedObjectsGroupFamilyHistoryIDArray;
var selectedObjectsGroupFamilyNameArray;
var selectedObjectsGroupInstanceIDArray;
var selectedObjectsGroupInstanceNameArray;
// instantiate counts
var vertexCount;
var edgeCount;
var faceCount;
var bodyCount;
var groupFamilyCount;
var groupInstanceCount;
var identicalGroupInstanceCount;
var meshCount;
var lineMeshCount;
var pointMeshCount;
// instantiate booleans
var isConsistentGroupFamilyHistoryIDs;
var isConsistentGroupFamilyNames;
var isConsistentGroupInstanceNames;
// package up everything we need in a JSON object for use in the web script
PropertiesPlus.buildSelectionInfoObject = function()
{
var selectionInfoObject = {
"nHistoryID": nHistoryID, // editingHistoryID
"editingHistoryName" : editingHistoryName,
"editingHistoryInstances" : editingHistoryInstances,
"selectedObjectsIDArray" : selectedObjectsIDArray,
"selectedObjectsTypeArray" : selectedObjectsTypeArray,
"selectedObjectsNameArray" : selectedObjectsNameArray,
"selectedObjectsGroupFamilyHistoryIDArray" : selectedObjectsGroupFamilyHistoryIDArray,
"selectedObjectsGroupFamilyIDArray" : selectedObjectsGroupFamilyIDArray,
"selectedObjectsGroupFamilyNameArray" : selectedObjectsGroupFamilyNameArray,
"selectedObjectsGroupInstanceIDArray" : selectedObjectsGroupInstanceIDArray,
"selectedObjectsGroupInstanceNameArray" : selectedObjectsGroupInstanceNameArray,
"totalCount" : totalCount,
"vertexCount" : vertexCount,
"edgeCount" : edgeCount,
"faceCount" : faceCount,
"bodyCount" : bodyCount,
"meshCount" : meshCount,
"lineMeshCount" : lineMeshCount,
"pointMeshCount" : pointMeshCount,
"groupInstanceCount" : groupInstanceCount,
"isConsistentGroupFamilyHistoryIDs" : isConsistentGroupFamilyHistoryIDs,
"isConsistentGroupFamilyNames" : isConsistentGroupFamilyNames,
"isConsistentGroupInstanceNames" : isConsistentGroupInstanceNames,
"identicalGroupInstanceCount" : identicalGroupInstanceCount
};
return selectionInfoObject;
}
// updates variables and arrays about the items in the selection set
PropertiesPlus.GetSelectionInfo = function(args)
{
console.clear();
console.log("Properties Plus Plugin\n");
// clear arrays
selectedObjectsIDArray = [];
selectedObjectsTypeArray = [];
selectedObjectsNameArray = [];
selectedObjectsLevelsBoolArray = [];
selectedObjectsGroupFamilyIDArray = [];
selectedObjectsGroupFamilyHistoryIDArray = [];
selectedObjectsGroupFamilyNameArray = [];
selectedObjectsGroupInstanceIDArray = [];
selectedObjectsGroupInstanceNameArray = [];
// clear counts
totalCount = 0;
vertexCount = 0;
edgeCount = 0;
faceCount = 0;
bodyCount = 0;
groupFamilyCount = 0;
groupInstanceCount = 0;
identicalGroupInstanceCount = 0;
meshCount = 0;
lineMeshCount = 0;
pointMeshCount = 0;
// clear booleans
isConsistentGroupFamilyHistoryIDs = false;
isConsistentGroupFamilyNames = false;
isConsistentGroupInstanceNames = false;
// get current history
nHistoryID = FormIt.GroupEdit.GetEditingHistoryID();
//console.log("Current history: " + JSON.stringify(nHistoryID));
// get the editing history name
if (nHistoryID === 0)
{
editingHistoryName = "Main Sketch";
}
else
{
// get the Group family name
editingHistoryName = PropertiesPlus.getGroupFamilyName(nHistoryID);
}
// determine how many instances will be edited in the current editing history
if (nHistoryID === 0)
{
editingHistoryInstances = 1;
}
else
{
editingHistoryInstances = WSM.APIGetAllAggregateTransf3dsReadOnly(nHistoryID, 0).paths.length;
}
console.log("Currently editing: " + editingHistoryName + " (" + editingHistoryInstances + " in model)\n");
// get current selection
currentSelection = FormIt.Selection.GetSelections();
totalCount = currentSelection.length;
//console.log("Current selection: " + JSON.stringify(currentSelection));
console.log("Number of objects selected: " + totalCount);
// if too many items are selected, skip the rest of the info-gathering below
if (totalCount > args.maxObjectCount)
{
return PropertiesPlus.buildSelectionInfoObject();
}
// for each object in the selection, get info
for (var i = 0; i < totalCount; i++)
{
// if you're not in the Main History, calculate the depth to extract the correct history data
historyDepth = (currentSelection[i]["ids"].length) - 1;
// get objectID of the current selection, then push the results into an array
var nObjectID = currentSelection[i]["ids"][historyDepth]["Object"];
//console.log("Selection ID: " + nObjectID);
selectedObjectsIDArray.push(nObjectID);
// get object type of the current selection, then push the results into an array
var nType = WSM.APIGetObjectTypeReadOnly(nHistoryID, nObjectID);
//console.log("Object type: " + nType);
selectedObjectsTypeArray.push(nType);
//console.log("Object type array: " + selectedObjectsTypeArray);
// get the properties of this object
var objectProperties = WSM.APIGetObjectPropertiesReadOnly(nHistoryID, nObjectID);
//console.log("Object properties: " + JSON.stringify(objectProperties));
// get the name of this object, then push the results into an array
var objectName = objectProperties.sObjectName;
selectedObjectsNameArray.push(objectName);
//console.log("Object name array: " + JSON.stringify(selectedObjectsNameArray));
// get the Levels setting for this object, then push the results into an array
var bUseLevels = objectProperties.bReportAreaByLevel;
selectedObjectsLevelsBoolArray.push(bUseLevels);
//var bUsesLevels = objectProperties.b
// get group instance info, if there are any selected, and push the results into arrays
if (selectedObjectsTypeArray[i] == WSM.nInstanceType)
{
// get the Group family ID
var groupFamilyID = WSM.APIGetObjectsByTypeReadOnly(nHistoryID, nObjectID, WSM.nGroupType, true)[0];
selectedObjectsGroupFamilyIDArray.push(groupFamilyID);
// get the Group family History ID
var groupFamilyHistoryID = WSM.APIGetGroupReferencedHistoryReadOnly(nHistoryID, groupFamilyID);
selectedObjectsGroupFamilyHistoryIDArray.push(groupFamilyHistoryID);
// get the Group family name
var groupFamilyName = PropertiesPlus.getGroupFamilyName(groupFamilyHistoryID);
selectedObjectsGroupFamilyNameArray.push(groupFamilyName);
// push the Group instance name and ID into arrays
selectedObjectsGroupInstanceNameArray.push(objectName);
selectedObjectsGroupInstanceIDArray.push(nObjectID);
}
}
// do this only if there is a single Group instance selected
if (selectedObjectsGroupInstanceIDArray.length == 1)
{
var referenceHistoryID = WSM.APIGetGroupReferencedHistoryReadOnly(nHistoryID, selectedObjectsGroupInstanceIDArray[0]);
//console.log("Reference history for this Group: " + referenceHistoryID);
// determine how many total instances of this Group are in the model
identicalGroupInstanceCount += WSM.APIGetAllAggregateTransf3dsReadOnly(referenceHistoryID, 0).paths.length;
console.log("Number of instances in model: " + identicalGroupInstanceCount);
}
// determine if the instances come from the same group family
var groupFamilyHistoryIDComparisonResultsArray = testForIdentical(selectedObjectsGroupFamilyHistoryIDArray);
isConsistentGroupFamilyHistoryIDs = booleanReduce(groupFamilyHistoryIDComparisonResultsArray)
// determine if the group families are all of the same name
var groupFamilyNameComparisonResultsArray = testForIdentical(selectedObjectsGroupFamilyNameArray);
isConsistentGroupFamilyNames = booleanReduce(groupFamilyNameComparisonResultsArray);
// determine if the group instances are all of the same name
var groupInstanceNameComparisonResultsArray = testForIdentical(selectedObjectsGroupInstanceNameArray);
isConsistentGroupInstanceNames = booleanReduce(groupInstanceNameComparisonResultsArray);
//console.log("Are group instance names consistent? " + isConsistentGroupInstanceNames);
// fill out arrays for object types in the selection
for (var i = 0; i < selectedObjectsTypeArray.length; i ++)
{
if (selectedObjectsTypeArray[i] === WSM.nVertexType)
{
vertexCount ++;
}
if (selectedObjectsTypeArray[i] === WSM.nEdgeType)
{
edgeCount ++;
}
if (selectedObjectsTypeArray[i] === WSM.nFaceType)
{
faceCount ++;
}
if (selectedObjectsTypeArray[i] === WSM.nBodyType)
{
bodyCount ++;
}
if (selectedObjectsTypeArray[i] === WSM.nMeshType)
{
meshCount ++;
}
if (selectedObjectsTypeArray[i] === WSM.nLineMeshType)
{
lineMeshCount ++;
}
if (selectedObjectsTypeArray[i] === WSM.nPointMeshType)
{
pointMeshCount ++;
}
if (selectedObjectsTypeArray[i] === WSM.nInstanceType)
{
groupInstanceCount ++;
}
}
return PropertiesPlus.buildSelectionInfoObject();
}
PropertiesPlus.deselectObjectsByType = function(args)
{
// define a new selection
var newSelection = [];
// loop through the original selection,
// check whether each object matches the objectType
// if not, add it to the new selection
for (var i = 0; i < selectedObjectsTypeArray.length; i++)
{
if (selectedObjectsTypeArray[i] != args.objectTypeToDeselect)
{
newSelection.push(currentSelection[i]);
}
}
// clear the selection
FormIt.Selection.ClearSelections();
// set the new selection
FormIt.Selection.SetSelections(newSelection);
}
PropertiesPlus.getGroupFamilyName = function(groupHistoryID)
{
var groupName = WSM.APIGetRevitFamilyInformationReadOnly(groupHistoryID).familyReference;
// if the Group name is empty, that means it hasn't been set
// so use the default Group naming convention: "Group " + "historyID"
if (groupName == '')
{
groupName = "Group " + groupHistoryID;;
}
return groupName;
}
PropertiesPlus.calculateVolume = function()
{
var totalVolume = [];
// for each object selected, get the ObjectID and calculate the volume
for (var j = 0; j < selectedObjectsIDArray.length; j++)
{
// calculate the volume of the selection
var selectedVolume = WSM.APIComputeVolumeReadOnly(nHistoryID, selectedObjectsIDArray[j]);
console.log("Selected volume: " + JSON.stringify(selectedVolume));
// add multiple volumes up
totalVolume.push(selectedVolume);
console.log("Accumulated volume array: " + JSON.stringify(totalVolume));
}
}
PropertiesPlus.renameGroupFamilies = function(args)
{
if (selectedObjectsGroupFamilyHistoryIDArray.length === 1 || eliminateDuplicatesInArray(selectedObjectsGroupFamilyHistoryIDArray).length === 1)
{
WSM.APISetRevitFamilyInformation(selectedObjectsGroupFamilyHistoryIDArray[0], false, false, "", args.singleGroupFamilyRename, "", "");
}
else
{
for (var i = 0; i < selectedObjectsGroupFamilyIDArray.length; i++)
{
// TODO: restore Group category on rename
WSM.APISetRevitFamilyInformation(selectedObjectsGroupFamilyHistoryIDArray[i], false, false, "", args.multiGroupFamilyRename, "", "");
}
}
}
PropertiesPlus.renameGroupInstances = function(args)
{
if (selectedObjectsGroupInstanceIDArray.length == 1)
{
WSM.APISetObjectProperties(nHistoryID, selectedObjectsGroupInstanceIDArray[0], args.singleGroupInstanceRename, selectedObjectsLevelsBoolArray[0]);
}
else
{
for (var i = 0; i < selectedObjectsGroupInstanceIDArray.length; i++)
{
WSM.APISetObjectProperties(nHistoryID, selectedObjectsGroupInstanceIDArray[i], args.multiGroupInstanceRename, selectedObjectsLevelsBoolArray[i]);
}
}
}
PropertiesPlus.makeSingleGroupInstanceUnique = function(args)
{
// if only one instance exists in the model, this instance is already unique
if (identicalGroupInstanceCount == 1)
{
var message = selectedObjectsGroupFamilyNameArray[0] + " is already unique."
FormIt.UI.ShowNotification(message, FormIt.NotificationType.Information, 0);
}
else
{
// capture some data about the current selection before it's cleared
var originalSelection = currentSelection;
var originalGroupName = selectedObjectsGroupFamilyNameArray[0];
// make unique
var newGroupID = WSM.APICreateSeparateHistoriesForInstances(nHistoryID, selectedObjectsGroupInstanceIDArray[0], false);
// get the data changed in this history
var changedData = WSM.APIGetCreatedChangedAndDeletedInActiveDeltaReadOnly(nHistoryID, WSM.nInstanceType);
// get the new unique instance ID for selection
var newUniqueInstanceID = changedData["changed"];
//console.log("Unique instance ID: " + JSON.stringify(newUniqueInstanceID));
// clear the selection
FormIt.Selection.ClearSelections();
// get the new group history ID
var newGroupHistoryID = WSM.APIGetGroupReferencedHistoryReadOnly(nHistoryID, Number(newGroupID));
// get the new group name
var newGroupName = PropertiesPlus.getGroupFamilyName(newGroupHistoryID);
// determine the new selection path
var newSelectionPath = originalSelection[0];
// redefine the object ID for the selection path
newSelectionPath["ids"][historyDepth]["Object"] = Number(newUniqueInstanceID);
// add the newly-changed objects to the selection
FormIt.Selection.SetSelections(newSelectionPath);
var message = newGroupName + " is now unique from " + originalGroupName + ".";
FormIt.UI.ShowNotification(message, FormIt.NotificationType.Success, 0);
}
}
// the non-recursive version of Make Unique
PropertiesPlus.makeSingleGroupInstanceUniqueNR = function(args)
{
// if only one instance exists in the model, this instance is already unique
if (identicalGroupInstanceCount == 1)
{
var message = selectedObjectsGroupFamilyNameArray[0] + " is already unique."
FormIt.UI.ShowNotification(message, FormIt.NotificationType.Information, 0);
}
else
{
// capture some data about the current selection before it's cleared
var originalSelection = currentSelection;
var originalGroupName = selectedObjectsGroupFamilyNameArray[0];
// ungroup the instance
WSM.APIFlattenGroupsOrInstances(nHistoryID, selectedObjectsGroupInstanceIDArray[0], false, false);
// get the data changed in this history
var changedData = WSM.APIGetCreatedChangedAndDeletedInActiveDeltaReadOnly(nHistoryID, WSM.nUnSpecifiedType);
// get objects that were ungrouped
var ungroupedObjectIDs = changedData["created"];
//console.log("Unique instance ID: " + JSON.stringify(newUniqueInstanceID));
// clear the selection
//FormIt.Selection.ClearSelections();
// get the new group ID
var newGroupID = WSM.APICreateGroup(nHistoryID, ungroupedObjectIDs);
// get the new group history ID
var newGroupHistoryID = WSM.APIGetGroupReferencedHistoryReadOnly(nHistoryID, Number(newGroupID));
// get thew new group instance ID
var newGroupInstanceChangedData = WSM.APIGetCreatedChangedAndDeletedInActiveDeltaReadOnly(nHistoryID, WSM.nInstanceType);
var newGroupInstanceID = newGroupInstanceChangedData["created"];
// get the new group name
var newGroupName = PropertiesPlus.getGroupFamilyName(newGroupHistoryID);
// determine the new selection path
var newSelectionPath = originalSelection[0];
// redefine the object ID for the selection path
newSelectionPath["ids"][historyDepth]["Object"] = Number(newGroupInstanceID);
// add the newly-changed objects to the selection
FormIt.Selection.SetSelections(newSelectionPath);
var message = newGroupName + " is now non-recursively unique from " + originalGroupName + ".";
FormIt.UI.ShowNotification(message, FormIt.NotificationType.Success, 0);
}
}
// not used yet
PropertiesPlus.makeMultipleGroupInstancesUnique = function(args)
{
// if only one instance exists in the model, this instance is already unique
if (identicalGroupInstanceCount == 1)
{
var message = selectedObjectsGroupFamilyNameArray[0] + " was already unique."
FormIt.UI.ShowNotification(message, FormIt.NotificationType.Information, 0);
}
else
{
// capture some data about the current selection before it's cleared
var originalSelection = currentSelection;
var originalGroupName = selectedObjectsGroupFamilyNameArray[0];
// create a new array to capture the now-unique instances
var newUniqueInstanceIDArray = [];
for (var i = 0; i < selectedObjectsGroupInstanceIDArray.length; i++)
{
WSM.APICreateSeparateHistoriesForInstances(nHistoryID, selectedObjectsGroupInstanceIDArray[i], false);
// get the data changed in this history
var changedData = WSM.APIGetCreatedChangedAndDeletedInActiveDeltaReadOnly(nHistoryID, WSM.nInstanceType);
// add the changed instance ID to the array
var newUniqueInstanceID = changedData["changed"];
newUniqueInstanceIDArray.push(newUniqueInstanceID);
//console.log("Unique instance ID: " + JSON.stringify(newUniqueInstanceID));
}
// clear the selection
FormIt.Selection.ClearSelections();
// add the newly-unique objects back into selection
for (var i = 0; i < originalSelection.length; i++)
{
// determine the new selection path
var newSelectionPath = originalSelection[i];
// redefine the object ID for the selection path
newSelectionPath["ids"][historyDepth]["Object"] = Number(newUniqueInstanceIDArray[i]);
// add the newly-changed objects to the selection
FormIt.Selection.SetSelections(newSelectionPath);
}
var message = " is now unique from " + originalGroupName + ".";
FormIt.UI.ShowNotification(message, FormIt.NotificationType.Success, 0);
}
}