Mã nguồn
Đoạn mã sau sẽ tạo textstyle mới, và sử dụng font TCVN (ví dụ .vnArial).
1 Thêm class AJS_.cs
Lưu mã sau dưới dạng tệp tin AJS_.cs
Code:
public static ObjectId AddTextStyle(this Database db, string textstylename, string font = "Arial.ttf", bool cmdecho = false)
{
var TCVN = "tcvn";
using (Transaction tr = db.TransactionManager.StartTransaction())
{
TextStyleTable tst = (TextStyleTable)tr.GetObject(db.TextStyleTableId, OpenMode.ForRead);
try
{
SymbolUtilityServices.ValidateSymbolName(textstylename, false);
if (tst.Has(textstylename))
{
//if (cmdecho == true) ed.WriteMessage("\nTextsyle \"{0}\" already exists.", textstylename);
return tst[textstylename];
}
}
catch
{
// An exception has been thrown, indicating the
// name is invalid
//if (cmdecho == true) ed.WriteMessage("\nInvalid layer name.");
return ObjectId.Null;
}
var wdb = Curs.Database;
HostApplicationServices.WorkingDatabase = db;
// Create our new layer table record...
TextStyleTableRecord str = new TextStyleTableRecord();
// ... and set its properties
str.Name = textstylename;
str.FileName = font;
if (TCVN.Equals("tcvn"))
{
str.IsShapeFile = false;
str.Font = new Autodesk.AutoCAD.GraphicsInterface.FontDescriptor(".vnArial", false, false, 0, 34);
}
// Add the new layer to the layer table
tst.UpgradeOpen();
ObjectId ltId = tst.Add(str);
tr.AddNewlyCreatedDBObject(str, true);
HostApplicationServices.WorkingDatabase = wdb;
//Commit the transaction
//if (cmdecho == true) ed.WriteMessage("\nTextsyle \"{0}\" added.", textstylename);
tr.Commit();
return ltId;
}
}Link tải (MediaFire)
📥 https://www.mediafire.com/
---------------------------------------------------------------------------------------------
Mọi thông tin xin liên hệ Fanpage AutoLISP Thật là đơn giản!
Cảm ơn bạn đã theo dõi!


Không có nhận xét nào:
Đăng nhận xét