Create and add attribute group with attributes to all attribute sets
It's a lot easier to do it via setup script. Here is an example:
// Add new Attribute group
$groupName = 'My Attr Group';
$entityTypeId = $installer->getEntityTypeId('catalog_product');
$attributeSetId = $installer->getDefaultAttributeSetId($entityTypeId);
$installer->addAttributeGroup($entityTypeId, $attributeSetId, $groupName, 100);
$attributeGroupId = $installer->getAttributeGroupId($entityTypeId, $attributeSetId, $groupName);
// Add existing attribute to group
$attributeId = $installer->getAttributeId($entityTypeId, ATTRIBUTE_CODE);
$installer->addAttributeToGroup($entityTypeId, $attributeSetId, $attributeGroupId, $attributeId, null);
Note: $installer
variable is instance of Mage_Eav_Model_Entity_Setup
class. You can look there for further reference. You can also look in app/code/core/Mage/Catalog/sql/catalog_setup
folder for some more examples.
Using an installer script
Try
$filters = array(
'my_attribute_id_1',
'my_attribute_id_2'
..
);
$product_tab = 'General';
foreach($filters as $value){
$eavModel = Mage::getModel('eav/entity_setup','core_setup');
$attributeId = $eavModel->getAttributeId('catalog_product', $value);
foreach($eavModel->getAllAttributeSetIds('catalog_product') as $id) {
$attributeGroupId = $eavModel->getAttributeGroupId('catalog_product', $id, $product_tab);
$eavModel->addAttributeToSet('catalog_product', $id, $attributeGroupId, $attributeId);
}
}