Skip to content

Network Link Functions

These functions are used for working with network links.

FunctionDescription
addLinkAdds a new link to a project.
deleteLinkDeletes a link from the project.
getLinkIndexGets the index of a link given its ID name.
getLinkIdGets the ID name of a link given its index.
setLinkIdChanges the ID name of a link.
getLinkTypeRetrieves a link’s type.
setLinkTypeChanges a link’s type.
getLinkNodesGets the indexes of a link’s start- and end-nodes.
setLinkNodesSets the indexes of a link’s start- and end-nodes.
getLinkValueRetrieves a property value for a link.
setLinkValueSets a property value for a link.
setPipeDataSets a group of properties for a pipe link.
getPumpTypeRetrieves the type of head curve used by a pump.
getHeadCurveIndexRetrieves the curve assigned to a pump’s head curve.
setHeadCurveIndexAssigns a curve to a pump’s head curve.
getVertexCountRetrieves the number of internal vertex points assigned to a link.
getVertexRetrieves the coordinate’s of a vertex point assigned to a link.
setVerticesAssigns a set of internal vertex points to a link.

Adds a new link to a project.

addLink(id: string, linkType: LinkType, fromNode: string, toNode: string): number;

Parameters

ParameterTypeDescription
idstringthe ID name of the link to be added.
linkTypeLinkTypeThe type of link being added (see LinkType)
fromNodestringThe ID name of the link’s starting node.
toNodestringThe ID name of the link’s ending node.

Returns

Number the index of the newly added link.

A new pipe is assigned a diameter of 10 inches (254 mm) and a length of 330 feet (~ 100 meters). Its roughness coefficient depends on the head loss formula in effect (see HeadLossType) as follows:

  • Hazen-Williams formula: 130
  • Darcy-Weisbach formula: 0.5 millifeet (0.15 mm) *Chezy-Manning formula: 0.01

All other pipe properties are set to 0.

A new pump has a status of LinkStatusType.Open, a speed setting of 1, and has no pump curve or power rating assigned to it.

A new valve has a diameter of 10 inches (254 mm) and all other properties set to 0.

See LinkProperty.


Deletes a link from the project.

deleteLink(index: number, actionCode: ActionCodeType): void;

Parameters

ParameterTypeDescription
indexnumberthe index of the link to be deleted.
actionCodeActionCodeTypeThe action taken if any control contains the link.

If actionCode is ActionCodeType.Unconditional then the link and all simple and rule-based controls that contain it are deleted. If set to ActionCodeType.Conditional then the link is not deleted if it appears in any control and error 261 is returned.


Gets the index of a link given its ID name.

getLinkIndex(id: string): number;

Parameters

ParameterTypeDescription
idstringa link’s ID name.

Returns

Number the link’s index (starting from 1).


Gets the ID name of a link given its index.

getLinkId(index: number): string;

Parameters

ParameterTypeDescription
indexnumbera link’s index (starting from 1).

Returns

string The link’s ID name.


Changes the ID name of a link.

setLinkId(index: number, newid: string): void;

Parameters

ParameterTypeDescription
indexnumbera link’s index (starting from 1).
newidstringthe new ID name for the link.

Retrieves a link’s type.

getLinkType(index: number): LinkType;

Parameters

ParameterTypeDescription
indexnumbera link’s index (starting from 1).

Returns

LinkType the link’s type (see LinkType).


Changes a link’s type.

setLinkType(index: number, linkType: LinkType, actionCode: ActionCodeType): number;

Parameters

ParameterTypeDescription
indexnumberthe link’s index
linkTypeLinkTypethe new type to change the link to (see LinkType).
actionCodeActionCodeTypethe action taken if any controls contain the link.

Returns

Number the link’s new index after the type change.

If actionCode is ActionCodeType.Unconditional then all simple and rule-based controls that contain the link are deleted when the link’s type is changed. If set to ActionCodeType.Conditional then the type change is cancelled if the link appears in any control and error 261 is returned.


Gets the indexes of a link’s start- and end-nodes.

getLinkNodes(index: number): {
node1: number;
node2: number;
};

Parameters

ParameterTypeDescription
indexnumbera link’s index (starting from 1).

Returns

Object

{
node1: number;
node2: number;
}
PropertyTypeDescription
node1numberthe index of the link’s start node (starting from 1).
node2numberthe index of the link’s end node (starting from 1).

Sets the indexes of a link’s start- and end-nodes.

setLinkNodes(index: number, node1: number, node2: number): void;

Parameters

ParameterTypeDescription
indexnumbera link’s index (starting from 1).
node1numberThe index of the link’s start node (starting from 1).
node2numberThe index of the link’s end node (starting from 1).

Retrieves a property value for a link.

getLinkValue(index: number, property: LinkProperty): number;

Parameters

ParameterTypeDescription
indexnumbera link’s index (starting from 1).
propertyLinkPropertythe property to retrieve (see LinkProperty).

Returns

Number the current value of the property.

Values are returned in units that depend on the units used for flow rate (see Measurement Units).


Sets a property value for a link.

setLinkValue(index: number, property: number, value: number): void;

Parameters

ParameterTypeDescription
indexnumbera link’s index.
propertynumberthe property to set (see LinkProperty).
valuenumberthe new value for the property.

Values are in units that depend on the units used for flow rate (see Measurement Units).


Sets a group of properties for a pipe link.

setPipeData(index: number, length: number, diam: number, rough: number, mloss: number): void;

Parameters

ParameterTypeDescription
indexnumberthe index of a pipe link (starting from 1).
lengthnumberthe pipe’s length.
diamnumberthe pipe’s diameter.
roughnumberthe pipe’s roughness coefficient.
mlossnumberthe pipe’s minor loss coefficient.

These properties have units that depend on the units used for flow rate (see Measurement Units).


Retrieves the type of head curve used by a pump.

getPumpType(index: number): PumpType;

Parameters

ParameterTypeDescription
indexnumberthe index of a pump link (starting from 1).

Returns

PumpType the type of head curve used by the pump (see PumpType).


Retrieves the curve assigned to a pump’s head curve.

getHeadCurveIndex(linkIndex: number): number;

Parameters

ParameterTypeDescription
linkIndexnumberthe index of a pump link (starting from 1).

Returns

Number the index of the curve assigned to the pump’s head curve.


Assigns a curve to a pump’s head curve.

setHeadCurveIndex(linkIndex: number, curveIndex: number): void;

Parameters

ParameterTypeDescription
linkIndexnumberthe index of a pump link (starting from 1).
curveIndexnumberthe index of a curve to be assigned as the pump’s head curve.

Retrieves the number of internal vertex points assigned to a link.

getVertexCount(index: number): number;

Parameters

ParameterTypeDescription
indexnumbera link’s index (starting from 1).

Returns

Number the number of vertex points that describe the link’s shape.


Retrieves the coordinate’s of a vertex point assigned to a link.

getVertex(index: number, vertex: number): {
x: number;
y: number;
};

Parameters

ParameterTypeDescription
indexnumbera link’s index (starting from 1).
vertexnumbera vertex point index (starting from 1).

Returns

Object

{
x: number;
y: number;
}
PropertyTypeDescription
xnumberthe vertex’s X-coordinate value.
ynumberthe vertex’s Y-coordinate value.

Assigns a set of internal vertex points to a link.

setVertices(index: number, x: number[], y: number[]): void;

Parameters

ParameterTypeDescription
indexnumbera link’s index (starting from 1).
xNumber[]an array of X-coordinates for the vertex points.
yNumber[]an array of Y-coordinates for the vertex points.

Replaces any existing vertices previously assigned to the link.