Below code create a new dimension style and make the newly created dimension style as current.
[CommandMethod("NewDimStyle")]
public void NewDimStyle()
{
Database db =
Application.DocumentManager.MdiActiveDocument.Database;
using (Transaction trans =
db.TransactionManager.StartTransaction())
{
DimStyleTable DimTabb =
(DimStyleTable)trans.GetObject(db.DimStyleTableId,
OpenMode.ForRead);
ObjectId dimId = ObjectId.Null;
if (!DimTabb.Has("Test"))
{
DimTabb.UpgradeOpen();
DimStyleTableRecord newRecord =
new DimStyleTableRecord();
newRecord.Name = "Test";
dimId = DimTabb.Add(newRecord);
trans.AddNewlyCreatedDBObject(newRecord, true);
}
else
{
dimId = DimTabb["Test"];
}
DimStyleTableRecord DimTabbRecaord =
(DimStyleTableRecord)trans.GetObject(dimId,
OpenMode.ForRead);
if (DimTabbRecaord.ObjectId != db.Dimstyle)
{
db.Dimstyle = DimTabbRecaord.ObjectId;
db.SetDimstyleData(DimTabbRecaord);
}
trans.Commit();
}
}