/
FamilyInstance.cs
694 lines (583 loc) · 26.8 KB
/
FamilyInstance.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
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
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
using System;
using System.Linq;
using Autodesk.DesignScript.Geometry;
using DynamoServices;
using DynamoUnits;
using Revit.Elements.InternalUtilities;
using Revit.GeometryConversion;
using Revit.GeometryReferences;
using RevitServices.Persistence;
using RevitServices.Transactions;
using Point = Autodesk.DesignScript.Geometry.Point;
using Surface = Autodesk.DesignScript.Geometry.Surface;
using Vector = Autodesk.DesignScript.Geometry.Vector;
namespace Revit.Elements
{
/// <summary>
/// A Revit FamilyInstance
/// </summary>
[RegisterForTrace]
public class FamilyInstance : AbstractFamilyInstance
{
#region Private constructors
/// <summary>
/// Wrap an existing FamilyInstance.
/// </summary>
/// <param name="instance"></param>
protected FamilyInstance(Autodesk.Revit.DB.FamilyInstance instance)
{
SafeInit(() => InitFamilyInstance(instance));
}
/// <summary>
/// Internal constructor for a FamilyInstance
/// </summary>
internal FamilyInstance(Autodesk.Revit.DB.FamilySymbol fs, Autodesk.Revit.DB.XYZ pos,
Autodesk.Revit.DB.Level level)
{
SafeInit(() => InitFamilyInstance(fs, pos, level));
}
/// <summary>
/// Internal constructor for a FamilyInstance
/// </summary>
internal FamilyInstance(Autodesk.Revit.DB.FamilySymbol fs, Autodesk.Revit.DB.XYZ pos)
{
SafeInit(() => InitFamilyInstance(fs, pos));
}
internal FamilyInstance(Autodesk.Revit.DB.FamilySymbol fs, Autodesk.Revit.DB.Reference reference, Autodesk.Revit.DB.Line pos)
{
SafeInit(() => InitFamilyInstance(fs, reference, pos));
}
internal FamilyInstance(Autodesk.Revit.DB.FamilySymbol fs, Autodesk.Revit.DB.Reference reference, Autodesk.Revit.DB.XYZ location, Autodesk.Revit.DB.XYZ referenceDirection)
{
SafeInit(() => InitFamilyInstance(fs, reference, location, referenceDirection));
}
#endregion
#region Helpers for private constructors
/// <summary>
/// Initialize a FamilyInstance element
/// </summary>
/// <param name="instance"></param>
private void InitFamilyInstance(Autodesk.Revit.DB.FamilyInstance instance)
{
InternalSetFamilyInstance(instance);
}
/// <summary>
/// Initialize a FamilyInstance element
/// </summary>
private void InitFamilyInstance(Autodesk.Revit.DB.FamilySymbol fs, Autodesk.Revit.DB.XYZ pos,
Autodesk.Revit.DB.Level level)
{
//Phase 1 - Check to see if the object exists and should be rebound
var oldFam =
ElementBinder.GetElementFromTrace<Autodesk.Revit.DB.FamilyInstance>(Document);
//There was a point, rebind to that, and adjust its position
if (oldFam != null)
{
InternalSetFamilyInstance(oldFam);
InternalSetLevel(level);
InternalSetFamilySymbol(fs);
InternalSetPosition(pos);
return;
}
//Phase 2- There was no existing point, create one
TransactionManager.Instance.EnsureInTransaction(Document);
//If the symbol is not active, then activate it
if (!fs.IsActive)
fs.Activate();
Autodesk.Revit.DB.FamilyInstance fi;
if (Document.IsFamilyDocument)
{
fi = Document.FamilyCreate.NewFamilyInstance(pos, fs, level,
Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
}
else
{
fi = Document.Create.NewFamilyInstance(
pos, fs, level, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
}
InternalSetFamilyInstance(fi);
TransactionManager.Instance.TransactionTaskDone();
ElementBinder.SetElementForTrace(InternalElement);
}
/// <summary>
/// Initialize a FamilyInstance element
/// </summary>
private void InitFamilyInstance(Autodesk.Revit.DB.FamilySymbol fs, Autodesk.Revit.DB.XYZ pos)
{
//Phase 1 - Check to see if the object exists and should be rebound
var oldFam =
ElementBinder.GetElementFromTrace<Autodesk.Revit.DB.FamilyInstance>(Document);
//There was a point, rebind to that, and adjust its position
if (oldFam != null)
{
InternalSetFamilyInstance(oldFam);
InternalSetFamilySymbol(fs);
InternalSetPosition(pos);
return;
}
//Phase 2- There was no existing point, create one
TransactionManager.Instance.EnsureInTransaction(Document);
//If the symbol is not active, then activate it
if (!fs.IsActive)
fs.Activate();
var fi = Document.IsFamilyDocument
? Document.FamilyCreate.NewFamilyInstance(pos, fs, Autodesk.Revit.DB.Structure.StructuralType.NonStructural)
: Document.Create.NewFamilyInstance(pos, fs, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
InternalSetFamilyInstance(fi);
TransactionManager.Instance.TransactionTaskDone();
ElementBinder.SetElementForTrace(InternalElement);
}
private void InitFamilyInstance(Autodesk.Revit.DB.FamilySymbol fs, Autodesk.Revit.DB.Reference reference, Autodesk.Revit.DB.Line pos)
{
//Phase 1 - Check to see if the object exists and should be rebound
var oldFam =
ElementBinder.GetElementFromTrace<Autodesk.Revit.DB.FamilyInstance>(Document);
//There was an existing family instance, rebind to that, and adjust its position
if (oldFam != null && oldFam.HostFace.ElementId == reference.ElementId)
{
InternalSetFamilyInstance(oldFam);
InternalSetFamilySymbol(fs);
InternalSetPosition(pos);
return;
}
//Phase 2- There was no existing point, create one
TransactionManager.Instance.EnsureInTransaction(Document);
//If the symbol is not active, then activate it
if (!fs.IsActive)
fs.Activate();
var fi = Document.IsFamilyDocument
? Document.FamilyCreate.NewFamilyInstance(reference, pos, fs)
: Document.Create.NewFamilyInstance(reference, pos, fs);
InternalSetFamilyInstance(fi);
TransactionManager.Instance.TransactionTaskDone();
ElementBinder.SetElementForTrace(InternalElement);
}
private void InitFamilyInstance(Autodesk.Revit.DB.FamilySymbol fs, Autodesk.Revit.DB.Reference reference, Autodesk.Revit.DB.XYZ location,
Autodesk.Revit.DB.XYZ referenceDirection)
{
//Phase 1 - Check to see if the object exists and should be rebound
var oldFam =
ElementBinder.GetElementFromTrace<Autodesk.Revit.DB.FamilyInstance>(Document);
//There was an existing family instance, rebind to that, and adjust its position
if (oldFam != null && oldFam.HostFace.ElementId == reference.ElementId)
{
InternalSetFamilyInstance(oldFam);
InternalSetFamilySymbol(fs);
InternalSetPosition(location);
return;
}
//Phase 2- There was no existing point, create one
TransactionManager.Instance.EnsureInTransaction(Document);
//If the symbol is not active, then activate it
if (!fs.IsActive)
fs.Activate();
var fi = Document.IsFamilyDocument
? Document.FamilyCreate.NewFamilyInstance(reference, location, referenceDirection, fs)
: Document.Create.NewFamilyInstance(reference, location, referenceDirection, fs);
InternalSetFamilyInstance(fi);
TransactionManager.Instance.TransactionTaskDone();
ElementBinder.SetElementForTrace(InternalElement);
}
#endregion
#region Private mutators
private void InternalSetLevel(Autodesk.Revit.DB.Level level)
{
if (InternalFamilyInstance.LevelId.Compare(level.Id) == 0)
return;
TransactionManager.Instance.EnsureInTransaction(Document);
// http://thebuildingcoder.typepad.com/blog/2011/01/family-instance-missing-level-property.html
InternalFamilyInstance.get_Parameter(Autodesk.Revit.DB.BuiltInParameter.FAMILY_LEVEL_PARAM).Set(level.Id);
TransactionManager.Instance.TransactionTaskDone();
}
private void InternalSetPosition(Autodesk.Revit.DB.XYZ fi)
{
TransactionManager.Instance.EnsureInTransaction(Document);
var lp = InternalFamilyInstance.Location as Autodesk.Revit.DB.LocationPoint;
if (lp != null && !lp.Point.IsAlmostEqualTo(fi)) lp.Point = fi;
TransactionManager.Instance.TransactionTaskDone();
}
private void InternalSetPosition(Autodesk.Revit.DB.Curve pos)
{
TransactionManager.Instance.EnsureInTransaction(Document);
var lp = InternalFamilyInstance.Location as Autodesk.Revit.DB.LocationCurve;
if (lp != null && lp.Curve != pos) lp.Curve = pos;
TransactionManager.Instance.TransactionTaskDone();
}
#endregion
#region Public properties
/// <summary>
/// Gets family type of the specific family instance
/// </summary>
/// <search>
/// symbol
/// </search>
[Obsolete("Use Element.ElementType instead.")]
public new FamilyType Type
{
// NOTE: Because AbstractFamilyInstance is not visible in the library
// we redefine this method on FamilyInstance
get { return base.Type; }
}
/// <summary>
/// Gets the location of the specific family instance
/// </summary>
public new Point Location
{
// NOTE: Because AbstractFamilyInstance is not visible in the library
// we redefine this method on FamilyInstance
get { return base.Location; }
}
/// <summary>
/// Gets the FacingOrientation of the family instance
/// </summary>
public Vector FacingOrientation
{
get
{
return InternalFamilyInstance.IsValidObject ?
InternalFamilyInstance.FacingOrientation.ToVector() : null;
}
}
/// <summary>
/// The room in which the instance is located.
/// </summary>
public Element Room
{
get
{
var room = this.InternalFamilyInstance.Room;
if (room == null)
return null;
return room.ToDSType(true);
}
}
/// <summary>
/// The space in which the instance is located.
/// </summary>
public Element Space
{
get
{
var space = this.InternalFamilyInstance.Space;
if (space == null)
return null;
return space.ToDSType(true);
}
}
#endregion
#region Public static constructors
/// <summary>
/// Place a Revit FamilyInstance given the FamilyType (also known as the FamilySymbol in the Revit API) and its coordinates in world space
/// </summary>
/// <param name="familyType">Family Type. Also called Family Symbol.</param>
/// <param name="point">Point in meters.</param>
/// <returns></returns>
public static FamilyInstance ByPoint(FamilyType familyType, Point point)
{
if (familyType == null)
{
throw new ArgumentNullException("familyType");
}
if (point == null)
{
throw new ArgumentNullException("point");
}
return new FamilyInstance(familyType.InternalFamilySymbol, point.ToXyz());
}
/// <summary>
/// Place a Revit family instance of the given the FamilyType (also known as the FamilySymbol in the Revit API)
/// on a surface derived from a backing Revit face as reference and a line as reference for its position.
///
/// Note: The FamilyPlacementType must be CurveBased and the input surface must be created from a Revit Face
/// </summary>
/// <param name="familyType">Family Type. Also called Family Symbol.</param>
/// <param name="face">Surface geometry derived from a Revit face as reference element</param>
/// <param name="line">A line on the face defining where the symbol is to be placed</param>
/// <returns>FamilyInstance</returns>
public static FamilyInstance ByFace(FamilyType familyType, Surface face, Autodesk.DesignScript.Geometry.Line line)
{
if (familyType == null)
{
throw new ArgumentNullException("familyType");
}
if (face == null)
{
throw new ArgumentNullException("face");
}
if (line == null)
{
throw new ArgumentNullException("line");
}
var reference = ElementFaceReference.TryGetFaceReference(face);
return new FamilyInstance(familyType.InternalFamilySymbol, reference.InternalReference, (Autodesk.Revit.DB.Line) line.ToRevitType());
}
/// <summary>
/// Place a Revit family instance given the FamilyType (also known as the FamilySymbol in the Revit API)
/// on a surface derived from a backing Revit face as reference, a reference direction and a point location where to place the family.
///
/// Note: The FamilyType should be workplane based and the input surface must be created from a Revit Face. The reference direction defines the rotation of the instance on the reference, and thus cannot be perpendicular to the face.
/// </summary>
/// <param name="familyType">Family Type. Also called Family Symbol.</param>
/// <param name="face">Surface geometry derived from a Revit face as reference element</param>
/// <param name="location">Point on the face where the instance is to be placed</param>
/// <param name="referenceDirection">A vector that defines the direction of placement of the family instance</param>
/// <returns>FamilyInstance</returns>
public static FamilyInstance ByFace(FamilyType familyType, Surface face, Point location,
Vector referenceDirection)
{
if (familyType == null)
{
throw new ArgumentNullException("familyType");
}
if (face == null)
{
throw new ArgumentNullException("face");
}
if (location == null)
{
throw new ArgumentNullException("location");
}
if (referenceDirection == null)
{
throw new ArgumentNullException("referenceDirection");
}
var reference = ElementFaceReference.TryGetFaceReference(face);
return new FamilyInstance(familyType.InternalFamilySymbol, reference.InternalReference,
location.ToXyz(), referenceDirection.ToXyz());
}
/// <summary>
/// Place a Revit FamilyInstance given the FamilyType (also known as the FamilySymbol in the Revit API) and its coordinates in world space
/// </summary>
/// <param name="familyType">Family Type. Also called Family Symbol.</param>
/// <param name="x">X coordinate in meters</param>
/// <param name="y">Y coordinate in meters</param>
/// <param name="z">Z coordinate in meters</param>
/// <returns></returns>
public static FamilyInstance ByCoordinates(FamilyType familyType, double x = 0, double y = 0, double z = 0)
{
if (familyType == null)
{
throw new ArgumentNullException("familyType");
}
var pt = Point.ByCoordinates(x, y, z);
return ByPoint(familyType, pt);
}
/// <summary>
/// Place a Revit FamilyInstance given the FamilyType (also known as the FamilySymbol in the Revit API), it's coordinates in world space, and the Level
/// </summary>
/// <param name="familyType">Family Type. Also called Family Symbol.</param>
/// <param name="point">Point in meters.</param>
/// <param name="level">Level to host Family Instance.</param>
/// <returns></returns>
public static FamilyInstance ByPointAndLevel(FamilyType familyType, Point point, Level level)
{
if (familyType == null)
{
throw new ArgumentNullException("familyType");
}
return new FamilyInstance(familyType.InternalFamilySymbol, point.ToXyz(), level.InternalLevel);
}
/// <summary>
/// Obtain a collection of FamilyInstances from the Revit Document and use them in the Dynamo graph
/// </summary>
/// <param name="familyType">Family Type. Also called Family Symbol.</param>
/// <returns></returns>
/// <search>
/// byfamilysymbol,ByFamilySymbol
/// </search>
public static FamilyInstance[] ByFamilyType(FamilyType familyType)
{
if (familyType == null)
{
throw new ArgumentNullException("familyType");
}
return DocumentManager.Instance
.ElementsOfType<Autodesk.Revit.DB.FamilyInstance>()
.Where(x => x.Symbol.Id == familyType.InternalFamilySymbol.Id)
.Select(x => FromExisting(x, true))
.ToArray();
}
/// <summary>
/// Place a Revit FamilyInstance given the FamilyType (also known as the FamilySymbol in the Revit API) and its coordinate system.
/// </summary>
/// <param name="familyType">Family Type. Also called Family Symbol.</param>
/// <param name="coordinateSystem">Coordinates system to place the new family instance in.</param>
/// <returns>New family instance.</returns>
public static FamilyInstance ByCoordinateSystem(FamilyType familyType, CoordinateSystem coordinateSystem)
{
var transform = coordinateSystem.ToTransform() as Autodesk.Revit.DB.Transform;
double[] newRotationAngles;
TransformUtils.ExtractEularAnglesFromTransform(transform, out newRotationAngles);
double rotation = ConvertEularToAngleDegrees(newRotationAngles.FirstOrDefault());
Point location = transform.ToCoordinateSystem().Origin;
FamilyInstance familyInstance = ByPoint(familyType, location);
familyInstance.SetRotation(rotation);
return familyInstance;
}
#endregion
#region Internal static constructors
/// <summary>
/// Construct a FamilyInstance from the Revit document.
/// </summary>
/// <param name="familyInstance"></param>
/// <param name="isRevitOwned"></param>
/// <returns></returns>
internal static FamilyInstance FromExisting(Autodesk.Revit.DB.FamilyInstance familyInstance, bool isRevitOwned)
{
return new FamilyInstance(familyInstance)
{
IsRevitOwned = isRevitOwned
};
}
#endregion
#region Public Methods
public override string ToString()
{
return InternalFamilyInstance.IsValidObject ? InternalFamilyInstance.Name : "empty";
}
/// <summary>
/// Gets the host of this fmaily instance (if any). Eg. returns the wall of a window or door family instance.
/// </summary>
public Element GetHost
{
get
{
if (this.InternalFamilyInstance.Host != null)
// TODO: This might need to change since its not clear if the Host element is revit owned or not.
// Currently there is no way of figuring this out, therefore the assumption is true (Revit owned)
return ElementWrapper.Wrap(this.InternalFamilyInstance.Host, true);
throw new Exception(Properties.Resources.InvalidHost);
}
}
/// <summary>
/// Gets the family of this family instance
/// </summary>
public Family GetFamily
{
get
{
return Family.FromExisting(this.InternalFamilyInstance.Symbol.Family, true);
}
}
/// <summary>
/// Gets the family type of this family instance
/// </summary>
[Obsolete("Use Element.ElementType instead.")]
public new FamilyType GetType
{
// NOTE: Because AbstractFamilyInstance is not visible in the library
// we redefine this method on FamilyInstance
get { return base.Type; }
}
/// <summary>
/// Set the Euler angle of the family instance around its local Z-axis.
/// </summary>
/// <param name="degree">The Euler angle around Z-axis.</param>
/// <returns>The result family instance.</returns>
public FamilyInstance SetRotation(double degree)
{
if (this == null)
{
throw new ArgumentNullException("degree");
}
var oldTransform = InternalGetTransform();
double[] oldRotationAngles;
TransformUtils.ExtractEularAnglesFromTransform(oldTransform, out oldRotationAngles);
var newRotationAngle = degree * Math.PI / 180;
if (!oldRotationAngles[0].AlmostEquals(newRotationAngle, 1.0e-6))
{
var rotateAngle = newRotationAngle - oldRotationAngles[0];
var axis = Autodesk.Revit.DB.Line.CreateUnbound(oldTransform.Origin, oldTransform.BasisZ);
Autodesk.Revit.DB.ElementTransformUtils.RotateElement(Document, new Autodesk.Revit.DB.ElementId(Id), axis, -rotateAngle);
}
TransactionManager.Instance.TransactionTaskDone();
return this;
}
/// <summary>
/// Transforms this FamilyInstance from a source CoordinateSystem to a new context CoordinateSystem.
/// </summary>
/// <param name="fromCoordinateSystem">Source CoordinatSystem</param>
/// <param name="contextCoordinateSystem">Context CordinateSystem</param>
/// <returns>Transformed Element</returns>
public FamilyInstance Transform(CoordinateSystem fromCoordinateSystem, CoordinateSystem contextCoordinateSystem)
{
TransactionManager.Instance.EnsureInTransaction(Document);
var transManager = TransactionManager.Instance.TransactionWrapper;
var t = transManager.StartTransaction(Document);
var elementTransform = this.InternalGetTransform();
var contextTransform = contextCoordinateSystem.ToTransform();
try
{
if (elementTransform.BasisX.IsAlmostEqualTo(contextTransform.BasisX) &&
elementTransform.BasisY.IsAlmostEqualTo(contextTransform.BasisY) &&
elementTransform.BasisZ.IsAlmostEqualTo(contextTransform.BasisZ))
{
return this;
}
double degrees = GetRotationFromCS(fromCoordinateSystem, contextCoordinateSystem);
this.SetRotation(degrees);
this.SetLocationFromCS(fromCoordinateSystem, contextCoordinateSystem);
}
catch (Exception ex)
{
t.CancelTransaction();
throw new Exception(ex.Message);
}
TransactionManager.Instance.TransactionTaskDone();
return this;
}
#endregion
#region Private helper methods
/// <summary>
/// Get the transform of the internal family instance
/// </summary>
/// <returns>The internal transform</returns>
private Autodesk.Revit.DB.Transform InternalGetTransform()
{
TransactionManager.Instance.EnsureInTransaction(Document);
Document.Regenerate();
return InternalFamilyInstance.IsValidObject ? InternalFamilyInstance.GetTransform() : null;
}
private double GetRotationFromCS(CoordinateSystem fromCS, CoordinateSystem contextCS)
{
var elementTransform = this.InternalFamilyInstance.GetTransform();
var newTransform = contextCS.ToTransform() as Autodesk.Revit.DB.Transform;
var oldTransform = fromCS.ToTransform() as Autodesk.Revit.DB.Transform;
double[] oldRotationAngles;
TransformUtils.ExtractEularAnglesFromTransform(oldTransform, out oldRotationAngles);
double[] newRotationAngles;
TransformUtils.ExtractEularAnglesFromTransform(newTransform, out newRotationAngles);
return ConvertEularToAngleDegrees(newRotationAngles.FirstOrDefault());
}
private static double ConvertEularToAngleDegrees(double newRotationAngles)
{
return (newRotationAngles / (2 * Math.PI)) * 360;
}
private void SetLocationFromCS(CoordinateSystem fromCS, CoordinateSystem contextCS)
{
var locationGeometry = this.InternalElement.Location;
if (locationGeometry is Autodesk.Revit.DB.LocationCurve)
{
var locationCurve = locationGeometry as Autodesk.Revit.DB.LocationCurve;
var dynamoCurve = locationCurve.Curve.ToProtoType();
var newLocation = dynamoCurve.Transform(fromCS, contextCS) as Curve;
locationCurve.Curve = newLocation.ToRevitType(true);
dynamoCurve.Dispose();
newLocation.Dispose();
return;
}
else if (locationGeometry is Autodesk.Revit.DB.LocationPoint)
{
var location = this.InternalElement.Location as Autodesk.Revit.DB.LocationPoint;
var dynamoPoint = location.Point.ToPoint(true);
var newLocation = dynamoPoint.Transform(fromCS, contextCS) as Autodesk.DesignScript.Geometry.Point;
location.Point = newLocation.ToRevitType(true);
dynamoPoint.Dispose();
newLocation.Dispose();
return;
}
throw new Exception(Properties.Resources.InvalidElementLocation);
}
#endregion
}
}