- 积分
- 11674
- 明经币
- 个
- 注册时间
- 2008-5-10
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
楼主 |
发表于 2010-11-30 13:36:53
|
显示全部楼层
本帖最后由 cairunbin 于 2010-11-30 13:39 编辑
lzh741206 发表于 2010-11-30 10:58
你的代码呢
谢谢。
代码在这里。
Database db = HostApplicationServices.WorkingDatabase;
ObjectId brId;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
BlockTable bt = trans.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
BlockTableRecord newBtr = new BlockTableRecord();
bt.Add(newBtr);
trans.AddNewlyCreatedDBObject(newBtr, true);
Line horizontalGridLine = new Line(new Point3d(0, -10, 0), new Point3d(0, 10, 0));
newBtr.AppendEntity(horizontalGridLine);
trans.AddNewlyCreatedDBObject(horizontalGridLine, true);
AttributeDefinition attdef = new AttributeDefinition(new Point3d(22, 0, 0), "test only", "testAttributeDefinition", "null", ObjectId.Null);
newBtr.AppendEntity(attdef);
trans.AddNewlyCreatedDBObject(attdef, true);
BlockReference br = new BlockReference(new Point3d(30, 30 , 0), newBtr.ObjectId);
BlockTableRecord modelSpaceBtr = trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
brId = modelSpaceBtr.AppendEntity(br);
trans.AddNewlyCreatedDBObject(br, true);
AttributeReference ar = new AttributeReference();
ar.SetAttributeFromBlock(attdef, br.BlockTransform);
ar.TextString = attdef.TextString;
br.AttributeCollection.AppendAttribute(ar);
ar.Visible = true;
trans.Commit();
}
|
|