文字样式也和实体一样,可以创建一个textstyle table,这个表是textstyle record的容器
设置完文字样式之后,可以在创建实体的时候,使用这种文字样式。
//创建文字样式
public ObjectId CreateStyle()
{
ObjectId textstyleid = new ObjectId();
Database db = HostApplicationServices.WorkingDatabase;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
TextStyleTable st = trans.GetObject(db.TextStyleTableId, OpenMode.ForWrite) as TextStyleTable;
string stylename = "gbc";
TextStyleTableRecord str = new TextStyleTableRecord();
//查询是否包含gbc样式,若果不包含就创建该文字样式,包含就取出。
if (!st.Has(stylename))
{
str.Name = "gbc";
str.FileName = "txt";
str.BigFontFileName = "gbcbig";
}
else
{
foreach (ObjectId id in st)
{
if (str.Name == "gbc")
{
str = id.GetObject(OpenMode.ForNotify) as TextStyleTableRecord;
}
}
}
textstyleid = st.Add(str);
trans.AddNewlyCreatedDBObject(str, true);
trans.Commit();
}
return textstyleid;
}