Project Functions
These functions are used to manage a project.
| Function | Versions | Description |
|---|---|---|
open | 2.2+ | Opens an EPANET input file & reads in network data. |
openX | 2.3+ | Opens an EPANET input file in lenient mode (errors allowed). |
close | 2.2+ | Closes a project and frees all of its memory. |
runProject | 2.2+ | Runs a complete EPANET simulation. |
init | 2.2+ | Initializes an EPANET project. |
getCount | 2.2+ | Retrieves the number of objects of a given type in a project. |
getTitle | 2.2+ | Retrieves the title lines of the project. |
setTitle | 2.2+ | Sets the title lines of the project. |
saveInpFile | 2.2+ | Saves a project’s data to an EPANET-formatted text file. |
getComment | 2.2+ | Retrieves a descriptive comment assigned to an object. |
setComment | 2.2+ | Assigns a descriptive comment to an object. |
getTag | 2.3+ | Retrieves a tag string assigned to a node or link. |
setTag | 2.3+ | Assigns a tag string to a node or link. |
runProject 2.2+
Section titled “runProject ”Runs a complete EPANET simulation.
runProject( inputFile: string, reportFile: string, outputFile: string): voidParameters
| Parameter | Type | Description |
|---|---|---|
| inputFile | string | the name of an existing EPANET-formatted input file. |
| reportFile | string | the name of a report file to be created (or "" if not needed) |
| outputFile | string | the name of a binary output file to be created (or "" if not needed) |
Future versions of the epanet-js library will include the ability to attach a callback function similar to the EN_runproject function in OWA-EPANET.
init 2.2+
Section titled “init ”Initializes an EPANET project.
init(rptFile: string, outFile: string, unitType: FlowUnits, headLosstype: HeadLossType): voidParameters
| Parameter | Type | Description |
|---|---|---|
| rptFile | string | the name of a report file to be created (or "" if not needed) |
| outFile | string | the name of a binary output file to be created (or "" if not needed). |
| unitType | FlowUnits | the choice of flow units (see FlowUnits) |
| headLosstype | HeadLossType | the choice of head loss formula (see HeadLossType) |
This function should be called immediately after a Project object is created if an EPANET-formatted input file will not be used to supply network data. If the project receives it’s network data from an input file then there is no need to call this function.
open 2.2+
Section titled “open ”Opens an EPANET input file & reads in network data.
open(inputFile: string, reportFile: string, outputFile: string): voidParameters
| Parameter | Type | Description |
|---|---|---|
| inputFile | string | the name of an existing EPANET-formatted input file. |
| reportFile | string | the name of a report file to be created (or "" if not needed). |
| outputFile | string | the name of a binary output file to be created (or "" if not needed). |
openX 2.3+
Section titled “openX ”Reads an EPANET input file with errors allowed. The strict open aborts on the first parse error; openX collects the errors so the project can still be inspected.
openX(inputFile: string, reportFile: string, binaryFile: string): voidParameters
| Parameter | Type | Description |
|---|---|---|
| inputFile | string | the name of an existing EPANET-formatted input file. |
| reportFile | string | the name of a report file to be created (or "" if not needed). |
| binaryFile | string | the name of a binary output file to be created (or "" if not needed). |
getCount 2.2+
Section titled “getCount ”Retrieves the number of objects of a given type in a project.
getCount(obj: CountType): numberParameters
| Parameter | Type | Description |
|---|---|---|
| obj | CountType | a type of object to count. (see CountType) |
Returns
Number
The number of objects of the specified type
getTitle 2.2+
Section titled “getTitle ”Retrieves the title lines of the project.
getTitle(): { line1: string; line2: string; line3: string }Returns
Object
{ line1: string; line2: string; line3: string;}| Property | Type | Description |
|---|---|---|
| line1 | string | first title line. |
| line2 | string | second title line. |
| line3 | string | third title line. |
setTitle 2.2+
Section titled “setTitle ”Sets the title lines of the project.
setTitle(line1: string, line2: string, line3: string): voidParameters
| Parameter | Type | Description |
|---|---|---|
| line1 | string | first title line. |
| line2 | string | second title line. |
| line3 | string | third title line. |
saveInpFile 2.2+
Section titled “saveInpFile ”Saves a project’s data to an EPANET-formatted text file.
saveInpFile(filename: string): voidParameters
| Parameter | Type | Description |
|---|---|---|
| filename | string | the name of the file to create. |
close 2.2+
Section titled “close ”Closes a project and frees all of its memory.
close(): voidThis function clears all existing data from a project but does not delete the project, so it can be re-used with another set of network data.
getComment 2.2+
Section titled “getComment ”Retrieves a descriptive comment assigned to a node, link, time pattern or data curve.
getComment(objectType: ObjectType, index: number): stringParameters
| Parameter | Type | Description |
|---|---|---|
| objectType | ObjectType | one of ObjectType.Node, ObjectType.Link, ObjectType.TimePat or ObjectType.Curve (see ObjectType). |
| index | number | the object’s index (starting from 1). |
Returns
String
the comment assigned to the object.
setComment 2.2+
Section titled “setComment ”Assigns a descriptive comment to a node, link, time pattern or data curve.
setComment(objectType: ObjectType, index: number, comment: string): voidParameters
| Parameter | Type | Description |
|---|---|---|
| objectType | ObjectType | one of ObjectType.Node, ObjectType.Link, ObjectType.TimePat or ObjectType.Curve (see ObjectType). |
| index | number | the object’s index (starting from 1). |
| comment | string | the comment to assign. |
getTag 2.3+
Section titled “getTag ”Retrieves a tag string assigned to a node or link.
getTag(objectType: ObjectType, index: number): numberParameters
| Parameter | Type | Description |
|---|---|---|
| objectType | ObjectType | either ObjectType.Node or ObjectType.Link (see ObjectType). |
| index | number | the object’s index (starting from 1). |
setTag 2.3+
Section titled “setTag ”Assigns a tag string to a node or link.
setTag(objectType: ObjectType, index: number, tag: number): voidParameters
| Parameter | Type | Description |
|---|---|---|
| objectType | ObjectType | either ObjectType.Node or ObjectType.Link (see ObjectType). |
| index | number | the object’s index (starting from 1). |
| tag | number | the tag value to assign. |