CAD 展高程点C#属性块

 
public void ZhanGCD(Point3d pt)
{
    Database db = HostApplicationServices.WorkingDatabase;
    using (Transaction tr = db.TransactionManager.StartTransaction())
    {    
        ObjectId spaceid = db.CurrentSpaceId;
        /// 插入gc200块(高程点样式块)
        ObjectId objectId = spaceid.InsertBlockReference("GCD", "gc200", pt, new Scale3d(0.15), 0);
        /// 打开 GCD块参照
        BlockReference blockRef = tr.GetObject(objectId, OpenMode.ForWrite) as BlockReference;
        /// 定义属性
        AttributeDefinition attDef = new AttributeDefinition
        {
            Position = blockRef.Position, // 属性位置
            Tag = "Height",  // 属性名称
            Prompt = "请输入高程值:", // 属性值输入时提示
            TextString = pt.Z.ToString("0.00"),  // 属性值
            Height = 2, // 字体高度
            Justify = AttachmentPoint.MiddleLeft, // 字体对齐样式
            AlignmentPoint = new Point3d(2, 0, 0), // 字体位置(块插入点为(0,0,0))
            Layer = "GCD", // 文字图层
        };        
        // 定义属性参照
        AttributeReference attRef = new AttributeReference();
        // 属性定义 复制到属性参照 ;使用blockRef的变换矩阵
        attRef.SetAttributeFromBlock(attDef, blockRef.BlockTransform);
        // 块参照属性集合 添加属性参照
        blockRef.AttributeCollection.AppendAttribute(attRef);
        // 提交属性参照
        tr.AddNewlyCreatedDBObject(attRef, true);
        // 提交事务
        tr.Commit();
    }
}        

 

posted @ 2024-03-31 20:41  秉忠贞之志  阅读(162)  评论(0)    收藏  举报