Creates a new wire.
Namespace: Autodesk.Revit.DB.Electrical
Assembly: RevitAPI (in RevitAPI.dll) Version: 24.0.0.0 (24.0.0.0)
Since: 2015
Syntax
C# |
---|
|
Visual Basic |
---|
|
Visual C++ |
---|
|
Parameters
- document
- Type: Autodesk.Revit.DBDocument
The document.
- wireTypeId
- Type: Autodesk.Revit.DBElementId
The id of the wire type of the newly created wire.
- viewId
- Type: Autodesk.Revit.DBElementId
The view in which the wire is to be visible. This must be the id of a floor plan or reflected ceiling plan view.
- wiringType
- Type: Autodesk.Revit.DB.ElectricalWiringType
Specifiies the wiring type for the newly created wire. The shape of the wire is determined by this value and the total number of points supplied via the vertexPoints and endpoint connectors. If the wiring type is WiringType.Arc:- If there are 2 total points supplied, the wire is a straight-line wire.
- If there are 3 total points supplied, the wire is a circular arc wire.
- If there are 4 or more points, the wire is a spline wire.
- vertexPoints
- Type: System.Collections.GenericIListXYZ
The vertex point of the wire. If the startConnectorTo is a null reference (Nothing in Visual Basic), the first vertex of the vertexPoints will be the start point, otherwise, the start connector origin will be the start point. If the endConnectorTo is a null reference (Nothing in Visual Basic), the last vertex of the vertexPoints will be the end point, otherwise, the end connector origin will be the end point.
- startConnectorTo
- Type: Autodesk.Revit.DBConnector
The connector to which the wire start point connects. If a null reference (Nothing in Visual Basic), the start point connects to no existing connector. If set with a connector, the connector's origin will be added to the wire's vertices as the start point.
- endConnectorTo
- Type: Autodesk.Revit.DBConnector
The connector to which the wire end point connects. If a null reference (Nothing in Visual Basic), the end point connects to no existing connector. If set with a connector, the connector's origin will be added to the wire's vertices as the end point.
Return Value
The wire created.Examples

// Create an unconnected straight line wire between two points
public Wire CreateWire(Document document)
{
Wire wire = null;
FilteredElementCollector collector = new FilteredElementCollector(document);
IList<Element> wireTypes = collector.OfCategory(BuiltInCategory.OST_Wire).WhereElementIsElementType().ToElements();
WireType wireType = wireTypes.First() as WireType;
if (wireType != null)
{
IList<XYZ> wireVertices = new List<XYZ>();
wireVertices.Add(new XYZ(0, 0, 0));
wireVertices.Add(new XYZ(2, 0, 0));
wire = Wire.Create(document, wireType.Id, document.ActiveView.Id, WiringType.Arc, wireVertices, null, null);
}
return wire;
}

' Create an unconnected straight line wire between two points
Public Function CreateWire(document As Document) As Wire
Dim wire__1 As Wire = Nothing
Dim collector As New FilteredElementCollector(document)
Dim wireTypes As IList(Of Element) = collector.OfCategory(BuiltInCategory.OST_Wire).WhereElementIsElementType().ToElements()
Dim wireType As WireType = TryCast(wireTypes.First(), WireType)
If wireType IsNot Nothing Then
Dim wireVertices As IList(Of XYZ) = New List(Of XYZ)()
wireVertices.Add(New XYZ(0, 0, 0))
wireVertices.Add(New XYZ(2, 0, 0))
wire__1 = Wire.Create(document, wireType.Id, document.ActiveView.Id, WiringType.Arc, wireVertices, Nothing, _
Nothing)
End If
Return wire__1
End Function
Exceptions
Exception | Condition |
---|---|
Autodesk.Revit.ExceptionsArgumentException | wireTypeId is not a valid WireType id. -or- viewId does not represent a view valid for a Wire element. Either a floor plan or reflected ceiling plan is expected. -or- vertexPoints is not valid, because one or more points are coincident by comparing the X and Y of the points, or there are not at least two points including the connectors. -or- startConnectorTo cannot be connected to a wire, as it is not an electrical connector. -or- endConnectorTo cannot be connected to a wire, as it is not an electrical connector. |
Autodesk.Revit.ExceptionsArgumentNullException | A non-optional argument was null |
Autodesk.Revit.ExceptionsArgumentOutOfRangeException | A value passed for an enumeration argument is not a member of that enumeration |
Autodesk.Revit.ExceptionsDisabledDisciplineException | None of the following disciplines is enabled: Mechanical Electrical Piping. |