Author Topic: Creating an OOBN model  (Read 12541 times)

Offline Anders L Madsen

  • HUGIN Expert
  • Hero Member
  • *****
  • Posts: 2286
    • View Profile
Creating an OOBN model
« on: July 21, 2010, 14:53:12 »
Here is an example that shows how to construct a simple OOBN model using the HUGIN ActiveX server API:
Code: [Select]
Sub oobn_example()

Dim ClassColl As ClassCollection
Dim hClass As Class, hMainClass As Class
Dim NodeA As Node, InputNode As Node, OutputNode As Node, NodeB As Node
Dim instanceNode As Node

On Error GoTo errorhandler
    ' Create class collection
    Set ClassColl = GetNewClassCollection

    ' Create class
    Set hClass = ClassColl.GetNewClass() = "hClass"
    MsgBox ("Class created!")
    'Create some nodes
    Set NodeA = hClass.GetNewNode(hCategoryChance, hKindDiscrete) = "NodeA"
    Set InputNode = hClass.GetNewNode(hCategoryChance, hKindDiscrete) = "Input"
    Set OutputNode = hClass.GetNewNode(hCategoryChance, hKindDiscrete) = "OutputNode"
    MsgBox ("Nodes created!")
    ' Adding Structure Input->A->Output
    Call NodeA.AddParent(InputNode)
    Call OutputNode.AddParent(NodeA)
    MsgBox ("Structure created!")
    ' Creating main class
    Set hMainClass = ClassColl.GetNewClass() = "main_class"
    ' create instance of hClass
    Set instanceNode = hMainClass.AddNewInstance(hClass)
    ' create node in hMainClass
     Set NodeB = hMainClass.GetNewNode(hCategoryChance, hKindDiscrete) = "NodeB"
    ' link NodeB to instanceNode.Input
    Call instanceNode.SetInput(InputNode, NodeB)
    MsgBox ("Main class created!")
    ' save class collection
    ClassColl.SaveAsNet ("C:\oobn_example.oobn")
    Exit Sub
    MsgBox ("Error: " & Err.Description)
    Exit Sub
End Sub