Skip to content

Project Functions

These functions are used to manage a project.

FunctionVersionsDescription
open2.2+Opens an EPANET input file & reads in network data.
openX2.3+Opens an EPANET input file in lenient mode (errors allowed).
close2.2+Closes a project and frees all of its memory.
runProject2.2+Runs a complete EPANET simulation.
init2.2+Initializes an EPANET project.
getCount2.2+Retrieves the number of objects of a given type in a project.
getTitle2.2+Retrieves the title lines of the project.
setTitle2.2+Sets the title lines of the project.
saveInpFile2.2+Saves a project’s data to an EPANET-formatted text file.
getComment2.2+Retrieves a descriptive comment assigned to an object.
setComment2.2+Assigns a descriptive comment to an object.
getTag2.3+Retrieves a tag string assigned to a node or link.
setTag2.3+Assigns a tag string to a node or link.

Runs a complete EPANET simulation.

runProject(
inputFile: string,
reportFile: string,
outputFile: string
): void

Parameters

ParameterTypeDescription
inputFilestringthe name of an existing EPANET-formatted input file.
reportFilestringthe name of a report file to be created (or "" if not needed)
outputFilestringthe 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.


Initializes an EPANET project.

init(rptFile: string, outFile: string, unitType: FlowUnits, headLosstype: HeadLossType): void

Parameters

ParameterTypeDescription
rptFilestringthe name of a report file to be created (or "" if not needed)
outFilestringthe name of a binary output file to be created (or "" if not needed).
unitTypeFlowUnitsthe choice of flow units (see FlowUnits)
headLosstypeHeadLossTypethe 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.


Opens an EPANET input file & reads in network data.

open(inputFile: string, reportFile: string, outputFile: string): void

Parameters

ParameterTypeDescription
inputFilestringthe name of an existing EPANET-formatted input file.
reportFilestringthe name of a report file to be created (or "" if not needed).
outputFilestringthe name of a binary output file to be created (or "" if not needed).

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): void

Parameters

ParameterTypeDescription
inputFilestringthe name of an existing EPANET-formatted input file.
reportFilestringthe name of a report file to be created (or "" if not needed).
binaryFilestringthe name of a binary output file to be created (or "" if not needed).

Retrieves the number of objects of a given type in a project.

getCount(obj: CountType): number

Parameters

ParameterTypeDescription
objCountTypea type of object to count. (see CountType)

Returns

Number The number of objects of the specified type


Retrieves the title lines of the project.

getTitle(): { line1: string; line2: string; line3: string }

Returns

Object
{
line1: string;
line2: string;
line3: string;
}
PropertyTypeDescription
line1stringfirst title line.
line2stringsecond title line.
line3stringthird title line.

Sets the title lines of the project.

setTitle(line1: string, line2: string, line3: string): void

Parameters

ParameterTypeDescription
line1stringfirst title line.
line2stringsecond title line.
line3stringthird title line.

Saves a project’s data to an EPANET-formatted text file.

saveInpFile(filename: string): void

Parameters

ParameterTypeDescription
filenamestringthe name of the file to create.

Closes a project and frees all of its memory.

close(): void

This 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.


Retrieves a descriptive comment assigned to a node, link, time pattern or data curve.

getComment(objectType: ObjectType, index: number): string

Parameters

ParameterTypeDescription
objectTypeObjectTypeone of ObjectType.Node, ObjectType.Link, ObjectType.TimePat or ObjectType.Curve (see ObjectType).
indexnumberthe object’s index (starting from 1).

Returns

String the comment assigned to the object.


Assigns a descriptive comment to a node, link, time pattern or data curve.

setComment(objectType: ObjectType, index: number, comment: string): void

Parameters

ParameterTypeDescription
objectTypeObjectTypeone of ObjectType.Node, ObjectType.Link, ObjectType.TimePat or ObjectType.Curve (see ObjectType).
indexnumberthe object’s index (starting from 1).
commentstringthe comment to assign.

Retrieves a tag string assigned to a node or link.

getTag(objectType: ObjectType, index: number): number

Parameters

ParameterTypeDescription
objectTypeObjectTypeeither ObjectType.Node or ObjectType.Link (see ObjectType).
indexnumberthe object’s index (starting from 1).

Assigns a tag string to a node or link.

setTag(objectType: ObjectType, index: number, tag: number): void

Parameters

ParameterTypeDescription
objectTypeObjectTypeeither ObjectType.Node or ObjectType.Link (see ObjectType).
indexnumberthe object’s index (starting from 1).
tagnumberthe tag value to assign.