Can I add a timeline to a Case programatically?
You can base it on the code found in CRM/Case/Form/CaseView.php. You'll need to adjust references to $this, etc.

  $session            = CRM_Core_Session::singleton();
  $this-&gt;_uid         = $session-&gt;get('userID');
  $xmlProcessor       = new CRM_Case_XMLProcessor_Process();
  $xmlProcessorParams = array(
    'clientID' =&gt; $this-&gt;_contactID,
    'creatorID' =&gt; $this-&gt;_uid,
    'standardTimeline' =&gt; 0,
    'activity_date_time' =&gt; date('YmdHis'),
    'caseID' =&gt; $this-&gt;_caseID,
    'caseType' =&gt; $this-&gt;_caseType,
    'activitySetName' =&gt; $params['timeline_id'],
  );
  $xmlProcessor-&gt;run($this-&gt;_caseType, $xmlProcessorParams);
  $reports = $xmlProcessor-&gt;get($this-&gt;_caseType, 'ActivitySets');

  CRM_Core_Session::setStatus(ts('Activities from the %1 activity set have been added to this case.',
      array(1 =&gt; $reports[$params['timeline_id']])
  ), ts('Done'), 'success');