Skip to content

Network Link Functions

These functions are used for working with network links.

Function Description
addLink Adds a new link to a project.
deleteLink Deletes a link from the project.
getLinkIndex Gets the index of a link given its ID name.
getLinkId Gets the ID name of a link given its index.
setLinkId Changes the ID name of a link.
getLinkType Retrieves a link's type.
setLinkType Changes a link's type.
getLinkNodes Gets the indexes of a link's start- and end-nodes.
setLinkNodes Sets the indexes of a link's start- and end-nodes.
getLinkValue Retrieves a property value for a link.
setLinkValue Sets a property value for a link.
setPipeData Sets a group of properties for a pipe link.
getPumpType Retrieves the type of head curve used by a pump.
getHeadCurveIndex Retrieves the curve assigned to a pump's head curve.
setHeadCurveIndex Assigns a curve to a pump's head curve.
getVertexCount Retrieves the number of internal vertex points assigned to a link.
getVertex Retrieves the coordinate's of a vertex point assigned to a link.
setVertices Assigns 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

Parameter Type Description
id string the ID name of the link to be added.
linkType LinkType The type of link being added (see LinkType)
fromNode string The ID name of the link's starting node.
toNode string The 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

Parameter Type Description
index number the index of the link to be deleted.
actionCode ActionCodeType The 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.


getLinkIndex

Gets the index of a link given its ID name.

getLinkIndex(id: string): number;

Parameters

Parameter Type Description
id string a link's ID name.

Returns

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


getLinkId

Gets the ID name of a link given its index.

getLinkId(index: number): string;

Parameters

Parameter Type Description
index number a link's index (starting from 1).

Returns

string The link's ID name.


setLinkId

Changes the ID name of a link.

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

Parameters

Parameter Type Description
index number a link's index (starting from 1).
newid string the new ID name for the link.

getLinkType

Retrieves a link's type.

getLinkType(index: number): LinkType;

Parameters

Parameter Type Description
index number a link's index (starting from 1).

Returns

LinkType the link's type (see LinkType).


setLinkType

Changes a link's type.

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

Parameters

Parameter Type Description
index number the link's index
linkType LinkType the new type to change the link to (see LinkType).
actionCode ActionCodeType the 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.


getLinkNodes

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

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

Parameters

Parameter Type Description
index number a link's index (starting from 1).

Returns

Object

{
  node1: number;
  node2: number;
}
Property Type Description
node1 number the index of the link's start node (starting from 1).
node2 number the index of the link's end node (starting from 1).

setLinkNodes

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

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

Parameters

Parameter Type Description
index number a link's index (starting from 1).
node1 number The index of the link's start node (starting from 1).
node2 number The index of the link's end node (starting from 1).

getLinkValue

Retrieves a property value for a link.

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

Parameters

Parameter Type Description
index number a link's index (starting from 1).
property LinkProperty the 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).


setLinkValue

Sets a property value for a link.

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

Parameters

Parameter Type Description
index number a link's index.
property number the property to set (see LinkProperty).
value number the new value for the property.

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


setPipeData

Sets a group of properties for a pipe link.

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

Parameters

Parameter Type Description
index number the index of a pipe link (starting from 1).
length number the pipe's length.
diam number the pipe's diameter.
rough number the pipe's roughness coefficient.
mloss number the pipe's minor loss coefficient.

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


getPumpType

Retrieves the type of head curve used by a pump.

getPumpType(index: number): PumpType;

Parameters

Parameter Type Description
index number the index of a pump link (starting from 1).

Returns

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


getHeadCurveIndex

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

getHeadCurveIndex(linkIndex: number): number;

Parameters

Parameter Type Description
linkIndex number the index of a pump link (starting from 1).

Returns

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


setHeadCurveIndex

Assigns a curve to a pump's head curve.

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

Parameters

Parameter Type Description
linkIndex number the index of a pump link (starting from 1).
curveIndex number the index of a curve to be assigned as the pump's head curve.

getVertexCount

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

getVertexCount(index: number): number;

Parameters

Parameter Type Description
index number a link's index (starting from 1).

Returns

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


getVertex

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

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

Parameters

Parameter Type Description
index number a link's index (starting from 1).
vertex number a vertex point index (starting from 1).

Returns

Object

{
  x: number;
  y: number;
}
Property Type Description
x number the vertex's X-coordinate value.
y number the vertex's Y-coordinate value.

setVertices

Assigns a set of internal vertex points to a link.

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

Parameters

Parameter Type Description
index number a link's index (starting from 1).
x Number[] an array of X-coordinates for the vertex points.
y Number[] an array of Y-coordinates for the vertex points.

Replaces any existing vertices previously assigned to the link.