Creating Systems

Create electrical, mechanical and piping systems.

Create() method

MechanicalSystem and PipingSystem have static overloaded Create() methods to create new mechanical or piping systems. This is the preferred method for creating new MEP Systems. The simplest Create() overload for both classes creates a new system in a given document with a given type Id (which should be the Id for a DuctSystemType for a MechanicalSystem or the Id of a PipeSystemType for a PipingSystem. Both classes have a second Create() overload that also takes a name for the system. Once created, elements can be added to the system using the MEPSystem.Add() method.

Creating systems from Creation.Document class

MechanicalSystem and PipingSystem can also be created from the Creation.Document class using NewMechanicalSystem() and NewPipingSystem() respectively.

Electrical systems can currently only be created using the Creation.Document.NewElectricalSystem() method, which has two overloads. One creates a new ElectricalSystem element from an unused Connector while the other overload creates a new ElectricalSystem element from a set of electrical components. Both overloads require an ElectricalSystemType.

NewPipingSystem() and NewMechanicalSystem() both take a Connector that is the base equipment connector, such as a hot water heater for a piping system, or a fan for a mechanical system. They also take a ConnectorSet of connectors that will be added to the system, such as faucets on sinks in a piping system. The last piece of information required to create a new system is either a PipeSystemType for NewPipingSystem() or a DuctSystemType for NewMechanicalSystem().

In the following sample, a new SupplyAir duct system is created from a selected piece of mechanical equipment (such as a fan) and all selected Air Terminals.

Code Region: Creating a new mechanical system

// create a connector set for new mechanical system
ConnectorSet connectorSet = new ConnectorSet();
// Base equipment connector
Connector baseConnector = null;

// Select a Parallel Fan Powered VAV and some Supply Diffusers
// prior to running this example
ConnectorSetIterator csi = null;
ICollection<ElementId> selectedIds = uiDocument.Selection.GetElementIds();
Document document = uiDocument.Document;
foreach (ElementId id in selectedIds)
{
    Element e = document.GetElement(id);
    if (e is FamilyInstance)
    {
        FamilyInstance fi = e as FamilyInstance;
        Family family = fi.Symbol.Family;
        // Assume the selected Mechanical Equipment is the base equipment for new system
        if (family.FamilyCategory.Name == "Mechanical Equipment")
        {
            //Find the "Out" and "SupplyAir" connector on the base equipment
            if (null != fi.MEPModel)
            {
                csi = fi.MEPModel.ConnectorManager.Connectors.ForwardIterator();
                while (csi.MoveNext())
                {
                    Connector conn = csi.Current as Connector;
                    if (conn.Direction == FlowDirectionType.Out && conn.DuctSystemType == DuctSystemType.SupplyAir)
                    {
                        baseConnector = conn;
                        break;
                    }
                }
            }
        }
        else if (family.FamilyCategory.Name == "Air Terminals")
        {
            // add selected Air Terminals to connector set for new mechanical system
            csi = fi.MEPModel.ConnectorManager.Connectors.ForwardIterator();
            csi.MoveNext();
            connectorSet.Insert(csi.Current as Connector);
        }
    }
}

MechanicalSystem mechanicalSys = null;
if (null != baseConnector && connectorSet.Size > 0)
{
    // create a new SupplyAir mechanical system
    mechanicalSys = uiDocument.Document.Create.NewMechanicalSystem(baseConnector, connectorSet, DuctSystemType.SupplyAir);
}