AnalyticalLinkCreate Method |
Creates a new instance of a AnalyticalLink element between two Hubs.
Namespace: Autodesk.Revit.DB.StructureAssembly: RevitAPI (in RevitAPI.dll) Version: 25.0.0.0 (25.0.0.0)
Syntaxpublic static AnalyticalLink Create(
Document doc,
ElementId type,
ElementId startHubId,
ElementId endHubId
)
Public Shared Function Create (
doc As Document,
type As ElementId,
startHubId As ElementId,
endHubId As ElementId
) As AnalyticalLink
public:
static AnalyticalLink^ Create(
Document^ doc,
ElementId^ type,
ElementId^ startHubId,
ElementId^ endHubId
)
static member Create :
doc : Document *
type : ElementId *
startHubId : ElementId *
endHubId : ElementId -> AnalyticalLink
Parameters
- doc Document
-
Document to which new AnalyticalLink should be added.
- type ElementId
-
AnalyticalLinkType for the new AnalyticalLink.
- startHubId ElementId
-
Hub at start of AnalyticalLink.
- endHubId ElementId
-
Hub at end of AnalyticalLink.
Return Value
AnalyticalLink
The newly created AnalyticalLink instance.
ExceptionsException | Condition |
---|
ArgumentException |
startHubId is not a valid Hub ID for an AnalyticalLink element.
-or-
endHubId is not a valid Hub ID for an AnalyticalLink element.
-or-
Thrown if startHubId or endHubId do not represent ids of Hubs.
-or-
Thrown if startHubId == endHubId.
-or-
Thrown if type does not represent an id of an AnalyticalLinkType.
|
ArgumentNullException |
A non-optional argument was null
|
Examplepublic void CreateLink(Document doc, AnalyticalElement fi1, AnalyticalElement fi2)
{
FilteredElementCollector hubCollector = new FilteredElementCollector(doc);
hubCollector.OfClass(typeof(Hub));
ICollection<Element> allHubs = hubCollector.ToElements();
FilteredElementCollector linktypeCollector = new FilteredElementCollector(doc);
linktypeCollector.OfClass(typeof(AnalyticalLinkType));
ElementId firstLinkType = linktypeCollector.ToElementIds().First();
ElementId startHubId = GetHub(fi1.Id, allHubs);
ElementId endHubId = GetHub(fi2.Id, allHubs);
Transaction tran = new Transaction(doc, "Create Link");
tran.Start();
AnalyticalLink createdLink = AnalyticalLink.Create(doc, firstLinkType, startHubId, endHubId);
tran.Commit();
}
private ElementId GetHub(ElementId hostId, ICollection<Element> allHubs)
{
foreach (Element ehub in allHubs)
{
Hub hub = ehub as Hub;
ConnectorManager manager = hub.GetHubConnectorManager();
ConnectorSet connectors = manager.Connectors;
foreach (Connector connector in connectors)
{
ConnectorSet refConnectors = connector.AllRefs;
foreach (Connector refConnector in refConnectors)
{
if (refConnector.Owner.Id == hostId)
{
return hub.Id;
}
}
}
}
return ElementId.InvalidElementId;
}
Public Sub CreateLink(doc As Document, fi1 As AnalyticalElement, fi2 As AnalyticalElement)
Dim hubCollector As New FilteredElementCollector(doc)
hubCollector.OfClass(GetType(Hub))
Dim allHubs As ICollection(Of Element) = hubCollector.ToElements()
Dim linktypeCollector As New FilteredElementCollector(doc)
linktypeCollector.OfClass(GetType(AnalyticalLinkType))
Dim firstLinkType As ElementId = linktypeCollector.ToElementIds().First()
Dim startHubId As ElementId = GetHub(fi1.Id, allHubs)
Dim endHubId As ElementId = GetHub(fi2.Id, allHubs)
Dim tran As New Transaction(doc, "Create Link")
tran.Start()
Dim createdLink As AnalyticalLink = AnalyticalLink.Create(doc, firstLinkType, startHubId, endHubId)
tran.Commit()
End Sub
Private Function GetHub(hostId As ElementId, allHubs As ICollection(Of Element)) As ElementId
For Each ehub As Element In allHubs
Dim hub As Hub = TryCast(ehub, Hub)
Dim manager As ConnectorManager = hub.GetHubConnectorManager()
Dim connectors As ConnectorSet = manager.Connectors
For Each connector As Connector In connectors
Dim refConnectors As ConnectorSet = connector.AllRefs
For Each refConnector As Connector In refConnectors
If refConnector.Owner.Id = hostId Then
Return hub.Id
End If
Next
Next
Next
Return ElementId.InvalidElementId
End Function
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
See Also