create relation between two nodes using the relation module I am using the relation module and i don't like the way the default relation blocks work(entity collector and relation add blocks).

SO I'm trying to write my own block for creating relation. I have a form which has two text boxes, where the user selects two different end points between which the relation has to be made. he then clicks on submit and the relation has to be created.

coming to the relation module, i see that it doesn't have an API for use. Also i looked at the existing relation creating blocks(entity collector and relation add), they load entities and not nodes. Can some one explain me how i load all the entities available. Also is there a way where I can get the entity from the node id ?

Thanks.
I have a module that uses Hierarchical Select to give users a nice looking UI to create relations from.

Below is an excerpt of how I create the relation.

  $tid = 1; // A term id.
  $node = node_load(1);
  $relation_bundle = 'a_type_of_relation';

  $endpoints = array();
  $endpoints[] = array('entity_type' =&gt; 'taxonomy_term', 'entity_id' =&gt; $tid);
  $endpoints[] = array('entity_type' =&gt; 'node', 'entity_id' =&gt; $node-&gt;nid);

  $new_relation = relation_create($relation_bundle, $endpoints);

  if ($rid = relation_save($new_relation)) {
    drupal_set_message(t('Relation created'), 'status', FALSE);
  }
  else {
    drupal_set_message(t('Creating relation failed'), 'warning', FALSE);
  }


Adding more useful validation and messages is left as an exercise to reader, as that will be very context sensitive.