Skip to content

Commit 358cbd3

Browse files
authored
Revert "Revert "Element type (#25) (#2468)" (#2473)"
This reverts commit 64a7319.
1 parent 64a7319 commit 358cbd3

42 files changed

Lines changed: 5796 additions & 375 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/DynamoRevit/Resources/LayoutSpecs.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@
118118
{
119119
"path": "RevitNodes.Revit.Elements.Element"
120120
},
121+
{
122+
"path": "RevitNodes.Revit.Elements.ElementType"
123+
},
121124
{
122125
"path": "RevitNodes.Revit.Elements.FailureMessage"
123126
},

src/DynamoRevitIcons/RevitNodesImages.resx

Lines changed: 697 additions & 0 deletions
Large diffs are not rendered by default.

src/Libraries/RevitNodes/Elements/CurtainSystemType.cs

Lines changed: 5 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,14 @@ namespace Revit.Elements
88
/// <summary>
99
/// A Revit CurtainSystemType
1010
/// </summary>
11-
public class CurtainSystemType : Element
11+
public class CurtainSystemType : ElementType
1212
{
1313
#region Internal properties
1414

1515
/// <summary>
1616
/// An internal reference to the CurtainSystemType
1717
/// </summary>
18-
internal Autodesk.Revit.DB.CurtainSystemType InternalCurtainSystemType
19-
{
20-
get; private set;
21-
}
22-
23-
/// <summary>
24-
/// Reference to the Element
25-
/// </summary>
26-
[SupressImportIntoVM]
27-
public override Autodesk.Revit.DB.Element InternalElement
28-
{
29-
get { return InternalCurtainSystemType; }
30-
}
18+
internal Autodesk.Revit.DB.CurtainSystemType InternalCurtainSystemType => InternalElementType as Autodesk.Revit.DB.CurtainSystemType;
3119

3220
#endregion
3321

@@ -36,38 +24,9 @@ public override Autodesk.Revit.DB.Element InternalElement
3624
/// <summary>
3725
/// Private constructor for the Element
3826
/// </summary>
39-
/// <param name="CurtainSystemType"></param>
40-
private CurtainSystemType(Autodesk.Revit.DB.CurtainSystemType curtainSystemType)
41-
{
42-
SafeInit(() => InitCurtainSystemType(curtainSystemType));
43-
}
44-
45-
#endregion
46-
47-
#region Private constructors
48-
49-
/// <summary>
50-
/// Initialize a CurtainSystemType element
51-
/// </summary>
52-
/// <param name="CurtainSystemType"></param>
53-
private void InitCurtainSystemType(Autodesk.Revit.DB.CurtainSystemType curtainSystemType)
54-
{
55-
InternalSetCurtainSystemType(curtainSystemType);
56-
}
57-
58-
#endregion
59-
60-
#region Private mutators
61-
62-
/// <summary>
63-
/// Set the CurtainSystemType property, element id, and unique id
64-
/// </summary>
6527
/// <param name="curtainSystemType"></param>
66-
private void InternalSetCurtainSystemType( Autodesk.Revit.DB.CurtainSystemType curtainSystemType )
28+
private CurtainSystemType(Autodesk.Revit.DB.CurtainSystemType curtainSystemType):base(curtainSystemType)
6729
{
68-
this.InternalCurtainSystemType = curtainSystemType;
69-
this.InternalElementId = curtainSystemType.Id;
70-
this.InternalUniqueId = curtainSystemType.UniqueId;
7130
}
7231

7332
#endregion
@@ -91,7 +50,7 @@ private void InternalSetCurtainSystemType( Autodesk.Revit.DB.CurtainSystemType c
9150
/// </summary>
9251
/// <param name="name"></param>
9352
/// <returns></returns>
94-
public static CurtainSystemType ByName(string name)
53+
public static new CurtainSystemType ByName(string name)
9554
{
9655
if (name == null)
9756
{
@@ -123,7 +82,7 @@ public static CurtainSystemType ByName(string name)
12382
/// <summary>
12483
/// Create a CurtainSystemType from a user selected Element.
12584
/// </summary>
126-
/// <param name="CurtainSystemType"></param>
85+
/// <param name="curtainSystemType"></param>
12786
/// <param name="isRevitOwned"></param>
12887
/// <returns></returns>
12988
internal static CurtainSystemType FromExisting(Autodesk.Revit.DB.CurtainSystemType curtainSystemType, bool isRevitOwned)

src/Libraries/RevitNodes/Elements/Element.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -197,23 +197,19 @@ public Category GetCategory
197197
}
198198

199199
/// <summary>
200-
/// Returns the FamilyType for this Element. Returns null if the Element cannot have a FamilyType assigned.
200+
/// Returns the ElementType for this Element. Returns null if the Element cannot have an ElementType assigned.
201201
/// </summary>
202202
/// <returns name="ElementType">Element Type or Null.</returns>
203-
public Element ElementType
203+
public ElementType ElementType
204204
{
205205
get
206206
{
207207
var typeId = this.InternalElement.GetTypeId();
208208
if (typeId == ElementId.InvalidElementId)
209-
{
210209
return null;
211-
}
212-
else
213-
{
214-
var doc = DocumentManager.Instance.CurrentDBDocument;
215-
return doc.GetElement(typeId).ToDSType(true);
216-
}
210+
211+
var doc = DocumentManager.Instance.CurrentDBDocument;
212+
return doc.GetElement(typeId).ToDSType(true) as ElementType;
217213
}
218214
}
219215

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
using Autodesk.DesignScript.Runtime;
2+
using Autodesk.Revit.DB;
3+
using DSCore.IO;
4+
using DynamoServices;
5+
using RevitServices.Persistence;
6+
using RevitServices.Transactions;
7+
using System;
8+
using System.Collections.Generic;
9+
using System.Drawing;
10+
using System.Linq;
11+
using System.Text;
12+
using System.Threading.Tasks;
13+
14+
namespace Revit.Elements
15+
{
16+
/// <summary>
17+
/// A Revit ElementType
18+
/// </summary>
19+
public class ElementType : Element
20+
{
21+
#region Internal properties
22+
23+
/// <summary>
24+
/// An internal reference to the ElementType.
25+
/// </summary>
26+
internal Autodesk.Revit.DB.ElementType InternalElementType
27+
{
28+
get; private set;
29+
}
30+
31+
/// <summary>
32+
/// Reference to the Element.
33+
/// </summary>
34+
public override Autodesk.Revit.DB.Element InternalElement
35+
{
36+
get { return InternalElementType; }
37+
}
38+
39+
#endregion
40+
41+
#region Private constructors
42+
43+
/// <summary>
44+
/// Private constructor for the Element.
45+
/// </summary>
46+
/// <param name="elementType"></param>
47+
private protected ElementType(Autodesk.Revit.DB.ElementType elementType)
48+
{
49+
SafeInit(() => InitElementType(elementType));
50+
}
51+
52+
/// <summary>
53+
/// Initialize a ElementType element
54+
/// and sets the ElementType property, element id, and unique id.
55+
/// </summary>
56+
/// <param name="elementType"></param>
57+
private void InitElementType(Autodesk.Revit.DB.ElementType elementType)
58+
{
59+
this.InternalElementType = elementType;
60+
this.InternalElementId = elementType.Id;
61+
this.InternalUniqueId = elementType.UniqueId;
62+
}
63+
64+
#endregion
65+
66+
#region Public properties
67+
68+
/// <summary>
69+
/// The name of the ElementType.
70+
/// </summary>
71+
public new string Name
72+
{
73+
get { return InternalElementType.Name; }
74+
}
75+
76+
/// <summary>
77+
/// The FamilyName of the ElementType.
78+
/// </summary>
79+
public string FamilyName
80+
{
81+
get { return InternalElementType.FamilyName; }
82+
}
83+
84+
/// <summary>
85+
/// Determine if this ElementType can be deleted.
86+
/// </summary>
87+
public bool CanBeDeleted
88+
{
89+
get { return InternalElementType.CanBeDeleted; }
90+
}
91+
92+
/// <summary>
93+
/// Determine if this ElementType can be copied.
94+
/// </summary>
95+
public bool CanBeCopied
96+
{
97+
get { return InternalElementType.CanBeCopied; }
98+
}
99+
100+
/// <summary>
101+
/// Determine if this ElementType can be renamed.
102+
/// </summary>
103+
public bool CanBeRenamed
104+
{
105+
get { return InternalElementType.CanBeRenamed; }
106+
}
107+
108+
#endregion
109+
110+
#region Public constructors
111+
112+
/// <summary>
113+
/// Duplicates an existing element type and assigns it a new name.
114+
/// </summary>
115+
/// <param name="name">The new name of the element type.</param>
116+
/// <returns>The duplicated element type.</returns>
117+
public ElementType Duplicate(string name)
118+
{
119+
if (String.IsNullOrWhiteSpace(name))
120+
throw new ArgumentNullException(nameof(name));
121+
122+
TransactionManager.Instance.EnsureInTransaction(Document);
123+
ElementType newElementType = FromExisting(this.InternalElementType.Duplicate(name), true);
124+
TransactionManager.Instance.TransactionTaskDone();
125+
return newElementType;
126+
}
127+
128+
#endregion
129+
130+
#region Public static constructors
131+
132+
/// <summary>
133+
/// Returns the type Element with the given name.
134+
/// </summary>
135+
/// <param name="name">Name of the type</param>
136+
/// <returns>Type Element</returns>
137+
public static ElementType ByName(string name)
138+
{
139+
if (String.IsNullOrWhiteSpace(name))
140+
throw new ArgumentNullException(nameof(name));
141+
142+
var elementType = DocumentManager.Instance
143+
.ElementsOfType<Autodesk.Revit.DB.ElementType>()
144+
.FirstOrDefault(x => x.Name == name);
145+
146+
if (elementType == null)
147+
throw new KeyNotFoundException(Properties.Resources.ElementTypeNameNotFound);
148+
return FromExisting(elementType, true);
149+
}
150+
151+
#endregion
152+
153+
#region Internal static constructors
154+
155+
/// <summary>
156+
/// Create a ElementType from a user selected Element.
157+
/// </summary>
158+
/// <param name="elementType"></param>
159+
/// <param name="isRevitOwned"></param>
160+
/// <returns></returns>
161+
internal static ElementType FromExisting(Autodesk.Revit.DB.ElementType elementType, bool isRevitOwned)
162+
{
163+
return new ElementType(elementType)
164+
{
165+
IsRevitOwned = isRevitOwned
166+
};
167+
}
168+
169+
#endregion
170+
171+
#region Public methods
172+
173+
/// <summary>
174+
/// Get the preview image of an element. This image is similar to what is seen in
175+
/// the Revit UI when selecting the type of an element.
176+
/// </summary>
177+
/// <param name="size">The width and height of the preview image in pixels.</param>
178+
/// <returns>The preview image. null if there is no preview image.</returns>
179+
public Bitmap GetPreviewImage(int size = 500)
180+
{
181+
System.Drawing.Size imageSize = new System.Drawing.Size(size, size);
182+
Bitmap bitmapImage = this.InternalElementType.GetPreviewImage(imageSize);
183+
return bitmapImage;
184+
}
185+
186+
#endregion
187+
}
188+
}

src/Libraries/RevitNodes/Elements/FamilyType.cs

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,15 @@ namespace Revit.Elements
1111
/// A Revit FamilyType, the Revit API refers to this as a FamilySymbol
1212
/// </summary>
1313
[RegisterForTrace]
14-
public class FamilyType: Element
14+
public class FamilyType: ElementType
1515
{
1616

1717
#region Internal Properties
1818

1919
/// <summary>
2020
/// Internal wrapper property
2121
/// </summary>
22-
internal Autodesk.Revit.DB.FamilySymbol InternalFamilySymbol
23-
{
24-
get;
25-
private set;
26-
}
27-
28-
/// <summary>
29-
/// Reference to the Element
30-
/// </summary>
31-
public override Autodesk.Revit.DB.Element InternalElement
32-
{
33-
get { return InternalFamilySymbol; }
34-
}
22+
internal Autodesk.Revit.DB.FamilySymbol InternalFamilySymbol => InternalElementType as Autodesk.Revit.DB.FamilySymbol;
3523

3624
#endregion
3725

@@ -41,37 +29,8 @@ public override Autodesk.Revit.DB.Element InternalElement
4129
/// Private constructor for building a DSFamilySymbol
4230
/// </summary>
4331
/// <param name="symbol"></param>
44-
private FamilyType(Autodesk.Revit.DB.FamilySymbol symbol)
45-
{
46-
SafeInit(() => InitFamilySymbol(symbol));
47-
}
48-
49-
#endregion
50-
51-
#region Helper for private constructors
52-
53-
/// <summary>
54-
/// Initialize a FamilySymbol element
55-
/// </summary>
56-
/// <param name="symbol"></param>
57-
private void InitFamilySymbol(Autodesk.Revit.DB.FamilySymbol symbol)
58-
{
59-
InternalSetFamilySymbol(symbol);
60-
}
61-
62-
#endregion
63-
64-
#region Private mutators
65-
66-
/// <summary>
67-
/// Set the internal model of the family symbol along with its ElementId and UniqueId
68-
/// </summary>
69-
/// <param name="symbol"></param>
70-
private void InternalSetFamilySymbol(Autodesk.Revit.DB.FamilySymbol symbol)
32+
private FamilyType(Autodesk.Revit.DB.FamilySymbol symbol):base(symbol)
7133
{
72-
this.InternalFamilySymbol = symbol;
73-
this.InternalElementId = symbol.Id;
74-
this.InternalUniqueId = symbol.UniqueId;
7534
}
7635

7736
#endregion
@@ -197,7 +156,7 @@ public static FamilyType ByFamilyNameAndTypeName(string familyName, string typeN
197156
/// <search>
198157
/// symbol
199158
/// </search>
200-
public static FamilyType ByName(string name)
159+
public static new FamilyType ByName(string name)
201160
{
202161
if (name == null)
203162
{

0 commit comments

Comments
 (0)