WEAPBranch and WEAPBranches API Classes

The WEAPBranch class represents a specific Branch on the data tree (e.g., \Demand Sites\South City ), whereas WEAPBranches is a collection of all child Branches for a specified Branch (e.g., all child branches of \Demand Sites ).

You can get access to a WEAPBranches collection in two different ways:

  1. The Branches property of the WEAPApplication class, giving all branches, WEAP.Branches

  2. From the Children property of a WEAPBranch, e.g., WEAP.Branch("\Demand Sites").Children

You can get access to a WEAPBranch in three different ways:

  1. WEAPApplication.Branch(FullBranchPath), e.g., WEAP.Branch("\Demand Sites\South City")

  2. WEAPBranches(Index), specifying a number from 1 to WEAPBranches.Count, e.g., WEAP.Branch("\Demand Sites").Children(1)

  3. Iterate through the collection of all branches, e.g., For Each Branch in WEAP.Branches

WEAPBranches Properties and Methods

Example (using VB script)

Choose(Title, Default, MaxChoices, UseFullPath): Ask user to choose items from the branch collection.  If the optional parameter Default is given, it has the comma-separated list of items that are initially checked.  If the optional parameter MaxChoices is given, it has the maximum number of choices permitted.  If not given or zero, there is no maximum.  If the optional parameter UseFullPath is given, the branch list shown to the user will use the full branch path (e.g., \Demand Sites\South City) instead of the short name (e.g., South City).  The return value is another WEAPBrances collection containing the selected items.  If none were selected, the collection will be empty.  Note: because it returns a WEAPBranches collection, you can string together several in one statement, e.g., WEAP.DemandSites.FilterByTag("South").FilterByScenario("Not:Current Accounts").Choose("Select Demand Sites to set active in Current Accounts").NameList

' Ask the user which demand sites to activate

FOR EACH Br IN WEAP.DemandSites.FilterByScenario("Not:Current Accounts").Choose("Select Demand Sites to set active in Current Accounts")

  Br.ActiveInCurrentAccounts = TRUE

NEXT

' Ask user to choose one demand site

DS = WEAP.DemandSites.Choose("Select one Demand Site to process", "", 1)

Count: Get the number of WEAP branches in the collection. Read only.

FOR i = 1 to WEAP.Branch("\Demand Sites").Children.Count
  PRINT WEAP.Branch("\Demand Sites").Children(i).Name
NEXT

' Note: The following is equivalent and easier to understand:

FOR EACH Br IN WEAP.Branch("\Demand Sites").Children
PRINT Br.Name
NEXT

FilterByName(Names): Gets subset of branches in the collection whose name matches one of the names in Names parameter (separated by commas).  To allow partial matches, prefix with "Partial:", e.g., "Partial:Corn".  To find branches that do NOT match, prefix with "Not:", .e.g., "Not:Forest".  Returns a WEAPBranches collection.  Read only.  Note: because it returns a WEAPBranches collection, you can string together several in one statement, e.g., WEAP.Catchments.FilterByName("Partial:Fresno").FilterByScenario("Not:Current Accounts").Choose("Select Catchments to set active in Current Accounts")

' Set Soil Water Capacity to 1000 mm for all Forest and Grassland branches

FOR EACH Br IN WEAP.Branch("\Demand Sites").Descendants.FilterByName("Forest,Grassland")

  IF Br.VariableExists("Soil Water Capacity") THEN

    Br.Variable("Soil Water Capacity").Expression = 1000

  END IF

NEXT    

' Set Soil Water Capacity to 250 mm for all non Forest and Grassland branches

FOR EACH Br IN WEAP.Branch("\Demand Sites").Descendants.FilterByName("Not:Forest,Grassland")

  IF Br.VariableExists("Soil Water Capacity") THEN

    Br.Variable("Soil Water Capacity").Expression = 250

  END IF

NEXT

FilterByScenario(Scenarios): Gets subset of branches in the collection that are active in any of the scenarios in Scenarios parameter (separated by commas).  To find branches that are NOT active in any  scenario listed, prefix with "Not:", .e.g., "Not:Current Accounts,Reference" would match branches that were not active in Current Accounts or the Reference scenario.  Returns a WEAPBranches collection.  Read only.  Note: because it returns a WEAPBranches collection, you can string together several in one statement, e.g., WEAP.DemandSites.FilterByTag("South").FilterByScenario("Not:Current Accounts").Choose("Select Demand Sites to set active in Current Accounts")

