M

Wire.Create

Description:
Creates a new wire.
public static Wire Create(
	Document document,
	ElementId wireTypeId,
	ElementId viewId,
	WiringType wiringType,
	IList<XYZ> vertexPoints,
	Connector startConnectorTo,
	Connector endConnectorTo
)
  • document
    The document.
  • wireTypeId
    The id of the wire type of the newly created wire.
  • viewId
    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
    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.
    If the wiring type is WiringType.Chamfer, a polyline wire will be created connecting all the points.
  • IList<XYZ>
    vertexPoints
    The vertex point of the wire. If the startConnectorTo is nulla 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 nulla 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
    The connector to which the wire start point connects. If nulla 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
    The connector to which the wire end point connects. If nulla 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. The wire created.
// 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;
}