- UID
- 658062
- 积分
- 2147
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2008-10-22
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
[CommandMethod("STATION")]
public static void CreateStation()
{
// Get the current document and database
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
// Start a transaction
using (Transaction tr = db.TransactionManager.StartTransaction())
{
try
{
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForWrite);
string blkName = "STATION";
if (bt.Has(blkName))
{
ed.WriteMessage("\nBlock \"STATION\" already exist.");
return;
}
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
Point3d inspt = new Point3d(0, 0, 0);
BlockTableRecord newBtr = new BlockTableRecord();
bt.Add(newBtr);
newBtr.Name = blkName;
newBtr.Origin = inspt;
newBtr.BlockScaling = BlockScaling.Uniform;
newBtr.Units = UnitsValue.Inches;
newBtr.Explodable = true;
tr.AddNewlyCreatedDBObject(newBtr, true);
Line ln = new Line();
ln.StartPoint = new Point3d(0.5, 0, 0);
ln.EndPoint = new Point3d(12, 0, 0);
Circle circ = new Circle();
circ.Center = inspt;
circ.Radius = 0.5;
AttributeDefinition attr = new AttributeDefinition();
attr.Tag = "NUMBER";
attr.Prompt = "Station number:";
attr.TextString = "1";
attr.Verifiable = true;
attr.LockPositionInBlock = true;
//attr.TextStyle = db.Textstyle;//<-- A2009
attr.TextStyleId = db.Textstyle;//<-- A2010
attr.Height = 1.0;
attr.Position = new Point3d(6.0, 0.5, 0);
attr.AdjustAlignment(db);
newBtr.AppendEntity(ln);
tr.AddNewlyCreatedDBObject(ln, true);
newBtr.AppendEntity(circ);
tr.AddNewlyCreatedDBObject(circ, true);
newBtr.AppendEntity(attr);
tr.AddNewlyCreatedDBObject(attr, true);
tr.Commit();
}
catch (System.Exception ex)
{
ed.WriteMessage(ex.Message + "\n" + ex.StackTrace);
}
}
} |
|