' Ask user which active demand sites to deactivate

FOR EACH Br IN WEAP.DemandSites.FilterByScenario("Current Accounts").Choose("Select Demand Sites to make NOT active in Current Accounts")

  Br.ActiveInCurrentAccounts = FALSE

NEXT

' Ask user which inactive reservoirs to activate

FOR EACH Br IN WEAP.Reservoirs.FilterByScenario("Not:Current Accounts").Choose("Select Reservoirs to make active in Current Accounts")

  Br.ActiveInCurrentAccounts = TRUE

NEXT

FilterByTag(Tags): Gets subset of branches in the collection that have any of the tags in Tags parameter (separated by commas).  To find branches that do NOT match, prefix with "Not:", .e.g., "Not:South" would match branches that did not have a "South" tag.  Returns a WEAPBranches collection.  Read only.  Note: because it returns a WEAPBranches collection, you can string together several in one statement, e.g., WEAP.DemandSites.FilterByTag("South").FilterByScenario("Not:Current Accounts").Choose("Select Demand Sites to set active in Current Accounts")

' Activate all catchments with the tag "American River Bsain"

FOR EACH Br in WEAP.Catchments.FilterByTag("American River Basin")

  Br.ActiveInCurrentAccounts = True

NEXT

FilterByType(Types): Gets subset of branches in the collection whose type matches one of the types in Types parameter (separated by commas).  To find branches that do NOT match, prefix with "Not:", .e.g., "Not:Reservoir".  Returns a WEAPBranches collection.  Read only.  Note: because it returns a WEAPBranches collection, you can string together several in one statement, e.g., WEAP.Branch("Gauge 101").UpstreamNodes.FilterByType("Catchments").FilterByScenario("Not:Current Accounts").Choose("Select Catchments to set active in Current Accounts")

' Calculate the total population of all demands sites downsteam of North Reservoir

TotalPopulation = 0

FOR EACH Br IN WEAP.Branch("North Reservoir").DownstreamNodes(True).FilterByType("Demand Site")

  IF Br.Variable("Annual Activity Level").Unit = "cap" THEN    ' is the unit population?

    Population = Br.Variable("Annual Activity Level").Scale * Br.Variable("Annual Activity Level").ResultValue(WEAP.BaseYear, 1)

    Print Br.FullName & "  " & WEAP.BaseYear & " population = " & Population

    TotalPopulation = TotalPopulation + Population

  END IF

NEXT

PRINT

Print "Total " & WEAP.BaseYear & " population = " & TotalPopulation

FullNameList: Get a list of branch names (using the full path) separated by character specified by optional parameter ListSeparator (which defaults to comma). Read only.

DSToDelete = WEAP.Choose("Choose Demand Sites to delete", WEAP.DemandSites.FullNameList)

FOR EACH BranchName in Split(DSToDelete, ",")

  WEAP.Branch(BranchName).Delete

NEXT

Print WEAP.Gauges.FullNameList(";")   ' Get list of gauges, separated by semicolons

Item(BranchNameOrIndex): Get the branch identified by the branch name or index (from 1 to Count).  Item is the "default" property, and therefore is usually omitted. Thus, the first two examples to the right are equivalent.  If the BranchName matches multiple branches in the collection, the first one is returned.

 

PRINT WEAP.Branch("\Demand Sites").Children.Item(2).Name
PRINT WEAP.Branch("\Demand Sites").Children(2).Name

PRINT WEAP.Branch("\Demand Sites").Children.Item("Industry East").FullName
PRINT WEAP.Branch("\Demand Sites").Children("Industry East").FullName

PRINT WEAP.DemandSites("Industry East").FullName

PRINT WEAP.DemandSites("South City").Descendants("Showers").FullName

NameList: Get a list of branch names separated by character specified by optional parameter ListSeparator (which defaults to comma). Read only.

'Create an array of all the Demand Site names, using the Visual Basic Split function

DemandSiteArray = Split(WEAP.DemandSites.NameList, ",")

 

 

WEAPBranch Properties and Methods

Example (using VB script)

ActiveInCurrentAccounts: Set or get whether the branch is active in the Current Accounts.  The following types can be set as not active in the Current Accounts (all other types are always active in the Current Accounts): Demand Site, Catchment, Wastewater Treatment Plant, Groundwater Node, Reservoir, Other Supply, Transmission Link, Return Flow Link, Run of River Hydro, Diversion.

