- 积分
- 81
- 明经币
- 个
- 注册时间
- 2010-12-29
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
楼主 |
发表于 2010-12-30 23:00:24
|
显示全部楼层
已解决了,谢谢超级版本
DBText mytext = new DBText();
mytext.TextStyle = AddTextStyle("宋体", "1", "3", 20, 20);
//建立文字样式
public static ObjectId AddTextStyle(string name, string smallfont, string bigfont, double height, double xscale)
{
Database dbH = HostApplicationServices.WorkingDatabase;
using (Transaction trans = dbH.TransactionManager.StartTransaction())
{
TextStyleTable TST = (TextStyleTable)trans.GetObject(dbH.TextStyleTableId, OpenMode.ForWrite);
ObjectId id = GetIdFromSymbolTable(TST, name);
if (id == ObjectId.Null)
{
TextStyleTableRecord TSTR = new TextStyleTableRecord();
TSTR.Name = name;
TSTR.FileName = smallfont;
TSTR.BigFontFileName = bigfont;
TSTR.TextSize = height;
TSTR.XScale = xscale;
TST.UpgradeOpen();
id = TST.Add(TSTR);
trans.AddNewlyCreatedDBObject(TSTR, true);
}
return id;
}
}
//取得符号表的Id
public static ObjectId GetIdFromSymbolTable(SymbolTable st, string key)
{
Database dbH = HostApplicationServices.WorkingDatabase;
using (Transaction trans = dbH.TransactionManager .StartTransaction ())
{
if (st.Has(key))
{
ObjectId idres = st[key];
if (!idres.IsErased)
return idres;
foreach (ObjectId id in st)
{
if (!id.IsErased)
{
SymbolTableRecord str = (SymbolTableRecord)trans.GetObject(id, OpenMode.ForRead);
if (str.Name == key)
return id;
}
}
}
}
return ObjectId.Null;
} |
|