Systems

Systems

Creating a new system

New piping and mechanical systems can be created using the Revit API. 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 30-4: 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;
ElementSet selection = document.Selection.Elements;
foreach (Element e in selection)
{
        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 = document.Create.NewMechanicalSystem(baseConnector, connectorSet, DuctSystemType.SupplyAir);
}