WEAP.Branch("\Demand Sites\South City").ActiveInCurrentAccounts = FALSE

FOR EACH Branch IN WEAP.Branch("\Demand Sites").Children
IF Branch.
ActiveInCurrentAccounts THEN
...
END IF
NEXT

AddChild(NewName): Create a new branch named NewName on the Data Tree under the current branch.  Only works for branches under Demand Sites and Catchments, Key Assumptions or Other Assumptions.  Returns the new branch.  If a branch under the current branch with that name already exists, a new one will not be created -- the existing branch will be returned.

' Copy structure and data from catchment Agriculture West to catchment Agriculture North

SET AgNorthBranch = WEAP.Branch("\Demand Sites and Catchments\Agriculture North")

FOR EACH AgWestCrop IN WEAP.Branch("\Demand Sites and Catchments\Agriculture West").Children
SET NewBranch = AgNorthBranch.
AddChild(AgWestCrop.Name)
NewBranch.CopyData(AgWestCrop)
NEXT

AddChildren(NewNames): Create branches on the Data Tree under the current branch with names from the comma separated list in NewNames.  Only works for branches under Demand Sites and Catchments, Key Assumptions or Other Assumptions.  If a branch under the current branch with a name already exists, a new one will not be created.

WEAP.Branch("\Demand Sites\West City").AddChildren("West District, East District, North District, South District")

AddPoint(X, Y, AddBefore): Add a point to the line (river, diversion, transmission link, return flow link, runoff/infilltration link) at location X, Y.  If optional integer parameter AddBefore is given, add before this point (numbered 1 to NumPoints).  If not given, add at end (rivers and diversions) or just before the end (links).

 

Children: Get the collection of all branches immediately underneath this branch.  See WEAPBranches for details.  See also WEAPBranch.Descendants and WEAPBranch.Leaves.  Read only.

' Compare Children, Descendants and Leaves:

Print "Children"
FOR EACH Br IN WEAP.Branch("\Demand Sites").Children
PRINT STRING(Br.Level * 4, " ") & Br.Order & ": " & Br.Name
NEXT

Print "Descendants"
FOR EACH Br IN WEAP.Branch("\Demand Sites").Descendants
PRINT STRING(Br.Level * 4, " ") & Br.Order & ": " & Br.Name
NEXT

Print "Leaves"
FOR EACH Br IN WEAP.Branch("\Demand Sites").Leaves
PRINT STRING(Br.Level * 4, " ") & Br.Order & ": " & Br.Name
NEXT

ConnectedGroundwater: For river reaches, transmission links, return flow links and reservoirs, get the groundwater node that it is connected to, if any (for losses to or gains from groundwater).  Return an empty branch (Branch.ConnectedGroundwater.ID = 0) if no connection. Read only.

' List all nodes or reaches that have connections to groundwater
FOR EACH Br IN WEAP.Branches
SET GWNode = Br.ConnectedGroundwater
IF GWNode.ID > 0 THEN
PRINT Br.FullName & " IS CONNECTED TO " & GWNode.Fullname
END IF
NEXT

CopyData(SourceBranch): Copy all data from SourceBranch to the current branch.  SourceBranch is a WEAPBranch object, not the name of a branch.

' Create \Demand Sites\South City\Suburban, copying structure and data from \Demand Sites\South City\Single Family

SET SuburbanBranch = WEAP.Branch("\Demand Sites\South City").AddChild("Suburban")

FOR EACH SingleFamilyBranch IN WEAP.Branch("\Demand Sites\South City\Single Family").Children
SET NewBranch = SuburbanBranch.AddChild(SingleFamilyBranch.Name)
NewBranch.
CopyData(SingleFamilyBranch)
NEXT

Delete: Delete the branch and any associated schematic objects.  If the branch has any children, they will also be deleted.  You cannot delete Schematic objects if the Schematic is locked.  You cannot delete catchments or rivers created in Catchment Delineation Mode if Catchment Delineation Mode is not currently on.  You cannot delete a branch in the Results View or Scenario Explorer View.

' Delete all key assumptions

FOR EACH Br IN Branch("\Key Assumptions").Children
Br.
Delete
NEXT

' Delete each demand site that does not have any branches underneath

FOR EACH Br IN Branch("\Demand Sites").Children
If Br.Children.Count = 0 then Br.
Delete
NEXT

