- UID
- 658062
- 积分
- 2147
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2008-10-22
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
[CommandMethod("FieldPointLocation", "fpl", CommandFlags.Redraw | CommandFlags.Modal)]
public static void SetField()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
// Set snap to whatever you need:
// Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("osmode", 1);
using (Transaction tr = db.TransactionManager.StartTransaction())
{
Point3d pt = ed.GetPoint("\nPick field location: ").Value;
Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("lastpoint", pt);
Field fieldobj = new Field();
fieldobj.EvaluationOption = FieldEvaluationOptions.Automatic;
fieldobj.SetFieldCode("%<\\AcVar lastpoint \\f \"%lu2%pt3%ls59%pr3\">%");// decimal, separator semicolon,presicion 3
//fieldobj.SetFieldCode("%<\\AcVar lastpoint \\f \"%lu4%pt3\">%");// architectural, separator comma, precision 1/8"
MText mtextobj = new MText();
mtextobj.SetDatabaseDefaults();
mtextobj.SetField("Text", fieldobj);
fieldobj.Evaluate(0, db);
mtextobj.Location = pt;
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
btr.AppendEntity(mtextobj);
tr.AddNewlyCreatedDBObject(mtextobj, true);
tr.Commit();
}
} |
|