Application: PowerCircuit
Revit Platform: MEP
Revit Version: 2011.0
First Released For: 2009.0
Programming Language: C#
Skill Level: Beginning
Category: MEP
Type: ExternalCommand

Subject: Operate power circuits.
Summary: 
This sample shows how to operate power circuits.

Classes: 
Autodesk.Revit.UI.IExternalCommand
Autodesk.Revit.DB

Project Files: 
Command.cs
It contains the class Command which inherits from interface IExternalCommand and implements the Execute method.

CircuitOperationData.cs
Data class which stores the information for operating circuits.

CircuitOperationForm.cs
It contains a dialog which provides the options of operating circuits.

ElectricalSystemItem.cs
The class is used for displaying electrical systems in circuit selecting dialog. An electrical system item contains the name and id of an electrical system.

EditCircuitForm.cs
It contains a dialog which provides the options of editing circuits.

SelectCircuitForm.cs
It contains a dialog which let user select a circuit to operate.

Enum.cs
This file contains two Enumerations.
-	Operation enumeration lists the options to operate circuits.
-	EditOption enumeration lists the options to edit a circuit.

Description: 
This sample provides following functionalities.
-	Let user create a power circuit with selected elements. The elements should have unused electrical connectors within same voltage definition and with same pole numbers.
-	Let user edit a power circuit.
-	Let user add an element to a circuit. The element should have unused electrical connectors within same voltage definition and with same pole numbers as the circuit elements. 
-	Let user remove an element from the circuit.
-	Let user select a panel for a circuit. 
-	Let user disconnect panel from a circuit if the circuit has a panel。

Instructions: 
Open or new a Revit project and make sure needed electrical elements are placed. A sample project file PowerCircuit.rvt is available in the sample’s folder. Then execute the command.
1.	Create a power circuit
a.   Select elements which all have unused electrical connectors within same voltage definition and with same pole numbers in current project.
b.   Execute the command.
c.   Click the  button.
Expected result: A power circuit is created with the selected elements and highlighted. 
Note: 1. Currently in API there is no good way to check whether the connectors have the same voltage definition or pole numbers, therefore the sample skips validating this information and just provides message if creation fails. User must know clear whether the voltage and pole numbers of connectors of selected elements match with each other. 2. In this sample it is not allowed to create a power circuit with elements which are all lighting devices.

2.	Edit a power circuit.
a.	Select a power circuit or an element belongs to one or more circuits.
b.	Execute the command.
c.	Click the  button.
d.	If the selected element belongs to more than one power circuits, select a circuit from its circuits to edit in the “Select a Circuit” dialog. If not, go to next step.
e.	Choose an option to edit the circuit in the “Edit Circuit” dialog.
-	Click  button to add an element to the circuit. Then select an element which has unused electrical connectors within same voltage definition and with same pole numbers as the other circuit elements. For the same reason as Note in step 1, the sample just skips validating the voltage and pole numbers and provides message if creation fails.
Expected result: The selected element is added to the circuit and the circuit is highlighted.
-	Click  button to remove an element from the circuit. Then select the element to remove.
Expected result: The selected element is removed from the circuit and the circuit is highlighted. 
-	Click  button to select a panel for the circuit. The same as step 3.

3.	Select a panel for a circuit.
a.	Select a power circuit or an element belongs to one or more circuits. 
b.	Execute the command.
c.	Click  button to select a panel for the circuit.
d.	If the selected element belongs to more than one power circuits, select a circuit from its circuits to edit in the “Select a Circuit” dialog. If not, go to next step.
e.	Select a panel to assign it to the circuit. The panel must be assigned to distribution system with the same voltage definition as the other circuit elements.  Also the panel must have same pole numbers as the other circuit elements. For the same reason as Note in step 1, the sample just skips validating the voltage and pole numbers and provides message if creation fails. 
Expected result: The selected panel is assigned to the circuit and the circuit is highlighted.
 
4.	Disconnect the panel from a circuit.
a.	Select a power circuit or an element belongs to one or more circuits. 
b.	Execute the command.
c.	Click  button to disconnect the panel from the circuit.
d.	If the selected element belongs to more than one power circuits, select a circuit from its circuits to edit in the “Select a Circuit” dialog. If not, go to next step.
Expected result: The panel of the circuit is removed from the circuit and the circuit is highlighted.