' Delete all reservoirs

FOR EACH Br IN WEAP.Reservoirs
Br.
Delete
NEXT

Descendants: Get the collection of all branches at all levels underneath this branch.  The list has a "depth first" ordering -- a branch's children are ordered before its siblings.  Returns a WEAPBranches collection.  See also WEAPBranch.Children and WEAPBranch.Leaves.  Read only.

 

FOR EACH Br IN WEAP.Branch("\Key Assumptions").Descendants

  PRINT Br.FullName & " = " & Br.Variable("Annual Activity Level").Expression

NEXT

DownstreamNodes(IncludeOffstreamNodes, IncludeLinks): Gets the WEAPBranches collection of all nodes upstream of this branch, which must be a river node.  If IncludeOffstreamNodes is True (optional, default is False), include Demand Sites, Catchments and Wastewater Treatment Plants that return upstream.  If IncludeLinks is True (optional, default is False), include River Reaches, and, if IncludeOffstreamNodes, Return Flow and Runoff/Infiltration Links.  See also DownstreamNodes.  Read only.

' List all Demand Sites downstream of Central Reservoir

FOR EACH Br IN WEAP.Branch("Central Reservoir").DownstreamNodes(TRUE).FilterByType("Demand Site")

  PRINT Br.Name & " is downstream of Central Reservoir"

NEXT

FullName: Get the full path of the current branch. Each level is separated by the "\" character.  (e.g. Demand Sites\South City) Read only.

FOR EACH Br IN WEAP.Branches
  PRINT Br.
FullName
NEXT

HasTag(TagName): Set or get whether the branch has this tag.

Branch.HasTag(TagName) is equivalent to Branch.Tags.Exists(TagName)
Branch.HasTag(TagName) = TRUE is equivalent to Branch.Tags.Add(TagName)
Branch.HasTag(TagName) = FALSE is equivalent to Branch.Tags(TagName).Delete

IF WEAP.Branch("\Demand Sites\South City").HasTag("Agriculture") THEN PRINT "South City has agriculture tag"

WEAP.Branch("\Demand Sites\South City").HasTag("Agriculture") = FALSE

' Turn off all catchments that are not in the American River Basin

FOR EACH Br in WEAP.Catchments

  Br.ActiveInCurrentAccounts = Br.HasTag("American River Basin")

NEXT

HasTagCategory(TagCategoryName): Are any of these tags in this category?

FOR EACH Br in WEAP.Catchments

  Br.ActiveInCurrentAccounts = Br.HasTagCategory("Upper Watersheds")

NEXT

HeadflowNode: Get or set the headflow node for a diversion, e.g., "Supply and Resources\River\Weaping River\Diversions\Grand Canal Outflow".  Returns a WEAPBranch object -- use WEAPBranch.IsValid to test if valid (connected) or not (not connected).  When setting, the node must already exist, and you can use either a WEAPBranch object or the branch's name.  Set to "" (empty string) to disconnect.  As a shortcut, you can give just the name of the node, e.g., "Grand Canal Outflow"

SET HeadflowNode = WEAP.Branch("Supply and Resources\River\Grand Canal").HeadflowNode

IF HeadflowNode.IsValid THEN
PRINT "Grand Canal is Connected"
ELSE
PRINT "Grand Canal is Not connected"
END IF

WEAP.Branch("Supply and Resources\River\Grand Canal").HeadflowNode = "Supply and Resources\River\Weaping River\Diversions\Grand Canal Outflow"

ID: Get the internal unique numeric ID of the branch.  Each branch in the tree has a unique ID.  It is not displayed in WEAP's normal interface but may be useful when automating WEAP.  All valid branches have ID > 0, so you use the test Branch.ID = 0 to determine if a Branch reference is valid.  Read only.

FOR EACH Branch IN WEAP.Branches
  PRINT Branch.
ID
NEXT

IsLine: Returns true if the branch represents a line object on the Schematic (River, Diversion, River Reach, Transmission Link, Return Flow Link, or Runoff/Infiltration Link).  Read only.

' Print GIS X,Y coordinates for all lines and nodes on the Schematic

FOR EACH Branch IN WEAP.Branches

    IF Branch.IsNode THEN

      Print Branch.FullName & ": (" & Branch.X & ", " & Branch.Y & ")"  

    ELSE IF Branch.IsLine THEN     ' GIS coordinates of start and end points of line

      PRINT Branch.FullName & ": (" & Branch.X & ", " & Branch.Y & ") - (" & Branch.X2 & ", " & Branch.Y2 & ")"              

    END IF

