文字样式表的管理
Code
1public static ObjectId SetFontStyle(string strTextStyleName)
2 {
3 ObjectId objID; //文字样式表的样式
4 Database m_db = HostApplicationServices.WorkingDatabase;
5 DocumentLock docLock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
6 using (Transaction m_tr = m_db.TransactionManager.StartTransaction())
7 {
8 TextStyleTable tst = (TextStyleTable)m_tr.GetObject(m_db.TextStyleTableId, OpenMode.ForWrite);
9
10 if(tst.Has(strTextStyleName))
11 {
12 objID = tst[strTextStyleName];
13 TextStyleTableRecord tstr = (TextStyleTableRecord)m_tr.GetObject(objID, OpenMode.ForWrite);
14 string str1 = tstr.BigFontFileName;
15 string str2 = tstr.FileName;
16 }
17 else
18 {
19 TextStyleTableRecord tstr = new TextStyleTableRecord();
20 tstr.Name = strTextStyleName;
21
22 tstr.BigFontFileName = "gbcbig.shx";
23 //tstr.FileName = "SimSun.ttf";//字体名
24 tstr.FileName = "gbenor.shx";//字体名
25 //Returns with file name pointing to a copy of the name of the font file for this text style
26 //返回一个指向文字文件名称的拷贝的名称,用于文字样式
27
28 tstr.TextSize = 200;
29 tst.Add(tstr);
30 m_tr.AddNewlyCreatedDBObject(tstr, true);
31 m_tr.Commit();
32 objID = tst[strTextStyleName];
33 m_db.Textstyle = objID;
34 }
35
36 }
37 docLock.Dispose();
38 return objID;
39 }
1public static ObjectId SetFontStyle(string strTextStyleName)
2 {
3 ObjectId objID; //文字样式表的样式
4 Database m_db = HostApplicationServices.WorkingDatabase;
5 DocumentLock docLock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
6 using (Transaction m_tr = m_db.TransactionManager.StartTransaction())
7 {
8 TextStyleTable tst = (TextStyleTable)m_tr.GetObject(m_db.TextStyleTableId, OpenMode.ForWrite);
9
10 if(tst.Has(strTextStyleName))
11 {
12 objID = tst[strTextStyleName];
13 TextStyleTableRecord tstr = (TextStyleTableRecord)m_tr.GetObject(objID, OpenMode.ForWrite);
14 string str1 = tstr.BigFontFileName;
15 string str2 = tstr.FileName;
16 }
17 else
18 {
19 TextStyleTableRecord tstr = new TextStyleTableRecord();
20 tstr.Name = strTextStyleName;
21
22 tstr.BigFontFileName = "gbcbig.shx";
23 //tstr.FileName = "SimSun.ttf";//字体名
24 tstr.FileName = "gbenor.shx";//字体名
25 //Returns with file name pointing to a copy of the name of the font file for this text style
26 //返回一个指向文字文件名称的拷贝的名称,用于文字样式
27
28 tstr.TextSize = 200;
29 tst.Add(tstr);
30 m_tr.AddNewlyCreatedDBObject(tstr, true);
31 m_tr.Commit();
32 objID = tst[strTextStyleName];
33 m_db.Textstyle = objID;
34 }
35
36 }
37 docLock.Dispose();
38 return objID;
39 }