- 积分
- 24557
- 明经币
- 个
- 注册时间
- 2004-3-17
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
本帖最后由 作者 于 2010-6-25 17:20:38 编辑
-
- [CommandMethod("tt")]
- public static void Test()
- {
- var db = HostApplicationServices.WorkingDatabase;
- var doc = Application.DocumentManager.GetDocument(db);
- using (var tr = db.TransactionManager.StartTransaction())
- {
- var bt = db.BlockTableId.GetObject(OpenMode.ForWrite) as BlockTable;
- //创建一个无名块定义
- var blkdef = new BlockTableRecord();
- blkdef.Name = "*U";
- bt.Add(blkdef);
- tr.AddNewlyCreatedDBObject(blkdef, true);
- //向块定义添加实体
- Line line = new Line(Point3d.Origin, new Point3d(10, 0, 0));
- blkdef.AppendEntity(line);
- tr.AddNewlyCreatedDBObject(line, true);
- //向块定义添加多行属性
- AttributeDefinition attdef =
- new AttributeDefinition
- {
- Prompt = "Input A1:",
- Tag = "A1",
- Height = 3.5,
- IsMTextAttributeDefinition = true,
- Position = Point3d.Origin,
- };
- attdef.SetDatabaseDefaults();
-
- //在当前空间创建块引用
- var btr = db.CurrentSpaceId.GetObject(OpenMode.ForWrite) as BlockTableRecord;
- var blkref = new BlockReference(Point3d.Origin, blkdef.ObjectId);
- btr.AppendEntity(blkref);
- tr.AddNewlyCreatedDBObject(blkref, true);
- //在块引用中添加属性
- AttributeReference attref = new AttributeReference();
- attref.SetAttributeFromBlock(attdef, blkref.BlockTransform);
- attref.SetDatabaseDefaults();
- blkref.AttributeCollection.AppendAttribute(attref);
- tr.AddNewlyCreatedDBObject(attref, true);
- //更改属性的多行文字内容
- MText mt = attref.MTextAttribute;
- mt.Contents = @"123\p456";
- attref.MTextAttribute = mt;
- attref.UpdateMTextAttribute();
- tr.Commit();
-
- }
- }
|
|