NEXT

IsNode: Returns true if the branch represents a node on the Schematic (Demand Site, Catchment, Groundwater node, Local Reservoir, Other Local Supply, Wastewater Treatment Plant or any river node).  Read only.

' Print GIS X,Y coordinates for all lines and nodes on the Schematic

FOR EACH Branch IN WEAP.Branches

    IF Branch.IsNode THEN

      Print Branch.FullName & ": (" & Branch.X & ", " & Branch.Y & ")"  

    ELSE IF Branch.IsLine THEN     ' GIS coordinates of start and end points of line

      PRINT Branch.FullName & ": (" & Branch.X & ", " & Branch.Y & ") - (" & Branch.X2 & ", " & Branch.Y2 & ")"              

    END IF

NEXT

IsRiverNode: Returns true if the branch represents a node on a river.  Read only.

' List all river nodes

FOR EACH Br IN WEAP.Branches

  IF Br.IsRiverNode THEN

    Print Br.TypeName & ": " & Br.FullName

  END IF

NEXT

IsValid: Return TRUE if the WEAPBranch object is assocaited with a valid WEAP branch.  Read only

IF WEAP.Branch("Supply and Resources\River\Blue River").TailflowNode.IsValid THEN

  PRINT "Blue River is Connected"

ELSE

  PRINT "Blue River is Not connected"

END IF

IsVisible: Returns true if the branch is visible on the tree.  River category branches with no children will not be visible.  For example, in Weaping River Basin, Blue River does not have any reservoirs -- therefore, the Reservoirs branch underneath Blue River will not be visible.

IF WEAP.Branch("\Supply and Resources\River\Blue River\Reservoirs").IsVisible THEN
  ...
NEXT

Leaves: Gets the WEAPBranches collection of all leaves underneath this branch.  (A leaf is the lowest level, with no children of its own.)  See also WEAPBranch.Children and WEAPBranch.Descendants.  Read only.

' Print all Water Use Rate expressions (they are only at the lowest level branches for each demand site)

FOR EACH DS IN WEAP.DemandSites

  FOR EACH Br in DS.Leaves

    PRINT Br.FullName & ": Annual Water Use Rate = " & Br.Variable("Annual Water Use Rate").Expression

  NEXT

NEXT

Level: Get the level of the branch in the tree, where the top level (e.g., Key Assumptions, Demand Sites, Supply and Resources) equals one.  Read only.

FOR EACH Br IN WEAP.Branches

  PRINT STRING(Br.Level * 4, " ") & Br.Order & ": " & Br.Name

NEXT

Name: Get the name of the branch. Read only.

PRINT WEAP.Branch("\Demand Sites").Children(2).Name

NodeAbove: For river nodes or reaches, gets the WEAPBranch for the river node above this node or reach.  (The NodeAbove the first node or reach on a connected diversion is the diversion node on the main river.)  For transmission links, return flow links or catchment runoff links, gets the WEAPBranch for the source node.  Returns an empty branch (Branch.NodeAbove.ID = 0) if branch is not a river node, river reach, transmission link, return flow link or catchment runoff link, or is the first node or reach on the river. Read only.

' List all river reaches downstream of a reservoir.  (TypeID = 16 is a reach, TypeID = 4 is a reservoir)

FOR EACH River IN WEAP.Branch("Supply and Resources\River").Children

      FOR EACH RiverType IN River.Children

            FOR EACH Child IN RiverType.Children

               IF (Child.TypeID = 16) and (Child.NodeAbove.TypeID = 4) THEN

                  Print Child.FullName

               END IF

            NEXT

      NEXT

NEXT

' Lists all transmission links whose source is groundwater.

FOR EACH ToBranch IN WEAP.Branch("\Supply and Resources\Transmission Links").Children

  FOR EACH FromBranch IN ToBranch.Children

    IF FromBranch.NodeAbove.TypeID = 3 THEN      ' TypeID = 3 is a groundwater node

      PRINT FromBranch.FullName

    END IF

  NEXT

NEXT

NodeBelow: For river nodes or reaches, gets the WEAPBranch for the river node below this node or reach. (The NodeBelow the last node or reach on a river or diversion is the tributary inflow node on the downstream river.)  For transmission links, return flow links or catchment runoff links, gets the WEAPBranch for the destination node.   Returns an empty branch (Branch.NodeBelow.ID = 0) if branch is not a river node, river reach, transmission link, return flow link or catchment runoff link, or is already the last node or reach on the river. Read only.

