[讨论]lzh测试
本帖最后由 作者 于 2010-6-25 17:20:38 编辑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();
}
}
Contents mt.<font face="Verdana">Contents</font> <font face="Verdana"><font face="Verdana"><font face="Verdana">mt.<font face="Verdana">Contents;</font></font></font></font>
页:
[1]