# Class: oLink

## $. oLink

The $.oLink class models a connection between two nodes.
A $.oLink object is always describing just one connection between two nodes in the same group. For distant nodes in separate groups, use $.oLinkPath.

#### new $.oLink(outNode, inNode, outPortNum, inPortNum, outLinkNum, isValid)

openHarmony/openHarmony_nodeLink.js, line 1084
  Constructor for $.oLink class

  Name | Type | Default | Description
  --- | --- | --- | ---
  `outNode` | $.oNode |  | The node from which the link is coming out.
  `inNode` | $.oNode |  | The node into which the link is connected.
  `outPortNum` | oScene |  | optional The out-port of the outNode used by this link.
  `inPortNum` | oScene |  | optional The in-port of the inNode used by this link.
  `outLinkNum` | oScene |  | optional The link index coming out of the out-port.
  `isValid` | bool | false | optional Bypass checks and assume this link is connected.

  ##### Example

      // find out if two nodes are linked, and through which ports
      var doc = $.scn;
      var myNode = doc.root.$node("Drawing");
      var sceneComp = doc.root.$node("Composite");

      var myLink = new $.oLink(myNode, sceneComp);

      log(myLink.linked+" "+myLink.inPort+" "+myLink.outPort+" "+myLink.outLink); // trace the details of the connection.

      // activate/deactivate connections simply:
      myLink.connect();
      log (myLink.linked)  // true

      myLink.disconnect();
      log (myLink.linked)  // false

      // it is also possible to set the linked status directly on the linked property:
      myLink.linked = true;

      // however, changing the ports of the link object don't physically change the connection

      myLink.inPort = 2    // the connection didn't change, the link object simply represents now a different connection possible.
      log (myLink.linked)  // false

      myLink.connect()     // this will connect the nodes once more, with different ports. A new connection is created.

### Members

#### inNode$.oNode

  The node that the link is connected into. Changing this value doesn't reconnect the link, just changes the connection described by the link object.

#### inPortint

  The in-port used by the link. Changing this value doesn't reconnect the link, just changes the connection described by the link object.
  In the event this value wasn't known by the link object but the link is actually connected, the correct value will be found.

#### readonlyisMultiLevelbool

  Compares the start and end nodes groups to see if the path traverses several groups or not.

#### linkedbool

  Get and set the linked status of a link

#### readonlyoutLinkint

  The index of the link comming out of the out-port.
  In the event this value wasn't known by the link object but the link is actually connected, the correct value will be found.

#### outNode$.oNode

  The node that the link is coming out of. Changing this value doesn't reconnect the link, just changes the connection described by the link object.

#### outPortint

  The out-port used by the link. Changing this value doesn't reconnect the link, just changes the connection described by the link object.
  In the event this value wasn't known by the link object but the link is actually connected, the correct value will be found.

### Methods

#### connect(){bool}

openHarmony/openHarmony_nodeLink.js, line 1311
  Attemps to connect a link. Will guess the ports if not provided.

  ##### Returns:

  Type | Description
  --- | ---
  bool |

#### disconnect(){bool}

openHarmony/openHarmony_nodeLink.js, line 1356
  Disconnects a link.

  ##### Returns:

  Type | Description
  --- | ---
  bool | Whether disconnecting was successful;

#### getValidLink(){$.oLink}

openHarmony/openHarmony_nodeLink.js, line 1262
  Get a link that can be connected by working out ports that can be used. If a link already exists, it will be returned.

  ##### Returns:

  Type | Description
  --- | ---
  $.oLink | A separate $.oLink object that can be connected. Null if none could be constructed.

#### insertNode(oNode, nodeInPort, nodeOutPort, nodeOutLink){Array.<$.oLink>}

openHarmony/openHarmony_nodeLink.js, line 1453
  Connects the given node in the middle of the link. The link must be connected.

  Name | Type | Default | Description
  --- | --- | --- | ---
  `oNode` | $.oNode |  | The node to insert in the link
  `nodeInPort` | int | 0 | optional The inPort to use on the inserted node
  `nodeOutPort` | int | 0 | optional The outPort to use on the inserted node
  `nodeOutLink` | int | 0 | optional The outLink to use on the inserted node

  ##### Returns:

  Type | Description
  --- | ---
  Array.<$.oLink> | an Array of two oLink objects that describe the new connections.

  ##### Example

      include("openHarmony.js")
      doc = $.scn
      var node1 = doc.$node("Top/Drawing")
      var node2 = doc.$node("Top/Composite")
      var node3 = doc.$node("Top/Transparency")

      var link = new $.oLink(node1, node2)
      link.insertNode(node3) // insert the Transparency node between the Drawing and Composite