Hi Pascal,
2 things:
1) Sketch editing of title block definition, i.e. Edit() / ExitEdit(), seems to rely on a copy of the sketch, so you would need to add the attribute set with CopyWithOwner = True
2) All sketch editing of the title block definition should be done inside an Edit() / ExitEdit() section including modifying the attributes of a text box inside the sketch
Once I followed the above the attributes remained in tact:
static void test()
{
Application = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application") as Inventor.Application;
if (Application.ActiveDocument == null)
Console.WriteLine("There is no active document in Inventor.");
else
if (!(Application.ActiveDocument is DrawingDocument))
Console.WriteLine("Active document should be a drawing document.");
else
{
// Get active drawing document
Document = Application.ActiveDocument as DrawingDocument;
// Get ANSI large title block definition
TitleBlockDefinitions titleBlockDefinitions = Document.TitleBlockDefinitions;
TitleBlockDefinition titleBlockDef1 = titleBlockDefinitions[1];
// Show counts of attribute set and attribute (should be 0)
TextBox textBox = titleBlockDef1.Sketch.TextBoxes[1];
Console.WriteLine("AttributeSets.Count => " + textBox.AttributeSets.Count.ToString() + " , Expected = 0 (Before creating)");
///////////////////////////////////////////////////////////////////
// Real modification, adding the Attribute set
///////////////////////////////////////////////////////////////////
// Edit sketch
DrawingSketch sketch;
titleBlockDef1.Edit(out sketch);
// Add Attribute set and attribute
textBox = sketch.TextBoxes[1];
AttributeSet myAttributeSet = textBox.AttributeSets.Add("MySet", true);
Inventor.Attribute myAttribute = myAttributeSet.Add("MyAttribute", ValueTypeEnum.kStringType, "MyAttributeValue");
// Exit sketch with saving
titleBlockDef1.ExitEdit(true);
// Show counts of attribute set and attribute (should be 1)
textBox = titleBlockDef1.Sketch.TextBoxes[1];
Console.WriteLine("AttributeSets.Count => " + textBox.AttributeSets.Count.ToString() + " , Expected = 1 (After creating, before editing sketch)");
///////////////////////////////////////////////////////////////////
// Fake modification, just for testing that the Attribute remains
///////////////////////////////////////////////////////////////////
//DrawingSketch sketch;
titleBlockDef1.Edit(out sketch);
// Exit sketch with saving
titleBlockDef1.ExitEdit(true);
// Show counts (ERROR USED TO BE HERE => should be 1 but previously showed 0)
textBox = titleBlockDef1.Sketch.TextBoxes[1];
Console.WriteLine("AttributeSets.Count => " + textBox.AttributeSets.Count.ToString() + " , Expected = 1 (After ExitEdit)");
Console.ReadKey();
}
}
Cheers,

Adam Nagy
Autodesk Platform Services