SetComponents Method


Sets a collection of the load combination components.

Namespace: Autodesk.Revit.DB.Structure
Assembly: RevitAPI (in RevitAPI.dll) Version: 16.0.0.0 (16.0.0.0)
Since: 2016

Syntax

C#
public void SetComponents(
	IList<LoadComponent> components
)
Visual Basic
Public Sub SetComponents ( _
	components As IList(Of LoadComponent) _
)
Visual C++
public:
void SetComponents(
	IList<LoadComponent^>^ components
)

Parameters

components
Type: System.Collections.Generic IList LoadComponent
A collection of the load combination components.

Examples

Copy C#
#region Autodesk.Revit.DB.Structure.LoadCombination.SetUsageIds(System.Collections.Generic.IList{Autodesk.Revit.DB.ElementId})
LoadCombination CreateLoadCombinationLoadCaseLoadUsageLoadNatureAndLoadComponent(Document document)
{
    // Create a new load combination
    LoadCombination loadCombination = LoadCombination.Create(document, "DL1 + RAIN1", LoadCombinationType.Combination, LoadCombinationState.Ultimate);
    if (loadCombination == null)
       throw new Exception("Create new load combination failed.");

    // Get all existing LoadCase
    FilteredElementCollector collector = new FilteredElementCollector(document);
    ICollection<Element> collection = collector.OfClass(typeof(LoadCase)).ToElements();

    // Find LoadCase "DL1"
    LoadCase case1 = null;
    foreach (Element e in collection)
    {
       LoadCase loadCase = e as LoadCase;
       if (loadCase.Name == "DL1")
       {
          case1 = loadCase;
          break;
       }
    }

    // Get all existing LoadNature
    collector = new FilteredElementCollector(document);
    collection = collector.OfClass(typeof(LoadNature)).ToElements();

    // Find LoadNature "Dead"
    LoadNature nature1 = null;
    foreach (Element e in collection)
    {
       LoadNature loadNature = e as LoadNature;
       if (loadNature.Name == "Dead")
       {
          nature1 = loadNature;
          break;
       }
    }

    // Create LoadNature "Dead" if not exist
    if (nature1 == null)
       nature1 = LoadNature.Create(document, "Dead");

    // Create LoadCase "DL1" if not exist
    if (case1 == null)
       case1 = LoadCase.Create(document, "DL1", nature1.Id, LoadNatureCategory.Dead);

    // Create LoadNature "Rain"
    LoadNature nature2 = LoadNature.Create(document, "Rain");
    if (nature2 == null)
       throw new Exception("Create new load nature failed.");

    // Create LoadCase "RAIN1"
    LoadCase case2 = LoadCase.Create(document, "RAIN1", nature2.Id, LoadNatureCategory.Snow);
    if (case1 == null || case2 == null)
       throw new Exception("Create new load case failed.");

    // Create LoadComponents - they consist of LoadCases or nested LoadCombination and Factors
    List<LoadComponent> components = new List<LoadComponent>();
    components.Add(new LoadComponent(case1.Id, 2.0));
    components.Add(new LoadComponent(case2.Id, 1.5));

    // Add components to combination
    loadCombination.SetComponents(components);

    // Create LoadUsages
    LoadUsage usage1 = LoadUsage.Create(document, "Frequent");
    LoadUsage usage2 = LoadUsage.Create(document, "Rare");

    if (usage1 == null || usage2 == null)
       throw new Exception("Create new load usage failed.");

    // Add load usages to combination
    loadCombination.SetUsageIds(new List<ElementId>() {usage1.Id, usage2.Id});

    // Give the user some information
    TaskDialog.Show("Revit", string.Format("Load Combination ID='{0}' created successfully.", loadCombination.Id.IntegerValue));

    return loadCombination;
}
#endregion
Copy VB.NET
'#Region "Autodesk.Revit.DB.Structure.LoadCombination.SetUsageIds(System.Collections.Generic.IList{Autodesk.Revit.DB.ElementId})"
Private Function CreateLoadCombinationLoadCaseLoadUsageLoadNatureAndLoadComponent(document As Document) As LoadCombination

   ' Create a new load combination
   Dim loadCombination As LoadCombination = loadCombination.Create(document, "DL1 + RAIN1", LoadCombinationType.Combination, LoadCombinationState.Ultimate)
   If loadCombination Is Nothing Then
      Throw New Exception("Create new load combination failed.")
   End If

   ' Get all existing LoadCase
   Dim collector As New FilteredElementCollector(document)
   Dim collection As ICollection(Of Element) = collector.OfClass(GetType(LoadCase)).ToElements()

   ' Find LoadCase "DL1"
   Dim case1 As LoadCase = Nothing
   For Each e As Element In collection
      Dim loadCase As LoadCase = TryCast(e, LoadCase)
      If loadCase.Name Is "DL1" Then
         case1 = loadCase
         Exit For
      End If
   Next

   ' Get all existing LoadNature
   collector = New FilteredElementCollector(document)
   collection = collector.OfClass(GetType(LoadCase)).ToElements()

   ' Find LoadNature "Dead"
   Dim nature1 As LoadNature = Nothing
   For Each e As Element In collection
      Dim loadNature As LoadNature = TryCast(e, LoadNature)
      If loadNature.Name Is "Dead" Then
         nature1 = loadNature
         Exit For
      End If
   Next

   ' Create LoadNature "Dead" if not exist
   If nature1 Is Nothing Then
      nature1 = LoadNature.Create(document, "Dead")
   End If

   ' Create LoadCase "DL1" if not exist
   If case1 Is Nothing Then
      case1 = LoadCase.Create(document, "DL1", nature1.Id, LoadNatureCategory.Dead)
   End If

   ' Create LoadNature "Rain"
   Dim nature2 As LoadNature = LoadNature.Create(document, "Rain")
   If nature2 Is Nothing Then
      Throw New Exception("Create new load nature failed.")
   End If

   ' Create LoadCase "RAIN1"
   Dim case2 As LoadCase = LoadCase.Create(document, "RAIN1", nature2.Id, LoadNatureCategory.Snow)
   If case1 Is Nothing Or case2 Is Nothing Then
      Throw New Exception("Create new load case failed.")
   End If

   ' Create LoadComponents - they consist of LoadCases or nested LoadCombination and Factors
   Dim components As List(Of LoadComponent) = New List(Of LoadComponent)()
   components.Add(New LoadComponent(case1.Id, 2.0))
   components.Add(New LoadComponent(case2.Id, 1.5))

   ' Add components to combination
   loadCombination.SetComponents(components)

   ' Create LoadUsages
   Dim usage1 As LoadUsage = LoadUsage.Create(document, "Frequent")
   Dim usage2 As LoadUsage = LoadUsage.Create(document, "Rare")

   If usage1 Is Nothing Or usage2 Is Nothing Then
      Throw New Exception("Create new load usage failed.")
   End If

   ' Add load usages to combination
   loadCombination.SetUsageIds(New List(Of ElementId) From {usage1.Id, usage2.Id})

   ' Give the user some information
   TaskDialog.Show("Revit", String.Format("Load Combination ID='{0}' created successfully.", loadCombination.Id.IntegerValue))

   Return loadCombination
End Function
'#End Region

Exceptions

Exception Condition
Autodesk.Revit.Exceptions ArgumentNullException A non-optional argument was NULL

See Also