明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2451|回复: 3

[讨论]lzh测试

[复制链接]
发表于 2010-6-8 20:41 | 显示全部楼层 |阅读模式
本帖最后由 作者 于 2010-6-25 17:20:38 编辑

  1.         [CommandMethod("tt")]
  2.         public static void Test()
  3.         {
  4.             var db = HostApplicationServices.WorkingDatabase;
  5.             var doc = Application.DocumentManager.GetDocument(db);
  6.             using (var tr = db.TransactionManager.StartTransaction())
  7.             {
  8.                 var bt = db.BlockTableId.GetObject(OpenMode.ForWrite) as BlockTable;
  9.                 //创建一个无名块定义
  10.                 var blkdef = new BlockTableRecord();
  11.                 blkdef.Name = "*U";
  12.                 bt.Add(blkdef);
  13.                 tr.AddNewlyCreatedDBObject(blkdef, true);
  14.                 //向块定义添加实体
  15.                 Line line = new Line(Point3d.Origin, new Point3d(10, 0, 0));
  16.                 blkdef.AppendEntity(line);
  17.                 tr.AddNewlyCreatedDBObject(line, true);
  18.                 //向块定义添加多行属性
  19.                 AttributeDefinition attdef =
  20.                     new AttributeDefinition
  21.                     {
  22.                         Prompt = "Input A1:",
  23.                         Tag = "A1",
  24.                         Height = 3.5,
  25.                         IsMTextAttributeDefinition = true,
  26.                         Position = Point3d.Origin,
  27.                     };
  28.                 attdef.SetDatabaseDefaults();
  29.                
  30.                 //在当前空间创建块引用
  31.                 var btr = db.CurrentSpaceId.GetObject(OpenMode.ForWrite) as BlockTableRecord;
  32.                 var blkref = new BlockReference(Point3d.Origin, blkdef.ObjectId);
  33.                 btr.AppendEntity(blkref);
  34.                 tr.AddNewlyCreatedDBObject(blkref, true);
  35.                 //在块引用中添加属性
  36.                 AttributeReference attref = new AttributeReference();
  37.                 attref.SetAttributeFromBlock(attdef, blkref.BlockTransform);
  38.                 attref.SetDatabaseDefaults();
  39.                 blkref.AttributeCollection.AppendAttribute(attref);
  40.                 tr.AddNewlyCreatedDBObject(attref, true);
  41.                 //更改属性的多行文字内容
  42.                 MText mt = attref.MTextAttribute;
  43.                 mt.Contents = @"123\p456";
  44.                 attref.MTextAttribute = mt;
  45.                 attref.UpdateMTextAttribute();
  46.                 tr.Commit();
  47.             
  48.             }
  49.         }

 楼主| 发表于 2010-6-8 20:49 | 显示全部楼层
  1. Contents
复制代码
 楼主| 发表于 2010-6-8 20:50 | 显示全部楼层
mt.Contents
 楼主| 发表于 2010-6-8 20:52 | 显示全部楼层
mt.Contents;
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-3-28 22:15 , Processed in 0.221216 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表