AddAssociation Method


Adds a new association between an analytical element and a physical element.

Namespace: Autodesk.Revit.DB.Structure
Assembly: RevitAPI (in RevitAPI.dll) Version: 24.0.0.0 (24.0.0.0)
Since:  2023

Syntax

C#
public void AddAssociation(
	ElementId analyticalElementId,
	ElementId physicalElementId
)
Visual Basic
Public Sub AddAssociation ( _
	analyticalElementId As ElementId, _
	physicalElementId As ElementId _
)
Visual C++
public:
void AddAssociation(
	ElementId^ analyticalElementId, 
	ElementId^ physicalElementId
)

Parameters

analyticalElementId
Type: Autodesk.Revit.DBElementId
Id of the analytical element.
physicalElementId
Type: Autodesk.Revit.DBElementId
Id of the physical element.

Remarks

The arguments must be ids of an analytical and of a physical element that don't have other associations, otherwise an exception is thrown. Physical element can have one of these categories:
  • Columns
  • Curtain Wall Panels
  • Floors
  • Generic Models
  • Mass
  • Parts
  • Railings
  • Ramps
  • Roofs
  • Stairs
  • Structural Columns
  • Structural Foundation
  • Structural Framing
  • Structural Trusses
  • Structural Beam System
  • Walls
Analytical element can have one of these categories:
  • Analytical Member
  • Analytical Panel

Examples

CopyC#
using (Transaction trans = new Transaction(doc, "AddAssociationBetweenPhysicalAndAnalyticalElements"))
{
   trans.Start();

   ElementId idAnalyticalElem = GetSelectedObject(activeDoc, "Please select analytical element");
   ElementId idPhysicalElem = GetSelectedObject(activeDoc, "Please select physical element");

   //gets the AnalyticalToPhysicalAssociationManager for the current document
   AnalyticalToPhysicalAssociationManager analyticalToPhysicalManager = AnalyticalToPhysicalAssociationManager.GetAnalyticalToPhysicalAssociationManager(doc);
   if (analyticalToPhysicalManager == null)
      return Result.Failed;

   //creates a new association between physical and analytical selected elements
   analyticalToPhysicalManager.AddAssociation(idAnalyticalElem, idPhysicalElem);

   trans.Commit();
CopyVB.NET
Using trans As Transaction = New Transaction(doc, "AddAssociationBetweenPhysicalAndAnalyticalElements")
    trans.Start()
    Dim idAnalyticalElem = GetSelectedObject(activeDoc, "Please select analytical element")
    Dim idPhysicalElem = GetSelectedObject(activeDoc, "Please select physical element")

    'gets the AnalyticalToPhysicalAssociationManager for the current document
    Dim analyticalToPhysicalManager = AnalyticalToPhysicalAssociationManager.GetAnalyticalToPhysicalAssociationManager(doc)
    If analyticalToPhysicalManager Is Nothing Then Return Result.Failed

    'creates a new association between physical and analytical selected elements
    analyticalToPhysicalManager.AddAssociation(idAnalyticalElem, idPhysicalElem)
    trans.Commit()
CopyVB.NET
Using trans As Transaction = New Transaction(doc, "AddAssociationBetweenPhysicalAndAnalyticalElements")
    trans.Start()
    Dim idAnalyticalElem = GetSelectedObject(activeDoc, "Please select analytical element")
    Dim idPhysicalElem = GetSelectedObject(activeDoc, "Please select physical element")

    'gets the AnalyticalToPhysicalAssociationManager for the current document
    Dim analyticalToPhysicalManager = AnalyticalToPhysicalAssociationManager.GetAnalyticalToPhysicalAssociationManager(doc)
    If analyticalToPhysicalManager Is Nothing Then Return Result.Failed

    'creates a new association between physical and analytical selected elements
    analyticalToPhysicalManager.AddAssociation(idAnalyticalElem, idPhysicalElem)
    trans.Commit()

Exceptions

ExceptionCondition
Autodesk.Revit.ExceptionsArgumentException Analytical id is not valid or has already defined another association. -or- Physical id is not valid or has already defined another association.
Autodesk.Revit.ExceptionsArgumentNullException A non-optional argument was null

See Also

ArchiLabs Desktop

Put AI to work inside Revit.

Give Desktop your instructions and project files to build Revit families, update model elements, and create views and schedules. Works directly in Revit and AutoCAD.

Explore Desktop →