' List all river reaches upstream of a tributary inflow node.  (TypeID = 16 is a reach, TypeID = 13 is a tributary inflow node)

FOR EACH River IN WEAP.Branch("Supply and Resources\River").Children
FOR EACH RiverType IN River.Children
FOR EACH Child IN RiverType.Children
IF (Child.TypeID = 16) and (Child.NodeBelow.TypeID = 13) THEN
Print Child.FullName
END IF
NEXT
NEXT

NEXT

' Lists all transmission links, including the source and destination.

FOR EACH ToBranch IN WEAP.Branch("\Supply and Resources\Transmission Links").Children

  FOR EACH FromBranch IN ToBranch.Children

    PRINT FromBranch.FullName & " GOES FROM " & FromBranch.NodeAbove.FullName & " TO " & FromBranch.NodeBelow.FullName

  NEXT

NEXT

Note: Set or get the note associated with the branch in plain text format.  If you want to set or get the note in rich text format, which includes text formatting codes and non-text elements such as graphics, use the NoteAsRTF property instead.

WEAP.Branch("\Demand Sites\South City").Note = "South City is a city on the banks of the Weaping River"

FOR EACH Br IN WEAP.Branches

  IF Br.Note <> "" THEN

    PRINT "*************** Notes for " & Br.FullName & ": "

    PRINT Br.Note

  END IF

NEXT

NoteAsRTF: Set or get the note associated with the branch, in rich text format.  If you want to set or get the note in plain text format, without text formatting codes and non-text elements such as graphics, use the Note property instead.

Branch("\Demand Sites\Agriculture North").NoteAsRTF = Branch("\Demand Sites\Industry North").NoteAsRTF

 

' Save formatted note as Rich Text Format, which can be opened in Microsoft Word

SET fso = CreateObject("Scripting.FileSystemObject")

SET f = fso.CreateTextFile("Notes.rtf", True)

f.Write Branch("\Demand Sites\Industry North").NoteAsRTF

f.Close

SET f = Nothing

SET fso = Nothing

NumChildren: Get the number of children below the branch, if any.

 

NumPoints: Get the number of points on the line (river, diversion, transmission link, return flow link, runoff/infilltration link).

PRINT WEAP.Branch("Supply and Resources\River\Weaping River").NumPoints

PRINT WEAP.Branch("Supply and Resources\Transmission Links\to Agriculture North\from North Aquifer").NumPoints   

Order: Get the order of the branch among its siblings, where the order of the first sibling is one. Read only.

FOR EACH Br IN WEAP.Branches

  PRINT STRING(Br.Level * 4, " ") & Br.Order & ": " & Br.Name

NEXT

Parent: Get the WEAPBranch object for the parent of the current branch. Read only.

PRINT WEAP.Branch("\Demand Sites\South City").Parent.Name    ' This will be "Demand Sites"

ParentID: Get the numeric ID of the Parent of the current branch.  Equivalent to Branch.Parent.ID.  Read only.

IF Branch.ParentID = WEAP.Branch("\Demand Sites").ID THEN   
...

PriorityOnTransmissionLink: Set or get whether the demand priority is entered on the transmission link.  If not, the demand priority will be entered on the demand site or catchment, and the supply preference will be entered on the transmission link.  Can be used only on Demand Sites, Catchments or Transmission Link branches.  When used on a Transmission Link, it will set PriorityOnTransmissionLink for the Demand Site or Catchment to which the Transmission Link goes.

WEAP.Branch("\Demand Sites\South City").PriorityOnTransmissionLink = FALSE

WEAP.Branch("\Supply and Resources\Transmission Links\to Agriculture West\from West Aquifer").PriorityOnTransmissionLink = TRUE

FOR EACH Branch IN WEAP.Branch("\Demand Sites").Children
IF Branch.
PriorityOnTransmissionLink THEN
...
END IF
NEXT

' Set value for "Demand Priority" or "Supply Preference," depending on setting of PriorityOnTransmissionLink

IF WEAP.Branch("\Supply and Resources\Transmission Links\to Agriculture West\from West Aquifer").PriorityOnTransmissionLink = TRUE THEN

   WEAP.Branch("\Supply and Resources\Transmission Links\to Agriculture West\from West Aquifer").Variables("Demand Priority").Expression = 3

