- UID
- 804730
- 积分
- 4
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2020-10-15
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
想在C#代码中先创建一个样式,然后创建一个DBText,让Dbtext应用新建的样式,发现按如下代码操作后,Dbtext在图纸上都没看到,去掉设置Dbtext的样式ID的语句是OK的,请各位求教下,谢谢。
- [CommandMethod("SetFontNew")]
- public void CreateMText()
- {
- //Database db = HostApplicationServices.WorkingDatabase;
- Document doc = Application.DocumentManager.MdiActiveDocument;
- Database db = doc.Database;
- Editor ed = doc.Editor;
- //DocumentLock dl = doc.LockDocument();
- try
- {
- ObjectId id = AddTextStyle2("宋体", "1", "3", 20, 20);
- using (Transaction tr = db.TransactionManager.StartTransaction())
- {
- BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
- BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
- MText mt = new MText();
- mt.Contents = "ABCDE";
- mt.TextStyleId = id;
- mt.Width = 3.5;
- mt.Height = 3.5;
- mt.Location = new Point3d(300, 300, 0);
- modelSpace.AppendEntity(mt);
- tr.AddNewlyCreatedDBObject(mt, true);
- tr.Commit();
- }
- }
- catch {
- }
- //dl.Dispose();
- }
- public static ObjectId AddTextStyle2(string name, string smallfont, string bigfont, double height, double xscale)
- {
- Document doc = Application.DocumentManager.MdiActiveDocument;
- Database db = doc.Database;
- Editor ed = doc.Editor;
- //DocumentLock dl = doc.LockDocument();
- using (Transaction tr = db.TransactionManager.StartTransaction())
- {
- TextStyleTable TST = (TextStyleTable)tr.GetObject(db.TextStyleTableId, OpenMode.ForWrite);
- ObjectId id = GetIdFromSymbolTable2(TST, "test", db, tr);
- if (id == ObjectId.Null)
- {
- TextStyleTableRecord TSTR = new TextStyleTableRecord();
- //TextStyleTableRecord TSTR = new TextStyleTableRecord();
- TSTR.Name = "test";
- TSTR.Font = new ZwSoft.ZwCAD.GraphicsInterface.FontDescriptor("SimSun", false, false, 134, 2);
- //TSTR.Name = name;
- //TSTR.FileName = smallfont;
- // TSTR.BigFontFileName = bigfont;
- TSTR.TextSize = height;
- TSTR.XScale = 1;
- TST.UpgradeOpen();
- id = TST.Add(TSTR);
- tr.AddNewlyCreatedDBObject(TSTR, true);
- }
- tr.Commit();
- return id;
- }
- }
- //取得符号表的Id
- public static ObjectId GetIdFromSymbolTable2(SymbolTable st, string key, Database dbH, Transaction trans)
- {
- 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;
- }
|
|