How can I programmatically add a tab to entry type? I'm trying to create a plugin that adds a tab full of fields to entry types but I can't seem to get it working. I tried assembleLayout but that replaced all the fields with my new fields rather than adding a new tab to them. 

I'm trying different combinations of FieldLayoutTabModel-&gt;setFields() but that throws an error about a fieldId property which leads me to believe I don't quite have the data types right. Any help would be appreciated.
I eventually figured this out. Here's the code that's working for me:

$newFields = array(
  0 =&gt; '12', // $field-&gt;fieldId
  1 =&gt; '15'  // $field-&gt;fieldId
);

// First we get all sections and loop through them
$allSections = craft()-&gt;sections-&gt;getAllSections();
foreach ($allSections as $section)
{
  // Then we get all EntryTypes of each section and loop through those
  $sectionEntryTypes = $section-&gt;getEntryTypes();
  foreach ($sectionEntryTypes as $entryType) 
  {
    // Grab the current layout and tabs
    $currentLayout = $entryType-&gt;getFieldLayout();
    $currentTabs = $currentLayout-&gt;getTabs();

    // This will the array passed to assembleLayout
    $postedFieldLayout = array();

    // Loop through each tab and build our array
    foreach ($currentTabs as $tab) {
      $fields = $tab-&gt;getFields();
      foreach ($fields as $field) {
        $postedFieldLayout[$tab-&gt;name][] = $field-&gt;fieldId;
      }
    }

    // Append the new fields we want to show to that array
    $postedFieldLayout['newFields'] = $this-&gt;newFields;
    $requiredFields = array();

    // Assemble the layout
    $fieldLayout = craft()-&gt;fields-&gt;assembleLayout($postedFieldLayout, $requiredFields);
    $fieldLayout-&gt;type = ElementType::Entry;
    $entryType-&gt;setFieldLayout($fieldLayout);

    // Save it
    if (craft()-&gt;sections-&gt;saveEntryType($entryType))
    {
      Craft::log('Successfully appended fields.');
    }
    else 
    {
      Craft::log('Could not append the fields.', LogLevel::Warning);
    }
  }
}