ELSE

   WEAP.Branch("\Supply and Resources\Transmission Links\to Agriculture West\from West Aquifer").Variables("Supply Preference").Expression = 2

END IF

ReachAbove: Gets the WEAPBranch for the river reach above this node or reach.  (The ReachAbove the first node or reach on a connected diversion is the reach above the diversion node on the main river.)  Returns an empty branch (Branch.ReachAbove.ID = 0) if branch is not a river node or reach, or is the first reach on the river or unconnected diversion. Read only.

 

ReachBelow: Gets the WEAPBranch for the river reach below this node or reach. (The ReachBelow the last node or reach on a river or diversion is the reach below the tributary inflow node on the downstream river.)  Returns an empty branch (Branch.ReachBelow.ID = 0) if branch is not a river node or reach, or is already the last reach on the river or diversion that does not flow into another river or diversion. Read only.

' List all river reaches downstream of a reservoir.  (TypeID = 4 is a reservoir)

FOR EACH River IN WEAP.Branch("Supply and Resources\River").Children

      FOR EACH RiverType IN River.Children

            FOR EACH Child IN RiverType.Children

               IF (Child.TypeID = 4) THEN

                  PRINT Child.ReachBelow.FullName

               END IF

            NEXT

      NEXT

NEXT

ShapeID: Get the internal numerical ID of the schematic object (e.g., Demand Site or Reservoir) associated with the branch.  To match this ID to a GIS shape, look at the ObjID attribute in the WEAPNodes or WEAPArcs shape files.  Note: This is a different internal ID code from the Branch ID (Branch.ID).  Not every branch will have a corresponding schematic object, e.g., "\Demand Sites," in which case ShapeID = 0.  Each schematic object has a unique ShapeID, although several branches can be associated with one shape, e.g., WEAP.Branch("\Supply and Resources\Return Flows\from Agriculture North\to North Aquifer").ShapeID is the same as WEAP.Branch("\Water Quality\Pollutant Decrease in Return Flows\from Agriculture North\to North Aquifer").ShapeID.  Read only.

FOR EACH Branch IN WEAP.Branches
IF Branch.
ShapeID > 0 THEN
  PRINT "Branch " & Branch.Name & ", ShapeID = " & Branch.
ShapeID
END IF

NEXT

Split(NewNames, DoCopyData): Subdivide a branch, creating a new child for each name in the comma separated list NewNames.  If parameter DoCopyData is TRUE (optional, defaults to TRUE), copy all data from the current branch to the new branches (except Activity Level and Area).  Activity Unit for the new branches will be set to percent.

CALL WEAP.Branch("\Demand Sites\Industry North").Split("Manufacturing, Cooling")

StartupYear: Set or get the startup year for the branch object, in the currently active scenario. If startup year is 0, the branch is not active in the scenario. Can only be changed if the branch is already set as Not Active In Current Accounts. (This setting can be changed with the ActiveInCurrentAccounts property--see above.)  Note: Some objects (e.g., rivers) are always active and cannot be set to start up after the Base Year.

WEAP.ActiveScenario = "Supply Measures"

SET BrNorthRes = WEAP.Branch("\Supply and Resources\River\Weaping River\Reservoirs\North Reservoir")

IF BrNorthRes.StartupYear = 0 THEN  BrNorthRes.StartupYear = WEAP.BaseYear + 5

TailflowNoder: Get or set the tailflow node for a tributary or diversion, e.g., "Supply and Resources\River\Weaping River\Tributary Inflow\Blue River Inflow".  Returns a WEAPBranch object -- use WEAPBranch.IsValid to test if valid (connected) or not (not connected).  When setting, the node must already exist, and you can use either a WEAPBranch object or the branch's name.  Set to "" (empty string) to disconnect.  As a shortcut, you can give just the name of the node, e.g., "Blue River Inflow."

WEAP.Branch("Supply and Resources\River\Blue River").TailflowNode = "Supply and Resources\River\Weaping River\Tributary Inflow\Blue River"

IF WEAP.Branch("Supply and Resources\River\Blue River").TailflowNode.IsValid THEN
PRINT "Blue River is Connected"
ELSE
PRINT "Blue River is Not connected"
END IF

TypeID: Get the numeric code indicating the type of branch.  See list in TypeName below.  Read only.

FOR EACH Branch IN WEAP.Branch("\Demand Sites").Children
IF Branch.
TypeID = 1 THEN  ' Demand site (TypeID = 1) or catchment (TypeID = 21)?
...

NEXT

TypeName: Get the name of the type of branch.  Read only.  

Valid branch names and their associated ID's:

 

Type Name

TypeID

Catchment

21

Catchment Inflow Node

23

Demand Site

1

Diversion

15

Diversion Outflow

11

Flow Requirement

9

Groundwater

3

Other Supply

5

Reservoir

4

Return Flow

8

Return Flow Node

17

River

6

River Reach

16

River Withdrawal

10

Run of River Hydro

14

Runoff/Infiltration

22

Streamflow Gauge

20

Transmission Link

7

Tributary Inflow

13

Wastewater Treatment Plant

2

FOR EACH Branch IN WEAP.Branch("\Demand Sites").Children

  IF Branch.TypeName = "Demand Site" THEN  ' Demand site or catchment?

    ...

  END IF

NEXT

' Note: This is equivalent to  FOR EACH Branch IN WEAP.DemandSites

UpstreamNodes(IncludeOffstreamNodes, IncludeLinks): Gets the WEAPBranches collection of all nodes upstream of this branch, which must be a river node.  If IncludeOffstreamNodes is True (optional, default is False), include Demand Sites, Catchments and Wastewater Treatment Plants that return upstream.  If IncludeLinks is True (optional, default is False), include River Reaches, and, if IncludeOffstreamNodes, Return Flow and Runoff/Infiltration Links.  See also DownstreamNodes.  Read only.

' Tag all nodes upstream of Gauge 283401, including catchments, with the tag "American River Basin"

FOR EACH Br in WEAP.Branch("Gauge 283401").UpstreamNodes(True)

  Br.HasTag("American River Basin") = True

NEXT

' List all catchments upstream of Gauge 283401

FOR EACH Br in WEAP.Branch("Gauge 283401").UpstreamNodes(True).FilterByType("Catchment")

  Print Br.Name

NEXT

Variable(VariableName): Get the named variable for this branch. See WEAPVariable for details. Read only

WEAP.Branch("\Demand Sites\South City").Variable("Consumption").Expression = 40

VariableExists(VariableName): Returns true if the specified variable exists for this branch.  Branch.VariableExists(VariableName) is equivalent to Branch.Variables.Exists(VariableName).  Read only.

' Set the wind speed for every catchment to be 3.3 m/s
FOR EACH Branch IN WEAP.Branch("\Demand Sites and Catchments").Children
  IF Branch.
VariableExists("Wind") THEN ' This variable only exists for catchment branches
  Br.Variable("Wind").Expression = 3.3
  END IF
NEXT

Variables: Get the collection of all variables associated with this branch. See WEAPVariables for details. Read only

FOR i = 1 to WEAP.Branch("\Demand Sites\South City").Variables.Count;
  PRINT WEAP.Branch("\Demand Sites\South City").
Variables(i).Name
NEXT

WEAP.Branch("\Demand Sites\South City").Variables("Consumption").Expression = 30

X: Get the GIS X coordinate of the schematic object associated with the branch.  If the schematic object is a line, this will be the X coordinate of the starting point of the line.  If the Schematic GIS layers are unprojected (WGS84), then X is longitude.  Read only.

' Print each demand site's name and X,Y GIS coordinates

For Each Br in WEAP.Branch("\Demand Sites and Catchments").Children

  Print Br.FullName & ": " & Br.X & ", " & Br.Y               

Next

X2: If the schematic object associated with the branch is a line (river, diversion, river reach, transmission link, return flow link or runoff/infiltration link), get the GIS X coordinate of the endpoint of the line.  If the Schematic GIS layers are unprojected (WGS84), then X is longitude.  Read only.

See example for IsLine above.

Y: Get the GIS Y coordinate of the schematic object associated with the branch.  If the schematic object is a line, this will be the Y coordinate of the starting point of the line.  If the Schematic GIS layers are unprojected (WGS84), then Y is latitude.  Read only.

See example for X above.

Y2: If the schematic object associated with the branch is a line (river, diversion, river reach, transmission link, return flow link or runoff/infiltration link), get the GIS Y coordinate of the endpoint of the line.  If the Schematic GIS layers are unprojected (WGS84), then Y is latitude.  Read only.

See example for IsLine above.